I was debugging my "Game of Life on PIC" and my Ascii2Hex function doesn't work like I want it to.
I'm sending a couple of strings from the PC to the PIC.
Those strings look like this : "<1FF8>" (this is written in the usb_input string variable).
"1FF8" is a hex value in ASCII. I just need to convert that back to an integer.
This is how I'm doing it:
Code: Select all
// FCV_USB_INPUT[0] is '<'
// FCV_USB_INPUT[5] is '>'
// FCV_COUNTER variable and FCV_GAME_OF_LIFE_PREV array initialized at 0
for (FCV_I = 1; FCV_I <= 4; FCV_I++)
{
FCV_DUMMY_VAR = FCV_USB_INPUT[FCV_I];
if (FCV_DUMMY_VAR >= '0' && FCV_DUMMY_VAR <= '9')
FCV_DUMMY_VAR = FCV_DUMMY_VAR - '0';
else if (FCV_DUMMY_VAR >= 'A' && FCV_DUMMY_VAR <= 'F')
FCV_DUMMY_VAR = (FCV_DUMMY_VAR - 'A') + 10;
else
FCV_DUMMY_VAR = 0;
FCV_GAME_OF_LIFE_PREV[FCV_COUNTER] = ((FCV_GAME_OF_LIFE_PREV[FCV_COUNTER] << 4) | FCV_DUMMY_VAR);
}
I also convert this value back to a ASCII-hex string and send it back to the PC and I receive "<00F8>" instead of "<1FF8>".
(This function is used 16 times in a loop where I increase the value of "FCV_COUNTER")
I need some help here, I tried like 20 other ways to get the nibbles right but in vain.
BR,
Nicolas L. F.
PS: The same function on PC works without problem.