16f877 with DS1302 cannot set date/time

Status
Not open for further replies.

ZS1BFE

Member level 1
Joined
Nov 17, 2007
Messages
40
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
Cape Town South Africa
Visit site
Activity points
1,612
I cannot manage to get the info I need from the DS1302 datasheet ?? Not so clear for novices>
I use the driver included in PCW PIC C to work my RTC.
32,768mhz x-tal
no pull ups & no caps on X-tal
DS1302.c from driver library

I can read the sec & min, correctly, BUT nothing of the other VARs from the DS1302 is correct.
To confirm what I read from Ds1302 , I have written the time(hour,day,mth,etc) to Port C. The values displayed on Port C is not correct ,the hours count up within 3or 4 counts and end up with all 8 bits high.

Some things thast are not so clear from the library:
Does the DS1302 driver use
12hr or 24hr mode?
Burst mode read & write ?
It is configured to use Port A0, A1 ,A2
Is it possible to move this to port C3 , C4, C5 ?

In the code , I declare all time / date variables as “int”

I can post my code here, but not sure if I can just paste into this message??

Thx for great forum.

- - - Updated - - -

relevant part of my code.
Code:
#fuses NOLVP
#include <DS1302.C>
#include <LCD.C>
void main() {

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_spi(FALSE);
   setup_psp(PSP_DISABLED);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);
   rtc_init();
   lcd_init();
rtc_set_datetime(8,9,19,0,4,30);

while(1)
{
rtc_get_time(hour,min,sec);    // rtc_get_time(hr,min,sec)      
rtc_get_date(day,mth,year,dow) ;
output_c(hour);
}

THX
 

- Your code is incomplete, variable definitions are missing.
- Pin definitions are inside DS1302.C, defaulting to port B pins, not RA0-RA2. You can use it or override it in the application main.
- CCS DS1302 use non-standard C syntax for parameters returning values. Double check that the functions are used as intended.
 
Reactions: ZS1BFE

    ZS1BFE

    Points: 2
    Helpful Answer Positive Rating
ThxFvM,
I have declared all VAR as ints, but has changed to BYTE, but does not make a difference.
I have also changed to Port B as declared in the library, but no success.
I have also tried to make the set_time values = BIN (0b00000000). No luck !!

The result are still the same.:: I can read the min, sec, nothing else AND I cannot set the min.

?? If the set_time is not send to DS1302, does it use any Default values?? Possible "00"
Here I include the rest of my code. PLS help.
Code:
byte hour;
byte min;
byte sec;

#include <DS1302.C>
#include <LCD.C>

void main() {

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_spi(FALSE);
   setup_psp(PSP_DISABLED);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);
   rtc_init();
   //lcd_init();


rtc_set_datetime(0b00000101,0b00010000,0b00010011,0b00000110,0b00010001,0b01010000);


while(1)
{

rtc_get_time(hour,min,sec);    // rtc_get_time(hr,min,sec)        Get the time

output_c(sec);
 


Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…