Wednesday, August 27, 2008

PIC Clock - with DS1307

After so many sleepless nights I managed to run a clock using a PIC, this time using the Maxim RTC chip, DS1307. This time I didn't use multiplexing to drive the four seven segments, instead I used another Maxim product, MAX7221 display driver. It has SPI interface and can drive upto 8 seven segments with display brightness control and that is cool... Since I'm using the PIC16F628 at the moment, I had to use Sotware SPI to drive the display. It worked without giving much problems but later came the most difficult part, DS1307. Oh boy, what a mess... It gave me thousand and one problems and took nearly a month to get it worked. But truly speaking I leaned a lot and mastered the DS1307. This fellow is really great and extremely easy to communicate via the I2C interface. I had problems because I used Software I2C routines in MikroC. I think SOFT_I2C has a problem with PORTA and after so many trial and error attempts it worked when I moved the DS1307 to PORTB. Now both DS1307 (I2C) and MAX7221 (SPI) are in PORTB and work without any trouble. DS1307 needs an external crystal (32.768kHz) to operate and again Maxim has another great product DS32KHZ, a temperature compensated 32.768kHz crystal which I found extremely accurate. So far the clock is running smoothly and accurately, which needs lot of other things, a way to set time, view calendar, set alarm etc. And I'm thinking of attaching a Temperature sensor too. Pictures, videos, schematic and code segments will appear shortly.