📄 dealchars.c
字号:
#include "dealchars.h"
////////////////////////////////////////////////////////////////////////
//Cyclic Redundancy Check (CRC). According to ISO/IEC 13239
////////////////////////////////////////////////////////////////////////
uint CRC16CheckSum(uchar *cBuffer,uchar iBufLen)
{
uchar i,j;
uint wCrc = CRC16_PRESET;
for (i=0; i<iBufLen; i++)
{
wCrc ^= (uint)cBuffer[i];
for (j=0; j<8; j++)
{
if (wCrc & 0x0001)
wCrc = (uint) (wCrc >> 1) ^ CRC16_POLYNOM;
else
wCrc = (uint)(wCrc >> 1);
}
}
wCrc = ~wCrc;
return wCrc;
}
///////////////////////////////////////////////////////////////////////////////
//Reverse the bits of a byte, 7-0, 6-1, 5-2, 4-3
///////////////////////////////////////////////////////////////////////////////
uchar reverse_byte(uchar original_byte)
{
uchar i, ret_byte = 0;
for (i=0; i<8; i++)
{
ret_byte >>= 1;
if (original_byte & 0x80)
ret_byte |= 0x80;
original_byte <<= 1;
}
return ret_byte;
}
///////////////////////////////////////////////////////////////////////////////
//convers two char to a HEX
///////////////////////////////////////////////////////////////////////////////
uchar char_to_hex(uchar high_char, uchar low_char)
{
uchar high_temp,low_temp;
if(high_char <= 0x39)
{
high_temp = high_char - 0x30;
}
else
{
high_temp = high_char - 0x37;
}
if(low_char <= 0x39)
{
low_temp = low_char - 0x30;
}
else
{
low_temp = low_char - 0x37;
}
return high_temp*16 +low_temp;
}
///////////////////////////////////////////////////////////////////////////////
//convers HEX to a two char
///////////////////////////////////////////////////////////////////////////////
uint hex_to_char(uchar a_hex)
{
uint temp;
uchar high_temp,low_temp;
high_temp = a_hex/16;
if(high_temp<=9)
{
high_temp += 0x30;
}
else
{
high_temp += 0x37;
}
low_temp = a_hex%16;
if(low_temp<=9)
{
low_temp += 0x30;
}
else
{
low_temp += 0x37;
}
temp = (uint)high_temp;
temp = (temp<<8) + (uint)low_temp;
return temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -