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

RTC rollover problem [solved]

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



Joined: 25 Mar 2010
Posts: 4

View user's profile Send private message

RTC rollover problem [solved]
PostPosted: Thu Mar 25, 2010 4:58 am     Reply with quote

Hi everyone. This is my first post but I read the forum for a long time.

Lets go with the problem... I use the CCS functions to work with the built-in Real Time Clock of the 18F26j11.

The RTC seems to work perfectly, but when it reaches the value 23:59:59 (day 1), the next value is 20:00:00 (day1) instead of 00:00:00 of the day2.

I have this problem with my own code and with the example of the CCS.
I don't know what to do.

This is a copy-paste of the hyperterminal:
Quote:

ACTUAL 25/03/10 23:59:57
ACTUAL 25/03/10 23:59:57
ACTUAL 25/03/10 23:59:57
ACTUAL 25/03/10 23:59:58
ACTUAL 25/03/10 23:59:59
ACTUAL 25/03/10 20: 0: 0
ACTUAL 25/03/10 20: 0: 1
ACTUAL 25/03/10 20: 0: 2
ACTUAL 25/03/10 20: 0: 3
ACTUAL 25/03/10 20: 0: 4
ACTUAL 25/03/10 20: 0: 5

Thx for all.


Last edited by turantus on Fri Jul 23, 2010 2:29 pm; edited 2 times in total
turantus



Joined: 25 Mar 2010
Posts: 4

View user's profile Send private message

PostPosted: Thu Mar 25, 2010 11:23 am     Reply with quote

Hi, I resolve the problem. The rtc_write( ) function don't work properly, I have to write the data by hand in BCD.
Code:

   #asm
   movlb   0x0f
   movlw   0x55
   movwf   EECON2
   movlw   0xAA
   movwf   EECON2
   BSF      RTCCFG,5
   #endasm

   RTCCFG =0xFF;         
   RTCVALL=0x11;    //year
   RTCVALH=0x00;   //none
   RTCVALL=0x31;           //day month
   RTCVALH=0x12;   //month
   RTCVALL=0x23;           //hour
   RTCVALH=0x04;   //day of week
   RTCVALL=0x55;     //sec
   RTCVALH=0x59;   //min

I hope that will work for someone.
Cool
lokinhas



Joined: 11 Feb 2009
Posts: 6

View user's profile Send private message

PostPosted: Fri Jul 23, 2010 11:08 am     Reply with quote

turantus thanks for the solution.

I had the same problem, and i solved it with your code.

You should change the PIC name to 18F26j11, so that people find this topic faster...

this is the code i used.

Code:
/*obtain bcd format of a decimal number*/
unsigned int8 bin_2_bcd(unsigned int8 num){   
   unsigned int8 converted_num;
   converted_num=(num/10)<<4|(num%10);
   return converted_num;
}


void rtc_write_corrected(rtc_time_t write_clock){
   write_clock.tm_year=bin_2_bcd(write_clock.tm_year);    //year
   write_clock.tm_mday=bin_2_bcd(write_clock.tm_mday);   //day month
   write_clock.tm_mon=bin_2_bcd(write_clock.tm_mon);   //month
   write_clock.tm_hour=bin_2_bcd(write_clock.tm_hour);    //hour
   write_clock.tm_wday=bin_2_bcd(write_clock.tm_wday);      //day of week
   write_clock.tm_sec=bin_2_bcd(write_clock.tm_sec);    //sec
   write_clock.tm_min=bin_2_bcd(write_clock.tm_min);   //min
   #asm
   movlb   0x0f
   movlw   0x55
   movwf   EECON2
   movlw   0xAA
   movwf   EECON2
   BSF      RTCCFG,5
   #endasm
   RTCCFG =0xFF;         
   RTCVALL=write_clock.tm_year;    //year
   RTCVALH=0x00;   //none
   RTCVALL=write_clock.tm_mday;   //day month
   RTCVALH=write_clock.tm_mon;   //month
   RTCVALL=write_clock.tm_hour;    //hour
   RTCVALH=write_clock.tm_wday;      //day of week
   RTCVALL=write_clock.tm_sec;    //sec
   RTCVALH=write_clock.tm_min;      //min
}
turantus



Joined: 25 Mar 2010
Posts: 4

View user's profile Send private message

PostPosted: Fri Jul 23, 2010 2:49 pm     Reply with quote

hi lokinhas, really glad I have been helpful.

I encountered another problem, in this case with the RTC alarm.

With some numbers of seconds (I named it as "the seconds of the beast" ), RTC interrupt don´t work. I don´t search a solution, I only used other values.

Maybe writing the date of the alarm using the same method with the time...



Sorry for my "english"
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