Embedded Partner
Full Member level 5
- Joined
- Nov 29, 2010
- Messages
- 247
- Helped
- 42
- Reputation
- 84
- Reaction score
- 37
- Trophy points
- 1,308
- Location
- Hubli(INDIA)
- Activity points
- 2,636
i m facing problem in C code
if i give input as some data i m getting different values on hyperterminal
input output
0x1234 1334
ox9999 9999
0x2389 23;9
0x1111 1111
0x2222 2222
9876 99?6
6789 67?9
so on
my code is
void main()
{
unsigned long int value;
value=hex_to_ascii(0x1234);
display_hyperterminal(value);
}
unsigned long int hex_to_ascii(unsigned int HEX)
{
unsigned long int FinalData;
unsigned int mov;
unsigned char Data1,Data2,Data3,Data4; // dummy variable to hold 16 bit hex no
mov=HEX & 0xF000;
mov = mov>>12;
Data1=(mov>0x0009)?(mov+0x37)mov+0x30);
mov=HEX & 0x0F00;
mov =mov>>8;
Data2=(mov>0x0009)?(mov+0x37)mov+0x30);
mov=HEX & 0x00F0; // masking the higher LSB
mov=mov>>4; // shifting to the lower LSB
Data3=(mov>0x0009)?(mov+0x37)mov+0x30);
mov=HEX & 0x000F;
Data4=(mov>0x0009)?(mov+0x37)mov+0x30);
FinalData= Data1;
//lcd_printc(Data1);
FinalData=FinalData<<8;
FinalData=FinalData & 0xffffff00;
FinalData=FinalData | Data2;
//lcd_printc(Data2);
FinalData=FinalData<<8;
FinalData=FinalData & 0xffffff00;
FinalData=FinalData | Data3;
//lcd_printc(Data3);
FinalData=FinalData | FinalData<<8;
FinalData=FinalData & 0xffffff00;
FinalData=FinalData | Data4;
//lcd_printc(Data4);
return FinalData;
}
if i give input as some data i m getting different values on hyperterminal
input output
0x1234 1334
ox9999 9999
0x2389 23;9
0x1111 1111
0x2222 2222
9876 99?6
6789 67?9
so on
my code is
void main()
{
unsigned long int value;
value=hex_to_ascii(0x1234);
display_hyperterminal(value);
}
unsigned long int hex_to_ascii(unsigned int HEX)
{
unsigned long int FinalData;
unsigned int mov;
unsigned char Data1,Data2,Data3,Data4; // dummy variable to hold 16 bit hex no
mov=HEX & 0xF000;
mov = mov>>12;
Data1=(mov>0x0009)?(mov+0x37)mov+0x30);
mov=HEX & 0x0F00;
mov =mov>>8;
Data2=(mov>0x0009)?(mov+0x37)mov+0x30);
mov=HEX & 0x00F0; // masking the higher LSB
mov=mov>>4; // shifting to the lower LSB
Data3=(mov>0x0009)?(mov+0x37)mov+0x30);
mov=HEX & 0x000F;
Data4=(mov>0x0009)?(mov+0x37)mov+0x30);
FinalData= Data1;
//lcd_printc(Data1);
FinalData=FinalData<<8;
FinalData=FinalData & 0xffffff00;
FinalData=FinalData | Data2;
//lcd_printc(Data2);
FinalData=FinalData<<8;
FinalData=FinalData & 0xffffff00;
FinalData=FinalData | Data3;
//lcd_printc(Data3);
FinalData=FinalData | FinalData<<8;
FinalData=FinalData & 0xffffff00;
FinalData=FinalData | Data4;
//lcd_printc(Data4);
return FinalData;
}
Last edited: