ASCII to hex conversion.
Discussion in "PIC Microcontroller Discussion" started by mohansaini Sep 11, 2013.
Wed Sep 11 2013, 10:42 am
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.
but its not working. Please tell what should i do.
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
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
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
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.
Powered by e107 Forum System