Sudhp
Member level 4
- Joined
- Oct 11, 2013
- Messages
- 69
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Location
- India
- Activity points
- 528
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#define DS1307_ID 0xD0
#define SEC 0x00
#define MIN 0x01
#define HOUR 0x02
#define DOW 0x03 <- Day of week
#define DATE 0x04
#define MONTH 0x05
#define YEAR 0x06
void ds1307_get_date(void)
{
I2CStart();
writeI2C(DS1307_ADDR);
writeI2C(0x03); // Start at REG 3 - Day of the 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();
}
hello,
in your program , you forget the day of the week !
add this variable and treat it in your program..
Code:#define DS1307_ID 0xD0 #define SEC 0x00 #define MIN 0x01 #define HOUR 0x02 #define DOW 0x03 <- Day of week #define DATE 0x04 #define MONTH 0x05 #define YEAR 0x06
example:
Code:void ds1307_get_date(void) { I2CStart(); writeI2C(DS1307_ADDR); writeI2C(0x03); // Start at REG 3 - Day of the 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(); }
Yes , make a loop and print day based on the number you get !Yeah.....I did this....
If i have to show sunday then I will give a command of 0x01 to save in rtc.....
but it's display on lcd as 1 as read from rtc......If I have to show sunday then should I make a program for this or It will show sunday on the lcd.....???
Yes , make a loop and print day based on the number you get !
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);
hello
example
Code: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);