' LCD clock program using Dallas1202/1302 RTC Device 16F877 Declare XTAL 20 REMARKS ON ' Graphic LCD pin Assignments Declare LCD_DTPIN PORTD.0 Declare LCD_RSPIN PORTE.0 Declare LCD_ENPIN PORTE.1 Declare LCD_LINES 2 Declare LCD_INTERFACE 8 ' Alias pins Symbol RST = PORTA.2 Symbol IO = PORTC.1 Symbol SCLK = PORTC.3 ' Allocate variables Dim rtcyear as byte Dim rtcday as byte Dim rtcmonth as byte Dim rtcdate as byte Dim rtchr as byte Dim rtcmin as byte Dim rtcsec as byte Dim rtccontrol as byte '------------------------------------------------------------------------------- Low RST ' Reset RTC Low SCLK ADCON1 = 7 ' PORTA and E digital Low PORTE.2 ' LCD R/W low = write Delayms 100 ' Wait for LCD to startup ' Set initial time to 8:00:00AM 07/16/99 rtcyear = $99 rtcday = $06 rtcmonth = $07 rtcdate = $16 rtchr = $08 rtcmin = 0 rtcsec = 0 Gosub settime ' Set the time Goto mainloop ' Skip subroutines '------------------------------------------------------------------------------- ' Subroutine to write time to RTC Settime: RST = 1 ' Ready for transfer Shout IO,SCLK,LSBFIRST,[$8e,0] ' Enable write RST = 0 ' Reset RTC RST = 1 ' Ready for transfer ' Write all 8 RTC registers in burst mode Shout IO,SCLK,LSBFIRST,[$be,rtcsec,rtcmin,rtchr,rtcdate,rtcmonth,rtcday,rtcyear,0] RST = 0 ' Reset RTC Return '------------------------------------------------------------------------------- ' Subroutine to read time from RTC gettime: RST = 1 ' Ready for transfer Shout IO,SCLK,LSBFIRST,[$bf] ' Read all 8 RTC registers in burst mode Shin IO,SCLK,LSBPRE,[rtcsec,rtcmin,rtchr,rtcdate,rtcmonth,rtcday,rtcyear,rtccontrol] RST = 0 ' Reset RTC Return '------------------------------------------------------------------------------- ' Main program loop - updates the LCD with the time Mainloop: Gosub gettime ' Read the time from the RTC ' Display time on LCD Print at 1,1, hex2 rtcmonth,"/",hex2 rtcdate,"/",hex2 rtcyear," ",hex2 rtchr,":",hex2 rtcmin,":",hex2 rtcsec Delayms 300 ' Do it approx 3 times a second Goto Mainloop ' Do it forever