-
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.
-
first observation... you should add ADCON1=7 at the top of your code to disable ADCs
-
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.