AM/PM indicator
MR
Posts: 46
I have viewed the stamp works, and other posts on the forum but I am still stuck.
How do I put the DS1302 in 12 hour mode using the attached code?
Help me understand what is inside the brackets in these subroutines? I didn't write this code but I am trying to learn from it.
They say if you Play a Microsoft CD backwards you can hear satanic messages, that's nothing because if you play it forward it installs Vista!
I didn't Fail 10,000 times, I simply found 10,000 ways that didn't work. -Thomas Edison
How do I put the DS1302 in 12 hour mode using the attached code?
Help me understand what is inside the brackets in these subroutines? I didn't write this code but I am trying to learn from it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔MR said...
WriteRTCRAM:
'Write to DS1202 RTC
HIGH RTCReset
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%11\2,Temp]
LOW RTCReset
RETURN
WriteRTC:
'Write to DS1202 RTC
HIGH RTCReset
SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,RTCCmd\5,%10\2,Temp]'
LOW RTCReset
RETURN
ReadRTCBurst:
HIGH RTCReset
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Year,Year]
LOW RTCReset
RETURN
ReadRTCRAM:
HIGH RTCReset
SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,RTCCmd\5,%11\2]
SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Temp]
LOW RTCReset
RETURN
They say if you Play a Microsoft CD backwards you can hear satanic messages, that's nothing because if you play it forward it installs Vista!
I didn't Fail 10,000 times, I simply found 10,000 ways that didn't work. -Thomas Edison
Comments
The SHIFTOUT statements all transfer 16 bits to the DS1302 (the DS1302 is upward compatible from the DS1202). The first 8 bits is the command byte as specified on the bottom of page 5 of the datasheet. Note that the LSB comes first as described there. The %0\1 or %1\1 is the LSB, then there's 5 bits of address, then %11\2 or %10/2 for the last 2 bits (for RTC vs RAM). The next 8 bits is the actual data to be written to the DS1302 register or RAM location. The same thing happens on a read except the last 8 bits are read using a SHIFTIN.
Okay I understand setting Bit 7 will toggle 12hr/24hr modes on the DS 1302, and Bit 5 selects am/pm of the hours register. I have played around with the code all night and I still can't get the
clock into 12 hour mode. When I set the clock to 12:59:55 it cycles over to 13:00:00 and not 01:00:00 PM. I don't understand how to change bit7 and bit5 of the hours register. Please look at the attached code and tell me
what I am doing wrong.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
They say if you Play a Microsoft CD backwards you can hear satanic messages, that's nothing because if you play it forward it installs Vista!
I didn't Fail 10,000 times, I simply found 10,000 ways that didn't work. -Thomas Edison
Here is what you are looking for
·reg = $84········· ' Point to register 84h
ioByte = %00000000 ' initializes the clock in 24 hour mode and clear the hours to "00"
GOSUB RTC_Out····· ' Send Command
·reg = $84········· ' Point to register 84h
ioByte = %00000010 ' initializes the clock in·12 hour mode and clear the hours to "00"
GOSUB RTC_Out····· ' Send Command
This from the·( DS1302_Demo.bs2··<<..·click here·)
' When reading the DS1302's clock data, BIT7 will be set when the RTC
· ' is in 12 Hour Mode.· We need to save this information, but we must
· ' then clear this bit so it doesn't interfere with the display.· Since
· ' the data is in BCD format, leaving BIT7 set would give us invalid
· ' value to display.· If the DS1302 is in 12 Hour Mode then we must
· ' also save the status of BIT5, which is the AM/PM bit, however, once
· ' again we must clear this Bit so our digits are valid for display.
· ' If the DS1302 is in 24 Hour Mode we must LEAVE BIT5 alone, since it
· ' is used when the hours are greater than 19.
· ' These bits remain at their original value on the DS1302, and will
· ' be reset on each read.
· modeFlag = clockMode················· ' Save 12/24 Hour Clock Mode
· clockMode = 0························ ' Clear BIT7
· ampmFlag = ampm······················ ' Save AM/PM Flag
· IF modeFlag = 1 THEN ampm = 0········ ' Clear BIT5 (12 Hour Mode only!)
· DEBUG " ", HEX2 month, "/", HEX2 date, "/", HEX2 year, " "
· ' If clockMode is cleared, then the modeFlag will be 0 and the
· ' time will display in 24 hour format.
· ' If clockMode is set, then the modeFlag will be 1 and the
· ' time will display in 12 Hour format with an AM/PM suffix.
· IF (modeFlag = Hr24) THEN············ ' Check For 24 Hour Display mode
··· DEBUG HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs
· ELSE
··· DEBUG HEX2 hrs, ":", HEX2 mins····· ' Print Hours/Minutes
··· IF ampmFlag = 0 THEN
····· DEBUG "AM"
··· ELSE
····· DEBUG "PM"
··· ENDIF
··· DEBUG " [noparse][[/noparse]", HEX2 secs, "]"
· ENDIF
· RETURN
I hope this helps
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 3/28/2009 1:44:02 PM GMT