Guest
|
reset trouble!! |
Posted: Sat Nov 26, 2005 4:43 am |
|
|
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
}
}
|
|
|