·· The % symbol indicates that the data following it is binary, hence 1's and 0's.· The backslash tells the SHIFTOUT command how many bits to SHIFTOUT.· This information can be found in the online help file under SHIFTOUT.· This also explains·LSBFIRST and LSBPRE.
As a side-note...You won't be using this exact command if you want to read an individual register.
And no, you probably won't just be able to replace BrstReg with SecReg...That code you posted has binary values that were being used to construct a command byte (8 bits).· You already have this value in the code from the StampWorks manual.· I would use that code as a template...Not the code you posted...Good luck!
'Define I/O pins and RTC variables
Clk CON 0
Dta CON 1
RTCCS CON 2
RTCCmd VAR Byte
Value VAR Byte
Seconds VAR Byte
Idx VAR Byte
'Define RTC Command Constants
SecReg CON %00000
CtrlReg CON %00111
'Set I/O pin states and directions
OUTS = %0000000000000000 'All logic low
DIRS = %0000000000000111 'I/O 0,1 and 2 are output, rest are input
Initialize:
'Set Time to 0 seconds
'NOTE: Date must be set only once for every power-up of DS1302 chip.
Seconds = $00
GOSUB SetTimeAndDate
LOOPer:
'Read out all date and time values and display them in two formats on
'the debug screen.
GOSUB ReadRTCBurst
DEBUG HOME,"seconds: ", DEC2 seconds
GOTO LOOPer
SetTimeAndDate:
'Write time values into all time-keeping registers, being sure to clear
'the write-protect bit in CtrlReg before the write, and set the
'write-protect bit after the write
FOR Idx = 0 TO 8
LOOKUP Idx,[noparse][[/noparse]0,Seconds,128],Value
LOOKUP Idx,[noparse][[/noparse]CtrlReg, SecReg, CtrlReg],RTCCmd
GOSUB WriteRTC
NEXT
RETURN
·· I'm not where I can try your code out for a few days...What exactly is happening?· What are you seeing on the display and which numbers appear to be skipped?
Comments
·· The % symbol indicates that the data following it is binary, hence 1's and 0's.· The backslash tells the SHIFTOUT command how many bits to SHIFTOUT.· This information can be found in the online help file under SHIFTOUT.· This also explains·LSBFIRST and LSBPRE.
As a side-note...You won't be using this exact command if you want to read an individual register.
And no, you probably won't just be able to replace BrstReg with SecReg...That code you posted has binary values that were being used to construct a command byte (8 bits).· You already have this value in the code from the StampWorks manual.· I would use that code as a template...Not the code you posted...Good luck!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--==<{Chris}>==--
'RTC Test1.bs2
'2/10/2005
' {$STAMP BS2}
' {$PBASIC 2.5}
'Define I/O pins and RTC variables
Clk CON 0
Dta CON 1
RTCCS CON 2
RTCCmd VAR Byte
Value VAR Byte
Seconds VAR Byte
Idx VAR Byte
'Define RTC Command Constants
SecReg CON %00000
CtrlReg CON %00111
'Set I/O pin states and directions
OUTS = %0000000000000000 'All logic low
DIRS = %0000000000000111 'I/O 0,1 and 2 are output, rest are input
Initialize:
'Set Time to 0 seconds
'NOTE: Date must be set only once for every power-up of DS1302 chip.
Seconds = $00
GOSUB SetTimeAndDate
LOOPer:
'Read out all date and time values and display them in two formats on
'the debug screen.
GOSUB ReadRTCBurst
DEBUG HOME,"seconds: ", DEC2 seconds
GOTO LOOPer
'==================== DS1302 Real-Time Clock Subroutines ===================
WriteRTCRAM:
'Write to DS1302 RAM Register
HIGH RTCCS
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%11\2,Value]
LOW RTCCS
RETURN
WriteRTC:
'Write to DS1302
HIGH RTCCS
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%10\2,Value]
LOW RTCCS
RETURN
ReadRTCBurst:
'Read all time-keeping registers in one burst
HIGH RTCCS
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,SecReg\5,%10\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds]
LOW RTCCS
RETURN
ReadRTCRAM:
'Read DS1302 RAM Register
HIGH RTCCS
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,RTCCmd\5,%11\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Value]
LOW RTCCS
RETURN
SetTimeAndDate:
'Write time values into all time-keeping registers, being sure to clear
'the write-protect bit in CtrlReg before the write, and set the
'write-protect bit after the write
FOR Idx = 0 TO 8
LOOKUP Idx,[noparse][[/noparse]0,Seconds,128],Value
LOOKUP Idx,[noparse][[/noparse]CtrlReg, SecReg, CtrlReg],RTCCmd
GOSUB WriteRTC
NEXT
RETURN
Thanks,
Matthew
·· I'm not where I can try your code out for a few days...What exactly is happening?· What are you seeing on the display and which numbers appear to be skipped?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--==<{Chris}>==--
1) the numbers go from 00-89, instead of 00-60
2) it skips the numbers 10-15, 26-31, 42-47, 58-63, 74-79, 90-99
Thanks,
Matthew
Yipee!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--==<{Chris}>==--