CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DS1307 SQW/OUT pin generate pulses at 1 second intervals

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bolubeyi



Joined: 27 Apr 2012
Posts: 15
Location: TURKEY

View user's profile Send private message

DS1307 SQW/OUT pin generate pulses at 1 second intervals
PostPosted: Wed Sep 05, 2012 9:14 am     Reply with quote

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?
temtronic



Joined: 01 Jul 2010
Posts: 9208
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Sep 05, 2012 10:20 am     Reply with quote

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.

hth
jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group