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

rtc problem

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



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

rtc problem
PostPosted: Fri May 09, 2008 1:44 am     Reply with quote

Hi,
I want to write date on lcd with ds1302, but I only see

D:00/00/2000
H:00:00:00

Here are the codes

Code:



#include <16F877A.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=4000000)
#include <lcd.c>
#include <DS1302.c>

byte saniye, dakika, saat, gun, ay, yil, haftanin_gunu;

void main()
{setup_psp(PSP_DISABLED);
 setup_spi(SPI_SS_DISABLED);
 setup_timer_1(T1_DISABLED);
 setup_timer_2(T2_DISABLED,0,1);
 setup_adc_ports(NO_ANALOGS);
 setup_adc(ADC_OFF);
 setup_CCP1(CCP_OFF);
 setup_CCP1(CCP_OFF);
 
 lcd_init();
 rtc_init();
 
 rtc_set_datetime(9, 06, 8, 4, 10, 18);

 while(1)
 {
  rtc_get_time(saat, dakika, saniye);
  rtc_get_date(gun, ay, yil, haftanin_gunu);
 
  printf(lcd_putc, "\fD:%02d/%02d/20%02d", gun, ay, yil);
 
  switch(haftanin_gunu)
  {case 1: printf(lcd_putc, "PAZ"); break;
   case 2: printf(lcd_putc, "PZT"); break;
   case 3: printf(lcd_putc, "SAL"); break;
   case 4: printf(lcd_putc, "CRS"); break;
   case 5: printf(lcd_putc, "PRS"); break;
   case 6: printf(lcd_putc, "[spam]"); break;
   case 7: printf(lcd_putc, "CTS"); break;
   }
   
   printf(lcd_putc, "\nH:%02d:%02d:%02d", saat, dakika, saniye);
   
   delay_ms(1000);
 
}

}



what must I do?
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri May 09, 2008 7:36 am     Reply with quote

Is your DS1302 chip wired up like this?


RTC_SCLK ----->PIN_B1
RTC_IO -----> PIN_B3
RTC_RST -----> PIN_B2
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

PostPosted: Fri May 09, 2008 1:52 pm     Reply with quote

hi again,
i cope with this problem at proteus but in hardware part date and time is 01/01/2000 00:00...i reset the circuit,it started to show the real time as i set in software.But a few seconds later it turned to show 01/01/2000 00:00 again...
how can i correct the real time?

here's the code:
Code:

#include <16F877A.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=4000000)
#define RTC_SCLK PIN_c4
#define RTC_IO   PIN_c5
#define RTC_RST  PIN_c3
#include <ds1302.c>
#include <lcd.c>
#use rs232 (baud=600, rcv=PIN_C7)

char x;
int say1=0;
int say2=0;

int saniye,dakika,saat,gun,ay,yil,haftanin_gunu;

float temp;
 
void read()
{ x=getc();}



void fivebyte1()
{
   while(1)
   {
         if(getc()==0xff)
          {say2++;
          if(say2>=5)
          {say2=0;
           read();
           break;}
          }
        else {say2 = 0;
        break;}
    }
}

void fivebyte0()
{
   while(1)
  {
   if(getc()==0x00)
   { say1++;
          if(say1>=5)
           {say1=0;
            fivebyte1();
            break;}
             }
            else say1 = 0;
      }
}

void main()
{
 

   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_1(T1_DISABLED);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_CCP1(CCP_OFF);
   setup_CCP2(CCP_OFF);

   lcd_init();

   rtc_init();

   rtc_set_datetime(9,6,8,2,11,31);

while(1)
{

 fivebyte0();

 switch(x)
 {
  case 'a':
  lcd_gotoxy(1,2);
  printf(lcd_putc, " TRAFIK YOGUN   ");
  delay_ms(1000);
  break;

  case 'b':
  lcd_gotoxy(1,2);
  printf(lcd_putc, " TRAFIK AKICI      ");
  delay_ms(1000);
  break;

  case 'c':
  lcd_gotoxy(1,2);
  printf(lcd_putc, "TRAFIK COK YOGUN ");
  delay_ms(1000);
  break;

  case 'd':
  lcd_gotoxy(1,2);
  printf(lcd_putc, " YOL BOS     ");
  delay_ms(1000);
  break;

 }
 
 rtc_get_time(saat,dakika,saniye);
 rtc_get_date(gun,ay,yil,haftanin_gunu);

 lcd_gotoxy(1,1);
 printf(lcd_putc,"%02d/%02d/20%02d",gun,ay,yil);
 printf(lcd_putc," %02d:%02d:%02d",saat,dakika,saniye);



}
}
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