unsigned char hr,min,sec,dow,mth,year,date;
char Jour_Sem [][6]={"Diman","Lundi", "Mardi", "Mercr", "Jeudi", "Vendr", "Samed"};
// length of literal=5 cars + Zero
static unsigned char Texte[80];
unsigned char *txt;
void ds1307_set_date(char dow,char date, char mth, char year );
void ds1307_get_date(void);
void ds1307_set_date(char date, char mth, char year, char day)
{
I2CStart();
writeI2C(DS1307_ADDR); // I2C write address
writeI2C(0x03); // Start at REG 0 - Seconds
writeI2C(bin2bcd(dow));
writeI2C(bin2bcd(date));
writeI2C(bin2bcd(mth));
writeI2C(bin2bcd(year));
writeI2C(0x10); // REG 7 - enable squarewave output pin
I2CStop();
}
void ds1307_get_date(void)
{
I2CStart();
writeI2C(DS1307_ADDR);
writeI2C(0x03); // Start at REG 3 - Day of week
I2CRestart();
writeI2C(DS1307_ADDR+1);
dow = bcd2bin(Read_I2C(0) ); // REG 3
date = bcd2bin(Read_I2C(0) ); // REG 4
mth = bcd2bin(Read_I2C(0) ); // REG 5
year = bcd2bin(Read_I2C(1)); // REG 6
I2CStop();
}
void main()
{
.....
ds1307_set_time(19,58,0);
ds1307_set_date(5, 23,8,13); // vend 23 aout 2013
txt=&Texte[0];
ds1307_get_date();
LCD_Erase_Line(4);
k=sprintf(txt,"Date is %s %02d/20%02d ",Jour_Sem [dow],date,mth,year);
LCD_puts(txt);