bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
Friends,
I tried to write to DS1307, but it's not writing properly,
I tried to write 16:01:00 Sunday,2 June 2013
but the result is
15:05:36 Sun 10 Mon 2051,
What do I miss here ?
thanks
I tried to write to DS1307, but it's not writing properly,
I tried to write 16:01:00 Sunday,2 June 2013
but the result is
15:05:36 Sun 10 Mon 2051,
What do I miss here ?
thanks
Code:
void Write_DS1307(void)
{
unsigned char i, hour_format;
// Make sure we enable the Oscillator control bit CH=0 on Register 0x00
ds1307_addr[0]=ds1307_addr[0] & 0x7F;
// Start the I2C Write Transmission
i2c_start(DS1307_ID,DS1307_ADDR,TW_WRITE);
// Start from Address 0x00
i2c_write(0x00);
// Write the data to the DS1307 address start at 0x00
// DS1307 automatically will increase the Address.
ds1307_addr[0] = '0';
i2c_write(dec2bcd(ds1307_addr[0]));//second
_delay_ms(10);
ds1307_addr[1] = '1';
i2c_write(dec2bcd(ds1307_addr[1]));//minute
_delay_ms(10);
ds1307_addr[2] = '16';
i2c_write(dec2bcd(ds1307_addr[2]));//hour
_delay_ms(10);
ds1307_addr[3] = '0';
i2c_write(dec2bcd(ds1307_addr[3]));//day of the week
_delay_ms(10);
ds1307_addr[4] = '2';
i2c_write(dec2bcd(ds1307_addr[4]));//day of the month
_delay_ms(10);
ds1307_addr[5] = '6';
i2c_write(dec2bcd(ds1307_addr[5]));//month
_delay_ms(10);
ds1307_addr[6] = '13';
i2c_write(dec2bcd(ds1307_addr[6]));//year
}