DS1307 SQW/OUT pin generate pulses at 1 second intervals
Posted: Wed Sep 05, 2012 9:14 am
Hi, I use ds1307 and ccs c. I want to generate pulses at 1 second intervals from ds1307 SQW/OUT - Square Wave/Output pins. How can I do this? How do I set ds1307?
Here's the way I do it...
Sorry I don't know where this function came from but it does work...
Code:
void ds1307_init(void)
{
BYTE seconds = 0;
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x00); // REG 0
i2c_start();
i2c_write(0xD1); // RD from RTC
seconds = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307
i2c_stop();
seconds &= 0x7F;
delay_us(3);
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x00); // REG 0
i2c_write(bin2bcd(seconds)); // Start oscillator with current "seconds value
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x07); // point to Control Register
i2c_write(0x10); // Enable squarewave output pin
i2c_stop();
}
The second last line does the job. If you read the DS1307 datasheet, it'll also explain how to set for other interrupt rates.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum