ozarkshermit
- 25th February 2011, 16:04
Hi all
I am working with a DS1307, everything is great except for the AM/PM bit (bit 5 of the Hours Register). It seems to me that the bit should alternate from 1 to 0 (or vice-versa) when the time changes from 12:59:59 to 1:00:00.
I need to monitor the bit in case power is lost before midnite or noon, and restored later, when the AM-PM would change. Everything else works, I'm running in 12 hr mode, and when time goes from 12:59:59 to 1:00:00 as it should, the AM/PM bit does not change.
If I set AM initially, it stays that way. If I set PM initially, it stays that way. Never changes
What's up?
Ken
DaveC3
- 25th February 2011, 17:55
Not sure how you are monitoring the AM/PM bit but, here is how I detect am and pm
if rtchour.5 = 1 then
@ printstr2 37,1, "PM"
else
@ printstr2 37,1, "AM"
endif
rtchour is the byte from the rtc clock. the fifth bit is AM/PM, ignore the print stuff
Dave
ozarkshermit
- 25th February 2011, 18:48
Thanks Dave:
That's basically what I am doing. I have attached the stripped out part of the program to show exactly what I am doing. It is fairly well commented, and works fine except that the am / pm bit does not change
[code]
'************************************************* ****************
' PIC IS AN 18F2520 RUNNING AT 32 MHZ ON IT'S INTERNAL OSCILLATOR
'************************************************* *****************
' THE INTERRUPT WILL BE USED AS PART OF THE FINAL PROGRAM SO IS INCLUDED
'************************************************* **********************
INCLUDE "alldigital.pbp"
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
INCLUDE "modedefs.bas"
OSCCON = $70
OSCTUNE.6 = 1
DEFINE OSC 32
TRISA = %00001000
TRISB = %00000001
TRISC = %00000000
PB1 VAR PORTA.3
LED1 VAR PORTB.3 'ONLY USED TO VERIFY INTERRUPT IS WORKING
LED2 VAR PORTB.2 ' USED TO TEST THE AM PM BIT FOR 1 OR 0
ICSPDAT VAR PORTB.7
ICSPCLK VAR PORTB.6
Tx var PORTC.6 ' FOR SERIAL LCD
SCLpin var PORTA.7 ' 1302 CLOCK PIN
SDApin var PORTA.6 ' 1302 DATA PIN
SQWpin var PORTB.0
SS VAR BYTE
HH VAR Byte ' Hours 1-12
MM VAR ByTE ' Minutes 0-59
AM_PM VAR BYTE 'AM OR PM BIT SET
'*************************************
'**********************************
CounterA var byte
CounterB var byte
D0 VAR BYTE
D1 VAR BYTE
D2 VAR BYTE
D3 VAR BYTE
D4 VAR BYTE
D4=$90
PAUSE 1000 ' LET THE LCD STABALIZE
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _CLKINT, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'***************'********************************* ************************
@ INT_ENABLE INT_INT
if pb1=0 then goto SETUP 'BUTTON HELD DOWN AT POWER-UP TO GO TO SETUP
' LOOP HERE AFTER INITIAL SETUP, READ AND DISPLAY TIMER VALES
HERE:
I2CREAD SDAPin,SCLPin,$D0,$00,[SS,MM,HH,D0,D1,D2,D3,D4]
' THIS DOES NOT WORK - - BIT 5 DOES NOT CHANGE
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
IF HH.5=1 THEN LED2=1
IF HH.5=0 THEN LED2=0
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'************************************************* ****************
' THIS IS TO MONITOR THE RTC BITS 0 TO 7 VIA A SERIAL LCD BACKPACH
SEROUT2 Tx,84,[254,192,BIN8 HH]
' BIT 5 DOES NOT CHANGE ON THE TRANSITION FROM 12:59:50 TO 1:00:00
'************************************************* ******************
' CONVERT THE BCD VALUE BACK TO DECIMAL
cOUNTERb = SS
GOSUB bcd2DEC
ss = CounterB
cOUNTERb = MM
GOSUB bcd2DEC
MM = CounterB
cOUNTERb = hh
GOSUB bcd2DEC
hh = CounterB
SEROUT2 Tx,84,[254,128,#HH,58,#MM,58,#SS," "]
goto here
SETUP:
' START TIMES ARE ARBITRARY - - WILL BE SET VIA PUSHBUTTON LATER
' THE TIMES WERE CHOSEN TO ALLOW A QUICK TRANSITION FROM 12 TO 1 ON THE LOCK
CounterA = 12 'STARTING HOURS
Gosub ConvertBCD
hh=CounterB ' Save the Hours Value
'************************************************* *******************
'************************************************* ******************
' THIS IS USED TO SET THE CLOCK FOR 12 HR, START AT AM
HH = HH|%01000000 'NEED TO SET 12 HR AND AM
' DOES NOT MATTER IF AM OR PM IS PRESET HERE
'************************************************* ****************
'************************************************* *****************
CounterA = 59 'STARTING MINUTES
Gosub ConvertBCD
MM=CounterB ' Save the Minutes Value
CounterA=50 'STARTING SECONDS
gosub ConvertBCD
ss = CounterB
'WRITE TO THE 1307
I2CWRITE SDApin,SCLpin,$D0,$00,[ss,mm,hh,00,D1,D2,00,D4]
' WAIT TILL PUSHBUTTON RELEASE
while pb1=0
wend
goto here
'----------------------------------------
' INTERRUPT HANDLER 1 SEC INTERRUPT ON PORT B.0
'---------------------------------------
CLKINT:
TOGGLE LED1 ' FOR TEST OF INTERRUPT ONLY - REMOVE LATER
@ INT_RETURN
' CONVERT THE DECIMAL VALUE TO BCD
ConvertBCD:
CounterB=CounterA DIG 1
CounterB=CounterB<<4
CounterB=CounterB+CounterA DIG 0
Return
' CONVERT THE BCD VALUE TO DECIMAL
BCD2dec:
CounterB = ((CounterB >> 4)*10) + (CounterB & %1111)
return
END
[code]
ozarkshermit
- 25th February 2011, 21:44
PROBLEM SOLVED ? MAYBE
After trying everything in the book, I decided to set the starting time to 11:59:50.
When the time clicked over to 12:00:00, the bit changed ! !
It consistently changes on the transition from 11:59:59 to 12
That does not seem normal - but at least it works -
Did I miss something thinking that Am (or PM) changed from 11 to 12 vs 12 to 1 ?
Probably just my ignorance of the universal timekeeping protocol
Has anyone else tested this?
Ken
DaveC3
- 25th February 2011, 23:27
It is working correctly, AM/PM changes at 12:00
Dave
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.