Hi all,
Heres a code example that i have used to set an RTC by a serial input, its probably not the most efficient code, but it works and could help some of you out
It converts the Decimal input to BCD for the DS1302 DS1307 RTC
all the variables are BYTES
Code:'------ SET RTC ------------------------------------------------------------------------------------------- SetRTC: HSEROUT ["Enter Day" , 13,10] ' Output HSERIN [DEC2 r_day] RTCday=r_day DIG 1 RTCday=RTCday <<4 RTCday=RTCday+(r_day DIG 0) HSEROUT ["Enter Month" , 13,10] ' Output HSERIN [DEC2 r_month] RTCmonth=r_month DIG 1 RTCmonth=RTCmonth<<4 RTCmonth=RTCmonth+(r_month DIG 0) HSEROUT ["Enter Year 20xx" , 13,10] ' Output HSERIN [DEC2 r_year] RTCyear=r_year DIG 1 RTCyear=RTCyear<<4 RTCyear=RTCyear+(r_year DIG 0) HSEROUT ["Enter Hour" , 13,10] ' Output HSERIN [DEC2 r_hour] RTChour=r_hour DIG 1 RTChour=RTChour<<4 RTChour=RTChour+(r_hour DIG 0) HSEROUT ["Enter Minute" , 13,10] ' Output HSERIN [DEC2 r_min] RTCmin=r_min DIG 1 RTCmin=RTCmin<<4 RTCmin=RTCmin+(r_min DIG 0) r_sec=$00 pause 100 HSEROUT ["Writing to RTC" , 13,10] ' Output I2CWRITE SDA,SCL,$D0,$00,[r_sec,RTCmin,RTChour,$7,RTCday,RTCmonth,RTCyear,$90] ' Write to DS1307 pause 500 goto setup '=============================================================================================================================




Bookmarks