JNOR07
- 30th August 2007, 00:19
Greetings:
I would like to use a DS1307 RTC display the date and time in the following format 11:59:00 AM & 01/01/07 but am unable to figure out how to set 12-hour mode and also display the AM/PM divisor, I have read the DS1307 datasheet and looked at Melanie's DS1307 example that uses three buttons to set the date and time, this example provides far more functionality than I really need, I would prefer to just set the date and time in the PicBasic Pro code (2.47) when I flash the MCU (PIC18F4620).
I am assume the solution has to do with I2CWrite/I2CRead commands but I am unable to figure out the proper syntax, I am including the PicBasic Pro code (2.47) I that I have been working with for your review.
I am a hobbyist trying to teach myself and am fairly new to electronics, microcontrollers, and PicBasic Pro, so any assistance is greatly appreciated.
Thank you,
- JNOR07
-- SNIP --
' Defines
' 40MHz (HSPLL)
Define OSC 40
' Variables
RTCSec Var Byte
RTCMin Var Byte
RTCHour Var Byte
RTCDay Var Byte
RTCDate Var Byte
RTCMonth Var Byte
RTCYear Var Byte
RTCCtrl Var Byte
RTCMode Var Byte
RTCDivisor Var Byte
' Alias and Modifiers
SDA Var PORTB.1
SCL Var PORTB.2
' Other
' LCD R/W line (Write)
Low PORTB.3
' Wait for LCD initialize
Pause 100
' Set initial time (hh:mm:ss) - 11:59:00 AM
' Set initial date (mm/dd/yy) - 01/01/07
RTCSec = $45
RTCMin = $59
RTCHour = $11
RTCDay = $01
RTCDate = $01
RTCMonth = $01
RTCYear = $07
RTCCtrl = 1
' (0) 24-hour & (1) 12-hour
RTCMode = 1
' (0) AM & (1) PM
RTCDivisor = 0
' GoSub SetRTC subroutine
Gosub SetRTC
' Goto MainLoop loop
Goto MainLoop
' SetRTC subroutine
SetRTC:
I2CWrite SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
Return
' GetRTC subroutine
GetRTC:
I2CRead SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
Return
' MainLoop loop
MainLoop:
' GoSub GetRTC subroutine
Gosub GetRTC
' Clear display
Lcdout $FE, 1
' Display RTC time
LCDOUT "T: ", hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec
' Move cursor to beginning of second line
lcdout $FE, $C0
' Display RTC date
Lcdout "D: ", hex2 RTCMonth, "/", hex2 RTCDate, "/" , hex2 RTCYear
' Wait 250ms
Pause 250
' Goto MainLoop loop
Goto MainLoop
End
-- SNIP --
I would like to use a DS1307 RTC display the date and time in the following format 11:59:00 AM & 01/01/07 but am unable to figure out how to set 12-hour mode and also display the AM/PM divisor, I have read the DS1307 datasheet and looked at Melanie's DS1307 example that uses three buttons to set the date and time, this example provides far more functionality than I really need, I would prefer to just set the date and time in the PicBasic Pro code (2.47) when I flash the MCU (PIC18F4620).
I am assume the solution has to do with I2CWrite/I2CRead commands but I am unable to figure out the proper syntax, I am including the PicBasic Pro code (2.47) I that I have been working with for your review.
I am a hobbyist trying to teach myself and am fairly new to electronics, microcontrollers, and PicBasic Pro, so any assistance is greatly appreciated.
Thank you,
- JNOR07
-- SNIP --
' Defines
' 40MHz (HSPLL)
Define OSC 40
' Variables
RTCSec Var Byte
RTCMin Var Byte
RTCHour Var Byte
RTCDay Var Byte
RTCDate Var Byte
RTCMonth Var Byte
RTCYear Var Byte
RTCCtrl Var Byte
RTCMode Var Byte
RTCDivisor Var Byte
' Alias and Modifiers
SDA Var PORTB.1
SCL Var PORTB.2
' Other
' LCD R/W line (Write)
Low PORTB.3
' Wait for LCD initialize
Pause 100
' Set initial time (hh:mm:ss) - 11:59:00 AM
' Set initial date (mm/dd/yy) - 01/01/07
RTCSec = $45
RTCMin = $59
RTCHour = $11
RTCDay = $01
RTCDate = $01
RTCMonth = $01
RTCYear = $07
RTCCtrl = 1
' (0) 24-hour & (1) 12-hour
RTCMode = 1
' (0) AM & (1) PM
RTCDivisor = 0
' GoSub SetRTC subroutine
Gosub SetRTC
' Goto MainLoop loop
Goto MainLoop
' SetRTC subroutine
SetRTC:
I2CWrite SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
Return
' GetRTC subroutine
GetRTC:
I2CRead SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
Return
' MainLoop loop
MainLoop:
' GoSub GetRTC subroutine
Gosub GetRTC
' Clear display
Lcdout $FE, 1
' Display RTC time
LCDOUT "T: ", hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec
' Move cursor to beginning of second line
lcdout $FE, $C0
' Display RTC date
Lcdout "D: ", hex2 RTCMonth, "/", hex2 RTCDate, "/" , hex2 RTCYear
' Wait 250ms
Pause 250
' Goto MainLoop loop
Goto MainLoop
End
-- SNIP --