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

Clarification required on RTC programming

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



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

Clarification required on RTC programming
PostPosted: Fri May 11, 2018 12:43 am     Reply with quote

Hi,

CCS compiler version: 5.078
PIC microcontroller: 16F18325

I have a i2c connected RTC and the weekday changes of the rtc chip are as follows:
01,02,04,08,10,20,40 in hex (Sun..Sat)

This code below does not work properly:

Code:
 int getCurrentWeekDay(BYTE rtcday)
   {
       switch (rtcday)
      {
     case 0x1: return(1);break;
     case 0x2: return(2);break;
     case 0x4: return(3);break;
     case 0x8: return(4);break;
     case 0x10: return(5);break;
     case 0x20: return(6);break;
     case 0x40: return(7);break;
   }

}


It works only if i change case values to 1,2,4,8,10,20,40.

I don't understand clearly the RTC returned weekday values (rtcday) are hexadecimal. Can someone please explain.

Thanks and Regards.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 11, 2018 4:55 am     Reply with quote

well I looked at my prelim version of the datasheet and no 'real time clock' peripheral...just DL the newest version and even Adobe can't find 'real time clock' in the new datasheet.
So I have to assume the PIC16F18325 does NOT have a RTC peripheral in it.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Fri May 11, 2018 6:41 am     Reply with quote

He says he has an I2C RTC, but then doesn't tell us what it is. Makes it easy to help.... :(

We can't answer without that data.

His chip seems to return a single bit that moves along the register reflecting the day of the week. My guess would be that the code he is using to read the RTC, is performing a BCD to decimal conversion, hence the values internally have to be the decimal number not the hex he expects. Perhaps 75% of RTC chips return their internal registers in BCD, so this would make sense.
jaikumar



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

PostPosted: Fri May 11, 2018 6:49 am     Reply with quote

Ttelmah you nailed it. The return value from the function did convert the value to BCD2BIN.

Thanks for pointing it out.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 11, 2018 7:11 am     Reply with quote

yeesh, my eyes got fixated on the blury green code, so it might be time for trifocals as I have to take the bifcals off to read the screen, on to read papers and look at PCBs... getting old has it's 'challenges'.
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