Discussion in "PIC Microcontroller Discussion" started by    mohansaini    Sep 11, 2013.
Wed Sep 11 2013, 10:42 am
#1
Hi Sir,

I want to update time of my rtc which is based on internal rtcc of the controller. seconds,mins and hours are updated in an interrupt. Now i want to update time from a customized computer application which sends data in ASCII(for example if i want to set 12:45 i am receiving it as 0x31,0x32:0x34,0x35) i have to convert this data to hex so that i can directly update the time.

i have tried it as
                     unsigned char Tp1,Tp2;
                      Tp1=0x31&0x0F;
                      Tp2=0x32&0x0F;
                      hours=((Tp1<<4)|Tp2); 

but its not working. Please tell what should i do.
Wed Sep 11 2013, 11:26 am
#2
I dont see any issue in conversion. What exactly is not working? is it hours getting wrong value? or what?
Wed Sep 11 2013, 12:14 pm
#3
sir when i tried to set time 12:45 it was like 19:68. from PC side i am sending data as <12:45>.
Wed Sep 11 2013, 12:35 pm
#4
ok i think your clock registers expecting data in decimal not BCD. as you're sending bcd. 12 in hex is 18 in decimal. You need to change your conversion routine.
unsigned char Tp1,Tp2;
Tp1 = 0x31 & 0x0F;
Tp2 = 0x32 & 0x0F;
hours = Tp1 * 10 + Tp2;
 mohansaini like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm
HumanTak
Sun Apr 21 2024, 12:26 pm