PDA

View Full Version : DS1307 sample Program



Mark
- 29th September 2004, 01:37
I am working on a timer that will turn on at high tide.

I'm just getting started with this RTC and have been experimenting with Melanie's MN1307 -- It is very helpful & explains alot - but I am having some problems & I hope some one who has use this sample program may be able to shed some light.

I have wired this up & compiled the program with additional I2C write line to get the 1307 initialised. SetupPreset now looks like this:

SetupPreset:
RTCSec=$00 ' Seconds preset to 00
RTCMin=$15 ' Minutes preset to 15
RTCHour=$13 ' Hours preset to 13'00
RTCWDay=$01 ' Weekday preset to 01
RTCDay=$12 ' Day preset 12
RTCMonth=$06 ' Months preset to June
RTCYear=$02 ' Year preset to 2002
RTCCtrl=$10 ' Control preset to output 1 second 'Tick' on SQWpin
I2CWrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,RTCCtrl]
Pause 1000

Return


The display shows the 12 June 2002 defalut time OK

I'm having a problem with the setup loop - I can't get it to advance from the 12 24 hour set mode screen

all three buttons toggle between the 12 & 24

after the 20 secs delay it goes back to the time display as it should.

I'm not sure if I have a hardware or software problem - All three switches seem to be OK

Any suggestions will be appreciated.

Thanks

Melanie
- 29th September 2004, 01:58
Oh my Gawd... it's two years already since I wrote that!

Assuming you've connected the buttons as per the text... the SET Button...

SetButton var PORTB.5 ' Press to Set/memorise Button

... will save the current Set-Up and advance to the next option. The first option is the setting for 12/24 hour mode... if you're stuck in it, then it looks like you might have miss-wired the Buttons - especially the SET Button.

With no Buttons pressed, PortB.4, 5 and 6 should all be High. Check them with a DVM or scope. Then with SET only pressed, only PortB.5 should go LOW (0v), the others remain High.

You might have a short between SET and one of the adjacent pins. In the software, the code for Increment and Decrement is executed before SET, therefore if one of those pins are going Low (as it looks might be the case), all that happens is you end up toggling between 12/24 hour mode and never getting any further.

I really must update that one day for something more sophisticated... it's embarassing looking at it...

Mark
- 29th September 2004, 02:25
Thanks Melanie.

The switches were fine but there is a short on the proto18 PCB I used to build this between B5 and B6

I gave up looking for it after a while just moved the reset to B7.

Works fine now. Thanks for the great example & the fantastic troubleshooting -