CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DS1302 problem with display data on LCD

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jahan



Joined: 04 Apr 2005
Posts: 63

View user's profile Send private message Send e-mail

DS1302 problem with display data on LCD
PostPosted: Wed Nov 23, 2005 10:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 12:12 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 12:20 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 23, 2005 1:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 23, 2005 2:05 pm     Reply with quote

Use the forum's search page to search for these keywords:
bcd2bin bin2bcd
http://www.ccsinfo.com/forum/search.php
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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