|
|
View previous topic :: View next topic |
Author |
Message |
jahan
Joined: 04 Apr 2005 Posts: 63
|
DS1302 problem with display data on LCD |
Posted: Wed Nov 23, 2005 10:16 am |
|
|
Hi all,
I've setup a simple DS1302 with LCD on PIC16F84A running 4MHz. PCWH compiler version 3.223.
The code is copy from EX_RTCLK.C. I can set the time, and also display the time on the LCD, but the problem is that the data shows wrong.
This is what I use to display data on the LCD:
Code: |
printf(lcd_putc,"%2u/%2u/%2u\n%2u:%2u:%2u",day,mth,year,hour,min,sec);
|
the error on LCD display is that the seconds goes as follow:
1,2,3,4,5,6,7,8,9,16,17,18,...
what happened to 10? 11? 12? ...
from this error, all the minute and hours are also showing wrong data.
Any help ??? |
|
|
cmdrdan
Joined: 08 Apr 2005 Posts: 25 Location: Washington
|
|
Posted: Wed Nov 23, 2005 12:12 pm |
|
|
The DS1302 and DS1307 store time as BCD numbers, not binary. You'll have to make sure that you're loading the BCD version of the time into the chip when you set it, and convert BCD to binary when you read it. There are a number of topics on this board to that regard....
Dan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 23, 2005 12:20 pm |
|
|
Are you sure you have compiler vs. 3.223, because I installed that
version and EX_RTCLK.C has this line in it:
Code: | printf(lcd_putc,"%2X/%2X/%2X\n%2X:%2X:%2X",day,mth,year,hour,min,sec); |
It's using hex format to display the bytes. That's because in that
version of the examples, they don't convert from the BCD format
used by the ds1302 into binary format. So to display the numbers
properly, they use hex format for printf.
The EX_RTCLK.C code that you posted is the one that comes with
the latest version of the compiler. But in the latest version, the
DS1302.C file has some new routines in it, to do BCD-to-binary
and binary-to-BCD conversion.
So I wonder what version of the compiler you have ? Some sort
of mixture of two versions ? |
|
|
jahan
Joined: 04 Apr 2005 Posts: 63
|
|
Posted: Wed Nov 23, 2005 1:58 pm |
|
|
I've downloaded the upgrade to the compiler after purchase.
I'm not sure if the examples was downloaded along with the upgrade to the compiler.
can anybody share the BCD to binary & Binary to BCD?
Thankx |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
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
|