请用C语句进行编程∶内部RAM的20H、21H和30H、31H单元分别存放着两个无符号的16位数,将其中的小数置于40H和41H单元
时间: 2024-03-14 07:45:10 浏览: 99
以下是代码实现:
```c
unsigned char num1_low = 0x20;
unsigned char num1_high = 0x21;
unsigned char num2_low = 0x30;
unsigned char num2_high = 0x31;
unsigned short num1 = ((unsigned short)num1_high << 8) | num1_low;
unsigned short num2 = ((unsigned short)num2_high << 8) | num2_low;
unsigned char num1_low_new = num1 & 0xFF;
unsigned char num1_high_new = (num1 >> 8) & 0xFF;
unsigned char num2_low_new = num2 & 0xFF;
unsigned char num2_high_new = (num2 >> 8) & 0xFF;
unsigned char num1_new = (num1_high_new << 4) | (num1_low_new >> 4);
unsigned char num2_new = (num2_high_new << 4) | (num2_low_new >> 4);
unsigned char num1_address_low = 0x40;
unsigned char num1_address_high = 0x41;
unsigned char num2_address_low = 0x42;
unsigned char num2_address_high = 0x43;
*(unsigned char*)num1_address_low = num1_new;
*(unsigned char*)num1_address_high = (num1_new >> 8) & 0xFF;
*(unsigned char*)num2_address_low = num2_new;
*(unsigned char*)num2_address_high = (num2_new >> 8) & 0xFF;
```
这段代码首先读取了内部RAM的20H、21H和30H、31H单元分别存放的两个无符号的16位数,并将它们存储在num1和num2变量中。然后,通过位运算将每个数的小数部分提取出来,将它们合并成新的无符号16位数,并将它们存储在num1_new和num2_new变量中。最后,将这两个新的数分别存储在40H、41H和42H、43H单元中。
阅读全文