暂存,dec_to_bcd
This commit is contained in:
parent
dfa16f5c79
commit
d78f166ceb
|
@ -5,7 +5,7 @@
|
||||||
"type": "mrs-debugger",
|
"type": "mrs-debugger",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "ble_bjq_ch303rct6_ml307",
|
"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": {
|
"openOCDCfg": {
|
||||||
"useLocalOpenOCD": true,
|
"useLocalOpenOCD": true,
|
||||||
"executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
|
"executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
|
||||||
|
@ -39,8 +39,8 @@
|
||||||
"additionalCommands": []
|
"additionalCommands": []
|
||||||
},
|
},
|
||||||
"loadedFiles": {
|
"loadedFiles": {
|
||||||
"executableFile": "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": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf",
|
"symbolFile": "c:\\Users\\16586\\Desktop\\ble_-tyq_-bjq_-ch32-v303\\obj\\ble_bjq_ch303rct6_ml307.elf",
|
||||||
"executableFileOffset": 0,
|
"executableFileOffset": 0,
|
||||||
"symbolFileOffset": 0
|
"symbolFileOffset": 0
|
||||||
},
|
},
|
||||||
|
|
|
@ -302,18 +302,18 @@ int BSP_Ml307_Init (struct Ml307_Ops *ops, rt_uint8_t version)
|
||||||
return RT_EOK;
|
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;
|
return ((dec / 10) << 4) | (dec % 10);
|
||||||
uint8_t low = bcd & 0x0F;
|
|
||||||
return high + low;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t decimal_to_bcd(uint8_t decimal)
|
// 将BCD格式转换为十进制(可选)
|
||||||
|
uint8_t bcd_to_dec(uint8_t bcd)
|
||||||
{
|
{
|
||||||
uint8_t high = (decimal / 10) & 0x0F;
|
return ((bcd >> 4) * 10) + (bcd & 0x0F);
|
||||||
uint8_t low = (decimal % 10) & 0x0F;
|
|
||||||
return (high << 4) | low;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int test(uint8_t a)
|
int test(uint8_t a)
|
||||||
|
@ -321,9 +321,7 @@ int test(uint8_t a)
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
LOG_D("in = 0x%02X, %d", a, a);
|
LOG_D("in = 0x%02X, %d", a, a);
|
||||||
b = a;
|
b = a;
|
||||||
b = bcd_to_decimal(b);
|
b = dec_to_bcd(b);
|
||||||
LOG_D("in = 0x%02X, %d", b, b);
|
|
||||||
b = decimal_to_bcd(b);
|
|
||||||
LOG_D("in = 0x%02X, %d", b, b);
|
LOG_D("in = 0x%02X, %d", b, b);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue