Monday, February 16, 2015

Square Wave Output From DS1307 Real Time Clock

Interfacing DS1307 Real Time Clock with PIC16F877A Microcontroller

There is a pin on the DS1307 IC named SQW/OUT (Square Wave/Output Driver) When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of four square-wave frequencies (1Hz, 4kHz, 8kHz, 32kHz). The SQW/OUT pin is open drain and requires an external pullup resistor.
To enable this pin output you have to access to the following register (register 07h):
square wave output ds1307 mikroc
square wave output ds1307 mikroc

To get a square wave output at 1Hz, RS0 and RS1 must be zeroes. So we have to send 0X10 to make our square wave output frequency equal to 1Hz.
Square Wave Output From DS1307 circuit:
The DS1307 have to programmed one time if it equipped with battery, which means that we can disconnect the DS1307 with the microcontroller.
The LED blinks 0.5s ON and 0.5s OFF.

square wave output ds1307 mikroc
Square Wave Output From DS1307 mikroC code:
MikroC code:

void main(){
I2C1_Init(100000);  // initialize I2C protocol at 100KHz
 I2C1_Start();      // start signal
   I2C1_Wr(0xD0);   // address DS1307
   I2C1_Wr(0x07);   // start from word at address (REG7)
   I2C1_Wr(0x10);   // write SQW at 1Hz
   I2C1_Stop();     // stop signal
 }

References:
DS1307 Data sheet from Maxim Integrated.