View previous topic :: View next topic |
Author |
Message |
jaikumar
Joined: 15 Dec 2006 Posts: 109
|
Clarification required on RTC programming |
Posted: Fri May 11, 2018 12:43 am |
|
|
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: 9225 Location: Greensville,Ontario
|
|
Posted: Fri May 11, 2018 4:55 am |
|
|
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: 19504
|
|
Posted: Fri May 11, 2018 6:41 am |
|
|
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
|
|
Posted: Fri May 11, 2018 6:49 am |
|
|
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: 9225 Location: Greensville,Ontario
|
|
Posted: Fri May 11, 2018 7:11 am |
|
|
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'. |
|
|
|