Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Days programming for rtc DS1307

Status
Not open for further replies.

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
hii experts....
I am working on rtc ds1307.....I have copied program for date and time(from net) and it is working properly......
Now I have to add days in this.....I don't know how to do this......
somebody plz help me......
 

Attachments

  • rtc.txt
    2.2 KB · Views: 62

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();
}
 
  • Like
Reactions: Sudhp

    Sudhp

    Points: 2
    Helpful Answer Positive Rating
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();
}


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

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 !
 
  • Like
Reactions: Sudhp

    Sudhp

    Points: 2
    Helpful Answer Positive Rating
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);
 
  • Like
Reactions: Sudhp

    Sudhp

    Points: 2
    Helpful Answer Positive Rating
Thanks.......

- - - Updated - - -

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);

Thanks....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top