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

reset trouble!!

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








reset trouble!!
PostPosted: Sat Nov 26, 2005 4:43 am     Reply with quote

hi everone!

i am interfacing ds1302 RTC to PIC16f877, i am having two problems

1. The controller seems to reset from time to time(although i have not enabled a watch dog timer). i have noticed that controller doesnt reset that often when the backup power for ds1302 is not connected (as weird as this may sound), could the ds1302 be resetting the controller in some way or another with its backup power connected.

2. when the controller does work without reset, it shows the date and time (both converted into string format) properly after every 20 seconds
but when i try to concatenate both date and time by using the command:

combi = strcat (date,time);
then 'combi' doesnt get displayed properly by the command

fputs(combi,pc);

could this be something to do with the fact that i have declared combi as a pointer (as this is what u need to use the strcat command)


Code:
#include <16F877.h>
#device *=16 ADC=10 more accurate
#include <stdlib.h>
#include <string.h>
#USE DELAY (CLOCK=4000000)
#include <DS1302.C>
#fuses  XT,NOWDT,NOLVP
//#use rs232(baud=4800,xmit=pin_b1,rcv=pin_b2,parity=N,stream=pc)
#use rs232(baud=4800,xmit=pin_d2,rcv=pin_d3,parity=N,stream=pc)

byte get_bcd()
{
  char first,second;

  do
  {
    first=fgetc(pc);
  }

  while ((first<'0') || (first>'9'));


  fprintf(pc,"first = %C",first);

  first-='0';

  do
  {
    second=fgetc(pc);
  }

  while ((second<'0') || (second>'9'));


  fprintf(pc,"second = %C",second);

  return((first<<4)|(second-'0'));
}

void set_clock()
{
   byte day,mth,year,dow,hour,min;

   fprintf(pc,"\fYear 20: ");

   year=get_bcd();

   fprintf(pc,"\fMonth: ");

   mth=get_bcd();

   fprintf(pc,"\fDay: ");

   day=get_bcd();

   fprintf(pc,"\fWeekday 1-7: ");

   dow=get_bcd();

   fprintf(pc,"\fHour: ");

   hour=get_bcd();

   fprintf(pc,"\fMin: ");

   min=get_bcd();

   rtc_set_datetime(day,mth,year,dow,hour,min);
}



void main()
{
   byte day,mth,year,dow,hour,min,sec;

   char mychar;
   
   char time[9];
   
   char date[9];
   
   char *combi;
   
   rtc_init();

   fprintf(pc,"start");

   set_clock();

   while(1)

   {

      rtc_get_date( day, mth, year, dow);

      rtc_get_time( hour, min, sec );
     
      sprintf(date,"%2X/%2X/%2X",day,mth,year);
     
      fprintf(pc,"\n");
     
      fputs(date,pc);     
     
      fprintf(pc,"\n");
     
      sprintf(time,",%2X:%2X:%2X",hour,min,sec);
     
      fputs(time,pc);

      combi = strcat (date,time);

      fputs(combi,pc);
     
      delay_ms(20000); //delay of 20seconds



   }

}



dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Nov 26, 2005 12:25 pm     Reply with quote

One problem I can see right off is that you only declared combi as a pointer and there is no space reserved for it. Writing anything to it (wherever it is pointing) will overwrite other memory.

A second problem is that in DS1302.c the procedure GET_BCD() is already defined so the program will not compile.
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