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

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am