Hi Guys and Gals,
I'm trying to the the RTC2 module (see image below) working on my EasyPIC5 board.
I've scoured this forum, and trawled the web for various examples but still can't get the date and time displayed on the LCD. My guess is that I'm either missing something in the port config (can't say I can understand the datasheet but is seems that you don't need to set any fancy register) or the module has developed a fault.
The following code compiles fine and loads on the target chip (16F877a). It runs but displays 00/00/00 00:00:00 on the LCD.
The chip is using a 20Mhz xtal if that has any bearing on the issue, but I guess I should still be able to read and write to the DS1307 if the timing was out ?Code:@ __config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF DEFINE OSC 20 CLEAR ;----[LCD definitions]------------------------------------------------------ DEFINE LCD_DREG PORTB ' LCD Data port DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4) DEFINE LCD_EREG PORTB ' LCD Enable port DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD) DEFINE LCD_RSREG PORTB ' LCD Register Select port DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD) DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits) DEFINE LCD_LINES 4 ' number of lines on LCD DEFINE LCD_COMMANDUS 2000 ' Command delay time in us DEFINE LCD_DATAUS 50 ' Data delay time in us 'RTC pins on 877a SDA Var PORTC.4 SCL Var PORTC.3 ' Allocate variables RTCYear Var Byte RTCMonth Var Byte RTCDate Var Byte RTCDay Var Byte RTCHour Var Byte RTCMin Var Byte RTCSec Var Byte RTCCtrl Var Byte ' Initialize LCD LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Set initial time to 8:00:00AM 06/21/05 RTCYear = $10 RTCMonth = $03 RTCDate = $22 RTCDay = $02 RTCHour = $12 RTCMin = 0 RTCSec = 0 RTCCtrl = 0 Gosub set ' Set the time Goto mainloop ' Skip over subroutines ' Subroutine to write time to RTC set: I2CWrite SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl] Return ' Subroutine to read time from RTC gettime: I2CRead SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl] Return mainloop: Gosub gettime ' Read the time from the RTC ' Display time on LCD Lcdout $fe, 1, hex2 RTCMonth, "/", hex2 RTCDate, "/" , hex2 RTCYear,_ " ", hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec Pause 500 Goto mainloop





Bookmarks