暂存,dec_to_bcd

This commit is contained in:
stark1898y 2025-06-04 13:57:07 +08:00
parent dfa16f5c79
commit d78f166ceb
2 changed files with 12 additions and 14 deletions

View File

@ -5,7 +5,7 @@
"type": "mrs-debugger",
"request": "launch",
"name": "ble_bjq_ch303rct6_ml307",
"cwd": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307",
"cwd": "c:\\Users\\16586\\Desktop\\ble_-tyq_-bjq_-ch32-v303",
"openOCDCfg": {
"useLocalOpenOCD": true,
"executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
@ -39,8 +39,8 @@
"additionalCommands": []
},
"loadedFiles": {
"executableFile": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf",
"symbolFile": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf",
"executableFile": "c:\\Users\\16586\\Desktop\\ble_-tyq_-bjq_-ch32-v303\\obj\\ble_bjq_ch303rct6_ml307.elf",
"symbolFile": "c:\\Users\\16586\\Desktop\\ble_-tyq_-bjq_-ch32-v303\\obj\\ble_bjq_ch303rct6_ml307.elf",
"executableFileOffset": 0,
"symbolFileOffset": 0
},

View File

@ -302,18 +302,18 @@ int BSP_Ml307_Init (struct Ml307_Ops *ops, rt_uint8_t version)
return RT_EOK;
}
uint8_t bcd_to_decimal(uint8_t bcd)
#include <stdint.h>
// 将十进制转换为BCD格式例如33 -> 0x33
uint8_t dec_to_bcd(uint8_t dec)
{
uint8_t high = (bcd >> 4) * 10;
uint8_t low = bcd & 0x0F;
return high + low;
return ((dec / 10) << 4) | (dec % 10);
}
uint8_t decimal_to_bcd(uint8_t decimal)
// 将BCD格式转换为十进制可选
uint8_t bcd_to_dec(uint8_t bcd)
{
uint8_t high = (decimal / 10) & 0x0F;
uint8_t low = (decimal % 10) & 0x0F;
return (high << 4) | low;
return ((bcd >> 4) * 10) + (bcd & 0x0F);
}
int test(uint8_t a)
@ -321,9 +321,7 @@ int test(uint8_t a)
uint8_t b;
LOG_D("in = 0x%02X, %d", a, a);
b = a;
b = bcd_to_decimal(b);
LOG_D("in = 0x%02X, %d", b, b);
b = decimal_to_bcd(b);
b = dec_to_bcd(b);
LOG_D("in = 0x%02X, %d", b, b);
return b;
}