1、能實(shí)現(xiàn)三位數(shù)的加減乘除。
2、鍵盤輸入計(jì)算數(shù)據(jù),數(shù)碼管顯示輸入值。
3、使用8255擴(kuò)展接線驅(qū)動(dòng)數(shù)碼管和鍵盤。
define PA XBYTE[0x70ff]//定義8255端口
#define PB XBYTE[0x71ff]
#define PC XBYTE[0x72ff]
#define PD XBYTE[0x73ff]
unsigned int a=0,b=0; //輸入
unsigned char fuhao=0;//符號(hào)
unsigned int c=0;//結(jié)果
unsigned char code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//顯示0~9,無小數(shù)點(diǎn)
unsigned char disp[]={0,0,0,0,0,0,0,0};
void delay(unsigned int i)//延時(shí)
{
while(i--);
}
unsigned char key=0;
unsigned char key_scan()//按鍵檢測
{
unsigned char i,j,k=0;
i=0;
j=0;
PD=0X81;
PC=0x0f;
k=PC;
if(k!=0x0f) //檢測有無按下
{
switch(k)//檢測行
{
case 0x0e:i=3;break;
case 0x0d:i=2;break;
case 0x0b:i=1;break;
case 0x07:i=0;
}
PD=0X88;
PC=0xf0;
k=PC;
switch(k)//檢測列
{
case 0xe0:j=13;break;
case 0xd0:j=9;break;
case 0xb0:j=5;break;
case 0x70:j=1;
}
}
if(key!=i+j)
{
key=i+j;
return key;
}
else
return 0;
}
void main()//主函數(shù)
{
unsigned char i;
unsigned int m=0;
PD=0x80;
while(1)
{
//顯示
if(fuhao<5)
{
PA=0;
PB=0XFE;
PA=smgduan[a%1000/100];
delay(100);
PA=0;
PB=0XFD;
PA=smgduan[a%100/10];
delay(100);
PA=0;
PB=0XFB;
PA=smgduan[a%10];
delay(100);
PA=0;
PB=0XF7;
switch(fuhao)//符號(hào)
{
case 1:PA=0x01;break;
case 2:PA=0x40;break;
case 3:PA=0x08;break;
case 4:PA=0x80;break;
default:PA=0;
}
delay(100);
PA=0;
PB=0XEF;
PA=smgduan[b%1000/100];
delay(100);
PA=0;
PB=0XDF;
PA=smgduan[b%100/10];
delay(100);
PA=0;
PB=0XBF;
PA=smgduan[b%10];
delay(100);
}
else//顯示結(jié)果
{
PA=0;
PB=0XEF;
PA=smgduan[c%1000/100];
delay(100);
PA=0;
PB=0XDF;
PA=smgduan[c%100/10];
delay(100);
PA=0;
PB=0XBF;
PA=smgduan[c%10];
delay(100);
}
//==================================================
i=key_scan();//檢測
if((i>0)&&(i<11))//輸入數(shù)值
閱讀全文