hex转bcd
抖音号:STM8
代码如下(示例):
**
* @brief hex转bcd
* @param[in] {Value_H} 高字节
* @param[in] {Value_L} 低字节
* @return 转换完成后数据
*/
unsigned char hex_to_bcd(unsigned char Value_H,unsigned char Value_L)
{
unsigned char bcd_value;
if((Value_H >= '0') && (Value_H <= '9'))
Value_H -= '0';
else if((Value_H >= 'A') && (Value_H <= 'F'))
Value_H = Value_H - 'A' + 10;
else if((Value_H >= 'a') && (Value_H <= 'f'))
Value_H = Value_H - 'a' + 10;
bcd_value = Value_H & 0x0f;
bcd_value <<= 4;
if((Value_L >= '0') && (Value_L <= '9'))
Value_L -= '0';
else if((Value_L >= 'A') && (Value_L <= 'F'))
Value_L = Value_L - 'a' + 10;
else if((Value_L >= 'a') && (Value_L <= 'f'))
Value_L = Value_L - 'a' + 10;
bcd_value |= Value_L & 0x0f;
return bcd_value;
}