编程实现两个双字节压缩BCD码求和 用单片机的知识解答 请各位有懂的和我详细说一下
1.建立项目并创建文件
2.在程序编辑工作区编辑以下代码,下面代码是C语言代码,代码都是基础知识,没有难度。
3.将应用程序添加到项目中
4.编译与连接、生成机器代码文件。
#include<stdio.h>
#define uchar unsigned char
int BCD_Decimal(int bcd){
int thou,hun,dec;
int Decimal;
thou = bcd >> 12;
hun = (bcd >> 8) & 0x0f;
dec = (bcd >> 4) & 0x0f;
printf("0x%x 0x%x 0x%x\n",thou,hun,dec);
Decimal = thou*1000 + hun*100 + dec*10 + (bcd & 0x0f);
return Decimal;
}
//实现1260+1030=2290
int main()
{
int ch1 = 0x1260;
int ch2 = 0x1030;
int dec1 = BCD_Decimal(ch1);
int dec2 = BCD_Decimal(ch2);
int sum;
sum = dec1 + dec2;
printf("%Ld",sum);
return 0;
}
5.点击如下按钮进入调试界面