Saturday, March 12, 2011

DS1307 : Setting Time

There is a question from charlie about how to set time in DS1307 . The code here shows how to write time to DS1307. My C compiler is MikroC 8.0.

void write_ds1307(unsigned short address,unsigned shortw_data)
{
I2C_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0I2C_Wr(0xD0); // send byte via I2C (device address + W)
I2C_Wr(address); // send byte (address of DS1307 location)
I2C_Wr(w_data); // send data (data to be written)
I2C_Stop(); // issue I2C stop signal
}

//Set Time
write_ds1307(0,0x80); //Reset second to 0 sec. and stop Oscillator
write_ds1307(1,0x27); //write min 27
write_ds1307(2,0x14); //write hour 14
write_ds1307(3,0x02); //write day of week 2:Monday
write_ds1307(4,0x17); // write date 17
write_ds1307(5,0x06); // write month 6 June
write_ds1307(6,0x08); // write year 8 --> 2008
write_ds1307(7,0x10); //SQWE output at 1 Hz
write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator 
It is your task to incorporate the code with buttons for setting time. I have written code for taking care of the buttons but there are some bugs so I cannot show it now.

0 comments For DS1307 : Setting Time Article

What do you think about DS1307 : Setting Time article???
Please give your comments about DS1307 : Setting Time article in this Blog. give your comments about DS1307 : Setting Time article, either in the form of criticism and advice and support will be very meaningful for me to progress this blog

Post a Comment