??? 09/21/06 22:09 Read: times |
#124837 - Data conversion |
Hello all,
I wrote these routines to convert 5 bytes ASCII input from keypad to 2 byte hex value. After some calculation the hex value is convert back to 5 bytes ASCII to display on LCD. It works Ok. However, these seem very slow. My xtal = 12MHz and it takes more than 1 sec to complete each routine. Can anyone recommend a better way to do this. Any inputs will be greatly appreciated. Have a great one. Best Regards, T.L extern unsigned char data Buff_Kb [5]; extern unsigned char Dig_Cnt; /* The routine is work as follow: byte0 = a byte1 = b byte2 = c byte3 = d byte4 = e hex_val = (((((a*10)+b)*10+c)*10+d)*10)+e */ unsigned int Ascii_2_Hex (unsigned char dig_cnt) { unsigned int hex_val = 0; unsigned char i; for (i = 0; i < dig_cnt; i++) { hex_val = ((hex_val * 10) + (Buff_Kb[i] & 0x0f)); } if (hex_val) { Ready = 1; return (hex_val); } } void Hex_2_Ascii (unsigned int hex_val) { unsigned int hex; unsigned char i; hex = hex_val; for (i = Dig_Cnt; i > 0; i--) { Buff_Kb[i-1] = (hex % 10) | 0x30; hex /= 10; } } |
Topic | Author | Date |
Data conversion | 01/01/70 00:00 | |
How have you measured this? | 01/01/70 00:00 | |
How have you measured this? | 01/01/70 00:00 | |
Try This![]() | 01/01/70 00:00 |