Make an integer to ASCII conversion function. If the maximum value of the data you want to send can be determined, you can define an ASCII array based on the maximum value, and each unit of the array stores one bit of integer data.
Before sending, convert the units in the sending integer array into ASCII arrays, and then send them according to the general sending function.
void InttoChar (uint IntNumber)
//--------------------------- -----------------------------
// Name: void InttoChar (int IntNumber)
// Func.: Translate integer to ASCII charactor array
// Char.: IntNumber number to be translated to ASCII charactor
//------- --------------------------------------------------
{
if (IntNumber < 10)
{
AsciiArray[0] = IntNumber + 0x30;
< p> AsciiArray[1] = 0x20;AsciiArray[2] = 0x20;
AsciiArray[3] = 0x20;
AsciiArray[4] = 0x20 ;
return;
}
if (IntNumber < 100)
{
AsciiArray[0] = IntNumber / 10 + 0x30;
AsciiArray[1] = IntNumber % 10 + 0x30;
AsciiArray[2] = 0x20;
AsciiArray[3] = 0x20;
AsciiArray[4] = 0x20;
return;
}
if (IntNumber < 1000)
{
AsciiArray[0] = IntNumber / 100 + 0x30;
AsciiArray[1] = IntNumber % 100 / 10 + 0x30;
AsciiArray[2] = IntNumber % 10 + 0x30;
AsciiArray[3] = 0x20;
AsciiArray[4] = 0x20;
return;
p>}
if (IntNumber < 10000)
{
AsciiArray[0] = IntNumber / 1000 + 0x30;
< p> AsciiArray[1] = IntNumber % 1000 / 100 + 0x30;AsciiArray[2] = IntNumber % 100 / 10 + 0x30;
AsciiArray[3] = IntNumber % 10 + 0x30;
AsciiArray[4] = 0x20;
return;
}
else
{
AsciiArray[0] = IntNumber / 10000 + 0x30;
AsciiArray[1] = IntNumber % 10000 / 1000 + 0x30;
AsciiArray[2] = IntNumber % 1000 / 100 + 0x30;
AsciiArray[3] = IntNumber % 100 / 10 + 0x30;
AsciiArray[4] = IntNumber % 10 + 0x30;
return;
}
}