X1226 RTC - Help


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161

    Default X1226 RTC - Help

    Hello there,

    I have been struggling to get this Intersil RTC X1226 to work, but no luck.

    I am using PIC16F73 and an LCD to read/write the RTC. As you can see, i have tried everything but sigh. My code is as follows

    ' Clock Defines
    ' ----------------
    DS_SCL VAR PORTA.0 ' I2C clock pin
    DS_SDA VAR PORTA.1 ' I2C data pin
    RTC CON %11011111 ' RTC device address (byte addressing)


    ' -------------- RTC Address definitions -----------------
    SecReg CON $30 ' seconds address (00 - 59)
    MinReg CON $31 ' minutes address (00 - 59)
    HourReg CON $32 ' hours address (01 - 12) or (00 - 23)
    DayReg CON $36 ' day address (1 - 7)
    DateReg CON $33 ' date address (01 - 28/29, 30, 31)
    MonthReg CON $34 ' month address (01 - 12)
    YearReg CON $35 ' year address (00 - 99)
    Y2kReg CON $37 ' LEAP YEAR

    'Other Address definitions
    '===========================
    ContReg CON $0E ' control register
    StatusReg CON $3F ' STATUS register


    sec VAR BYTE ' seconds
    MINs VAR BYTE ' minutes
    hr VAR BYTE ' hours
    day VAR BYTE ' day
    date VAR BYTE ' date
    mon VAR BYTE ' month
    yr VAR BYTE ' year
    y2k var byte ' leap year ****
    stat var byte ' status resistor
    c_dtr var byte ' DTR control resistor
    c_atr var byte ' ATR control resistor
    c_int var byte ' INT control resistor
    c_bl var byte ' BL control resistor

    '-----------------------------------------------------------------

    ' Main program loop - in this case, it only updates the LCD with the time

    ' Display msg on LCD
    Lcdout $fe , 1 , "X1226 MOD"
    Lcdout $fe, $C0, "DEVBRD v1.d"
    pause 1000

    gosub start_cond
    GoSub SetTimeAndDate

    check:

    gosub read_rtc

    goto check

    LOOP:

    ' Read X1226
    I2CRead DS_SDA, DS_SCL, RTC, StatusReg, [stat]
    pause 10

    I2CRead DS_SDA, DS_SCL, RTC, ContReg, [c_dtr]
    pause 10

    ' Display Section
    ' ---------------
    Lcdout $fe , 1 ,"STATUS: ",HEX2 stat
    Lcdout $fe, $C0,"CNTRL: ",HEX2 c_dtr
    Pause 4000 ' Allow Time for user to view

    GOTO LOOP

    END

    SetTimeAndDate:
    '=============
    y2k=0:yr=0:date =0:mon =0:day=0:hr=0:mins=0:sec=0
    ' The constants below set the RTC to: 19:04:00 on 14-08-2006
    '################################################# ############
    yr=$06
    mon=$08
    date=$14
    day=$01
    hr=$19
    sec=$00
    mins=$04

    'Set the main Time
    I2CWrite DS_SDA, DS_SCL, RTC, StatusReg,[$02]
    Pause 10

    I2CWrite DS_SDA, DS_SCL, RTC, StatusReg,[$06]
    Pause 10

    I2CWrite DS_SDA, DS_SCL, RTC, SecReg,[sec,MINs,hr,date,mon,yr,day,y2k]
    Pause 10

    I2CWrite DS_SDA, DS_SCL, RTC, StatusReg,[0]
    Pause 10


    return

    read_rtc:

    ' Read X1226
    I2CRead DS_SDA, DS_SCL, RTC, SecReg, [sec,MINs,hr,date,mon,yr,day,y2k]
    pause 10


    ' Display Section
    ' ---------------
    Lcdout $fe , 1 ,"Time: ",HEX2 hr, ":", HEX2 MINs, ":", HEX2 sec
    Lcdout $fe, $C0,"Alarm: ",HEX2 date, ":", HEX2 mon, ":", HEX2 y2k
    Pause 500 ' Allow Time for user to view

    return


    start_cond:
    high DS_SCL : high DS_SDA : pause 10 : low DS_SDA


    return

    stop_cond:

    high DS_SCL : low DS_SDA : pause 10 : high DS_SDA

    return


    help appreciated. Thank you.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    first observation... you should add ADCON1=7 at the top of your code to disable ADCs
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default

    yes that's been added, as i just graduated my experiments on a selfmade development board using DS1337. The same pins and same header of code used for both the RTC working. The Datasheet of the RTC looks a bit too compicated to understand.

Similar Threads

  1. Easy and Accurate Clocks without RTC IC
    By paul borgmeier in forum Code Examples
    Replies: 18
    Last Post: - 28th October 2013, 21:28
  2. Low battery signal from an RTC
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th March 2008, 17:13
  3. PIC 16F877 I2C communications
    By sigmoideng in forum General
    Replies: 7
    Last Post: - 13th July 2007, 10:28
  4. Using RTC to generate long time delays
    By schlaray in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd January 2007, 00:31
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts