我写了一个读数子程程序,在12232LCD上能按我的所设显示出来。 但不知用在整个项目里面是否可靠?C51这样计算浮点数小数点正确吗? 我要显示是功率,在采集数据时可能会有W,mW,uW,nW等这样的数值出来。 我是按这样的思路写了一个这样的子程序,请电脑圈圈帮我指点一下。 #define AD_Loop_PickVol_PER 0.0024414 unsigned char idata serial_buff[77]; unsigned char code num[][16]={数字}; unsigned char code ELAPHT[][16]={英文}; unsigned char code welcome_1[]={中文}; void display(uint v) { unsigned char row, count; float tt; unsigned long int tmp ; long int value; tt=v*AD_Loop_PickVol_PER; value = tt * 100000000 + (value > 0 ? 0.5 : -0.5); //tmp = abs(value); tmp = value; serial_buff[0] = tmp / 1000000000; serial_buff[1] = tmp % 1000000000 /100000000; serial_buff[2] = tmp % 100000000 /10000000; serial_buff[3] = tmp % 10000000 /1000000; serial_buff[4] = tmp % 1000000 /100000; serial_buff[5] = tmp % 100000 /10000; serial_buff[6] = tmp % 10000 /1000; serial_buff[7] = tmp % 1000 /100; serial_buff[8] = tmp % 100/10; serial_buff[9] = tmp % 10; draw_bmp(0,1,8,ELAPHT[12]);//显示“Pi” if(value< 0) { draw_bmp(8,1,8,num[14]);//显示“-” } else { draw_bmp(8,1,8,num[13]);//显示“+” } for(count = 0; count != 10; count++) { draw_bmp(8+row*8,1,8,num[serial_buff][count]]);//显示读数 row++; if((count == 1))//定位小数位 { draw_bmp(8+row*8,1,8,num[10]);//显示小数点 row++; } } if((serial_buff[0]==0)&&(serial_buff[1]==0)) { for(row=0;row !=3;row++) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” }
if((serial_buff[2] ==0)&&(serial_buff[3] ==0)&&(serial_buff[4] ==0)) { for(row=3;row !=6;row++) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } if((serial_buff[5] ==0)&&(serial_buff[6] ==0)&&(serial_buff[7] ==0)) { for(row=6;row !=9;row++) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } if(serial_buff[8]==0) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” if(serial_buff[9]==0) { row++; draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } } draw_bmp(104,1,8,ELAPHT[8]);//显示“n” draw_bmp(112,1,8,ELAPHT[11]);//显示“W” } else { if(serial_buff[5]==0) { row=6; draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” if(serial_buff[6]==0) { row++; draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } } for(row=0;row<6;row++) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } for(row=9;row<11;row++) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } draw_bmp(104,1,8,ELAPHT[9]);//显示“u” draw_bmp(112,1,8,ELAPHT[11]);//显示“W” } } else { if(serial_buff[2]==0) { row=3; draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” if(serial_buff[3]==0) { row++; draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } } for(row=0;row<3;row++) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } for(row=6;row<11;row++) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } draw_bmp(104,1,8,ELAPHT[10]);//显示“m” draw_bmp(112,1,8,ELAPHT[11]);//显示“W” } } else { if(serial_buff[0]==0) { row=0; draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } for(row=7;row<11;row++) { draw_bmp(8+row*8,1,8,num[12]);//消隐设置“空格” } draw_bmp(112,1,8,ELAPHT[11]);//显示“W” } }
|