Well I compiled and loaded this example
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
TRISC= %11111111
;DB0 var byte[8]
CMCON = %00000111 ' Comparators = off
' Initialize LCD
LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250
' Set initial time
RTCYear = $10
RTCMonth = $03
RTCDate = $23
RTCDay = $02
RTCHour = $19
RTCMin = $35
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 RTCDate, "/",hex2 RTCMonth, "/" , hex2 RTCYear,_
" ", hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec
Pause 500
Goto mainloop
The correct date and time as per code was shown on the LCD. I then recompiled the melrtc.pbp code and this time I was able to run through the set up menu, and kept the date (today's date) and after the "memorise" was displayed the following was displayed:
2:59:01 AM
Wed 25 sep 2013
I have no idea what's screwing the code up, and as you said, given the age of the file, would of though that this would of been discussed years ago !
Bookmarks