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 CCS Technical Support

DS1302 display error

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



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

DS1302 display error
PostPosted: Wed Nov 23, 2011 7:26 am     Reply with quote

hello guys
I make a test code that uses the ds1302.c driver and lcd.c driver with PIC18F4520. After I set the time and data, it displays wrong time and data.

As follows is my code. I can't find where I'm wrong in this code, and pls help me !!
Code:

#include <18f452.h>
//#device ICD=TRUE
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay (clock = 20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8)
#define  PORTA 0xF80
#define  PORTB 0xF81
#define  PORTC 0xF82                           
#define  PORTD 0XF83
                       
//=============LCD PIN=============
#define LCD_ENABLE_PIN  PIN_A5                  // RA     
#define LCD_RS_PIN      PIN_A2                   //RS         
#define LCD_RW_PIN      PIN_A3                   //
//=============DS1302 PIN===========
#define RTC_SCLK PIN_E2
#define RTC_IO   PIN_E1
#define RTC_RST  PIN_E0


#include <ds1302.c>
#include <lcd.c>
byte day,mth,year,dow,hour,min,sec;


void main()
{
   
   lcd_init(); 
   rtc_init();
 
   rtc_set_datetime(22,11,11,03,9,10,33);
   //rtc_set_datetime(day, mth, year, dow, hour, min,sec);


   
   while(true)
   {
      delay_ms(1000);
      rtc_get_date( day, mth, year, dow);
      rtc_get_time( hour, min, sec );
      printf(lcd_putc,"\f\%2d/\%2d/\%2d\n",day,mth,year);
      printf(lcd_putc,"\%2d:\%2d:\%2d",hour,min,sec);

      /*rtc_get_time(hour,minute,second);
      rtc_get_date(day,mth,year,dow) ;
      printf(lcd_putc,"%2u/%2u/%2u\n%2u:%2u:%2u",day,mth,year,hour,minute,second);
      */
      //delay_ms(1000);
   }
}


I modified somewhere in ds1302.c driver as follow:
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 1602LCD display the data and time:
44/11/12
40:10:28


Where wrong ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2011 1:53 pm     Reply with quote

Post a link to the schematic of your PIC and ds1302 circuit.
You can use a free image hosting website to host your schematic image:
http://www.imageshack.com/
Then you can give us the link to it.
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

PostPosted: Thu Nov 24, 2011 12:11 am     Reply with quote

PCM programmer wrote:
Post a link to the schematic of your PIC and ds1302 circuit.
You can use a free image hosting website to host your schematic image:
http://www.imageshack.com/
Then you can give us the link to it.

Sorry, I can't open this web, it is very slow when I want to open it.
Pls who can support a new upload web for my schematic.

Thank you very much!

My schematic set as follow:
DS1302 pins

pin1 Vc2-------5V, pin2&pin3------Crystal, pin4---GND
pin8 VC1 ------battery , pin6------IO, pin7------SCLK
pin5------Rst

PIC18F4520 pin
RE0-------RST ,RE1---------IO,RE2-------SCLK


Last edited by leevise on Thu Nov 24, 2011 7:18 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 24, 2011 2:16 pm     Reply with quote

Quote:

pin1 Vc2-------5V, pin1 & pin2------Crystal

Here you claim to have pin 1 used for both Vcc2 and the crystal.
That's not correct.

What is your CCS compiler version ?
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

PostPosted: Thu Nov 24, 2011 7:21 pm     Reply with quote

PCM programmer wrote:
Quote:

pin1 Vc2-------5V, pin1 & pin2------Crystal

Here you claim to have pin 1 used for both Vcc2 and the crystal.
That's not correct.

What is your CCS compiler version ?


Sorry, I wrote wrong, it should be pin2&pin3-----crystal.
My CCS compiler version is 4.110.

My schematic upload :http://ul.to/znrd51p6
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 24, 2011 7:44 pm     Reply with quote

Your schematic shows capacitors on the crystal. The ds1302 data sheet
says specifically not to do this:
Quote:

OSCILLATOR CIRCUIT

The DS1302 uses an external 32.768kHz crystal. The oscillator circuit
does not require any external resistors or capacitors to
operate. See page 5:

http://pdfserv.maxim-ic.com/en/ds/DS1302.pdf
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

PostPosted: Fri Nov 25, 2011 3:05 am     Reply with quote

PCM programmer wrote:
Your schematic shows capacitors on the crystal. The ds1302 data sheet
says specifically not to do this:
Quote:

OSCILLATOR CIRCUIT

The DS1302 uses an external 32.768kHz crystal. The oscillator circuit
does not require any external resistors or capacitors to
operate. See page 5:

http://pdfserv.maxim-ic.com/en/ds/DS1302.pdf


Thank you ! I will take out 2 capacitors. But I ask a new question:
Someone told me, if add the capacitor for DS1302, they will enhance the time precision. Is this right?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 25, 2011 3:35 pm     Reply with quote

I never heard of it in this application. It's not recommended by Maxim.
Use the specified crystal (32.768 KHz, 6 pf load).
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

PostPosted: Sat Nov 26, 2011 6:11 pm     Reply with quote

PCM programmer wrote:
I never heard of it in this application. It's not recommended by Maxim.
Use the specified crystal (32.768 KHz, 6 pf load).


I take out those capactors, it also doesn't work, the LCD display

44/ 2/ 0
0: 0: 0

The clock also doesn't run!
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 26, 2011 7:58 pm     Reply with quote

You may have damaged the chip !
Have you tried writing and reading known data to the RAM on the DS1302 ?

If that test works, then I suggest the RTC part of the chip is defective.

If it fails, then the whole chip is defective.

Someone who has that chip may be able to confirm that the 1302 'driver' does work, I only have the 1307 here.
Also can you confirm the LCD works correctly by displaying "Hello World" on it ?
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

PostPosted: Sun Nov 27, 2011 11:35 pm     Reply with quote

temtronic wrote:
You may have damaged the chip !
Have you tried writing and reading known data to the RAM on the DS1302 ?

If that test works, then I suggest the RTC part of the chip is defective.

If it fails, then the whole chip is defective.

Someone who has that chip may be able to confirm that the 1302 'driver' does work, I only have the 1307 here.
Also can you confirm the LCD works correctly by displaying "Hello World" on it ?


I test my LCD ,this part code works. and I use other's code test the RTC ,it is very good ,so i think the LCD and DS1302 are ok.

I found the DS1302's crystal doesn't work . yesterday ,i disconnected the 2 capacitors(6pf) with DS1302 ,then the crytal didn't start. today so i had to connect the 2 capacitors(6pf) ,however, Ds1302' crystal still doesn't start.

1) why the crystal cann't start ?
2) Is my code defective?
I cann't solved it ,pls help me . I think everybody run his demo used my code in order to checking my code .
Also who can give me a successful demo code with DS1302 ?.
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