|
|
View previous topic :: View next topic |
Author |
Message |
domdom
Joined: 06 Sep 2006 Posts: 29
|
weird case for rtc ds1302 |
Posted: Sat Sep 22, 2007 7:47 am |
|
|
I am using real time clock to provide me timing information.
But my clock output in hyperterminal never update the seconds.
Output:
22/09/07
22:30:01
Code: | #include <16F873A.h>
#fuses HS,WDT,NOLVP,BROWNOUT
#USE DELAY (CLOCK=20000000) //this used to be 4mega
#include <DS1302.C>
#use rs232(baud=9600,xmit=pin_C6,rcv=pin_C7)
void main()
{
BYTE day,mth,year,dow,hour,min,sec;
rtc_init();
setup_wdt(wdt_2304MS);//Set date for 22 Sep 2007
rtc_set_datetime(22,9, 7,6,22,30); //Set time for 22:30:20
while(1)
{
delay_ms(1000);
rtc_get_date( day, mth, year, dow);
rtc_get_time( hour, min, sec );
printf("\f\%02d/\%02d/\%02d\r\n",day,mth,year);
printf("\%02d:\%02d:\%02d",hour,min,sec);
}
restart_wdt();
} |
Can someone tell me what wrong with my code? |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Sat Sep 22, 2007 8:12 am |
|
|
put your restart_wdt inside the while loop
Ken |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Sat Dec 26, 2009 7:07 pm |
|
|
Hi,
I know it's a very old post but i think this could be useful for someone else.
While playing with the DS1302 I've found this in the driver code.
Code: | void rtc_set_datetime(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min) {
write_ds1302(0x86,get_bcd(day));
write_ds1302(0x88,get_bcd(mth));
write_ds1302(0x8c,get_bcd(year));
write_ds1302(0x8a,get_bcd(dow));
write_ds1302(0x84,get_bcd(hr));
write_ds1302(0x82,get_bcd(min));
write_ds1302(0x80,get_bcd(0));
} |
The last line Code: | write_ds1302(0x80,get_bcd(0)); | automatically set the clock to 0 seconds at each calls of this date/time setting function.
This is your problem.
Regards,
Laurent |
|
|
Ttelmah Guest
|
|
Posted: Sun Dec 27, 2009 3:39 am |
|
|
This is the 'normal' way you set a clock!....
If you look at things like desk alarms, you put in with the buttons, the time for the 'next' minute, and when you finally advance out of the setting menu, or release the buttons, the clock 'starts' on the set time, with the seconds=0. Very few allow you to set the seconds.
My wrist watch does this, as do all the digital alarms in my house.
What is wrong, is that it should be better documented. :(
Best Wishes |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Sun Dec 27, 2009 3:37 pm |
|
|
Quote: | This is the 'normal' way you set a clock!....
If you look at things like desk alarms, you put in with the buttons, the time for the 'next' minute, and when you finally advance out of the setting menu, or release the buttons, the clock 'starts' on the set time, with the seconds=0. Very few allow you to set the seconds. |
I know put sometime in some applications you especially _WANT_ to update the seconds. Ex: when clock syncing you usually don't want to wait to the next 0 seconds to sync the DS1302. Instead you just input hour : min : sec so the new function is easy to tweak it will look like this:
Code: |
void rtc_set_datetime(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min, BYTE sec) {
write_ds1302(0x86,get_bcd(day));
write_ds1302(0x88,get_bcd(mth));
write_ds1302(0x8c,get_bcd(year));
write_ds1302(0x8a,get_bcd(dow));
write_ds1302(0x84,get_bcd(hr));
write_ds1302(0x82,get_bcd(min));
write_ds1302(0x80,get_bcd(sec));
} |
The driver code is well done by CCS but they are some exceptions that you need to modify some drivers to get it match the product datasheet.
Happy Holidays!
Best Regards,
Laurent |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|