1、#include#include#define uint unsigned int#define uchar unsigned char uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77;uchar data tab2;uchar ws2=0,0;uchar code table2=0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7;uchar code tablewei=0x0e,0x0d;sbit dula=P15;sbit dawr=P2
2、6;/DA 写数据段 sbit dacs=P27;/DA 始能段uchar num1,f,f1,f2,f3,f4,f5,f6,keynum;/f 为数字键标志位;f1 为 DA 转换标志位;f2,f4 分别为+,-0.1 标志位;f3 为清零标志位void delay(uint z)/延时子程序uint x,y;for(x=z;x0;x-)for(y=110;y0;y-);void display(uint number)/显示 LED uchar i,j;tab0=number%10;tab1=number/10;for(i=0,j=0;i2;i+,j+) dula=1;P2=tablewe
3、ij;if(i=0)P0=tabletabi;elseP0=table2tabi;dula=0;delay(5);keyscan()/键盘扫描uchar num,tt; P1=0xfe;tt=P1;tt=ttwhile(tt!=0xf0) / 检查按键是否被摁下delay(50);tt=P1;tt=ttwhile(tt!=0xf0) / 检查按键是否被摁下 tt=P1; switch(tt)case 0xee: num=7,f=1;break;case 0xde: num=8;f=1;break;case 0xbe: num=9;f=1;break;case 0x7e: num=0;f3=1;
4、/清零按键 break;default:break; while(tt!=0xf0)tt=P1;tt=tt P1=0xfd;tt=P1;tt=ttwhile(tt!=0xf0) / 检查按键是否被摁下delay(50);tt=P1;tt=ttwhile(tt!=0xf0) / 检查按键是否被摁下tt=P1; switch(tt)case 0xed: num=4;f=1;break;case 0xdd: num=5;f=1;break;case 0xbd: num=6;f=1;break;case 0x7d: num=14;f4=1;/减 0.1 按键break;default:break;wh
5、ile(tt!=0xf0)tt=P1;tt=tt P1=0xfb;tt=P1;tt=ttwhile(tt!=0xf0) / 检查按键是否被摁下delay(50);tt=P1;tt=ttwhile(tt!=0xf0) / 检查按键是否被摁下tt=P1; switch(tt)case 0xeb: num=1;f=1;break;case 0xdb: num=2;f=1;break;case 0xbb: num=3;f=1;break;case 0x7b: num=+;f2=1;/加 0.1 按键break;default:break;while(tt!=0xf0)tt=P1;tt=tt P1=0x
6、f7;tt=P1;tt=ttwhile(tt!=0xf0) / 检查按键是否被摁下delay(50);tt=P1;tt=ttwhile(tt!=0xf0) / 检查按键是否被摁下tt=P1; switch(tt)case 0xe7: num=0;f=1;break;case 0xd7: num=10;f1=1;/确认 DA 转换按键break;case 0xb7: num=11;f5=1;break;case 0x77: num=12;f6=1;break;default:break;while(tt!=0xf0)tt=P1;tt=tt return(num);void jishu()/预置电
7、压值 keynum=keyscan();if(f=1) f=0;num1=num1*10+keynum;void change()/DA 转换if(f1=1)P3=(uchar)(256*num1/100);delay(100);void up_down_clear()/加减 0.1 和清零if(f2=1) f2=0;num1+;if(f4=1)f4=0;num1-;if(f3=1)f3=0;num1=0;void up_down_1()/加减 1if(f5=1)f5=0;num1=num1+10;if(f6=1)f6=0;num1=num1-10;void main() dawr=0;dacs=0;P3=0;while(1) jishu();up_down_clear() ;up_down_1(); display(num1); change();