Hi
Since the last ice age I have been trying to get my Nixie Clock (Atmega162) to talk to a DS1302 RTC.
Since I use Codevision, with a built-in library, I tried that first. It works, but I can't figure out how to get 12-hour mode.
So I stole some code from here:
http://www.nerdkits.com/library/...
made a few changes (just pin definitions etc), and it works! But again, its only 24-hour!
So I have been trying to figure out how to make it 12-hour...
Here in the initialization code, you can see where I have commented-out the 24-hr setting, and added a 12-hour setting.
I have commented each line, so you can see what I am trying to achieve -
-read 0x85 (read hours address)
-set bit 7 Hi (12-hour mode)
-write back to 0x84 (write hours address)
... and it totally doesn't work - still ticks over to 13:00:00
Can anybody see what I'm doing wrong?
Code snippet attached here, full code as attachments.
void rtc_init() { unsigned char tmp; // temp variable unsigned char tmp2; // temp variable reset(); send(0x8E); // tell ds1302 what we want to read/write send(0x00); // turn off write protect reset(); // read seconds then write them back. this gets the clock ticking send(0x81); tmp = read(); reset(); send(0x80); send(tmp); //------------added by me-------------- reset(); // read hours and make sure mode is on 12 hour BIT 7 SHOULD BE HI send(0x85); // tell the DS1302 that we want to read 0x85 (hours) tmp = read(); send(0x84); // tell the DS1302 that we want to WRITE 0x84 (hours) tmp |= (1<<7); //set bit 7 Hi send(tmp); //------------removed by me-------------- /* reset(); // read hours and make sure mode is on 24hour send(0x85); tmp = read(); tmp2 = (tmp & (1<<7)); if (tmp2) { reset(); send(0x84); tmp &= ~(1<<7); send(tmp); } */ }
Thanks!
Pete