#include
#define uchar unsigned char
#define uint unsigned int
bit NumSem;//前后操作數(shù)的互斥信號量
bit equ;//等號判斷
bit clr;//清零標(biāo)志
bit add;//加標(biāo)志
bit dec;//減標(biāo)志
bit mul;//乘標(biāo)志
bit div;//除標(biāo)志
bit op;//算術(shù)符號標(biāo)志
uchar KeyNum;//鍵值
uint result;//計(jì)算結(jié)果
uint PreNum,LatNum;//計(jì)算的兩個(gè)操作數(shù)前操作數(shù),后操作數(shù)
uchar KeyPos;
uchar DisLed[]={0xC0,0xF9,0xA4,0xB0,0x99,//LED數(shù)碼七段表
0x92,0x82,0xF8,0x80,0x90};
uchar NumBufe[]={0,0,0,0};
//sbit P10=P1^0;
//sbit P11=P1^1;
//sbit P12=P1^2;
//sbit P13=P1^3;
void T0Intal(void);//定時(shí)器0初始化程序
void DisPlay(void);//顯示程序
void ResultNum(void);//計(jì)算器運(yùn)算結(jié)果
void Clear(void);//清零程序
void Delay_510(void);//延時(shí)510us程序用匯編編寫
void ChangeNum(uchar *p,uchar nCount);//NumBufe[]移位程序
void main(void)
{
T0Intal();
while(1)
{
if(NumSem)
{
PreNum=NumBufe[3]*1000+NumBufe[2]*100+NumBufe[1]*10+NumBufe[0];
NumBufe[4]=0;
NumSem=0;
}
if(op)
{
if(PreNum!=0)
{
if(NumBufe[4]==0)
{
NumSem=1;
}
if(equ)
{
if(NumBufe[4]!=0)
{
LatNum=NumBufe[3]*1000+NumBufe[2]*100+NumBufe[1]*10+NumBufe[0];
//DisLed[]=0;
KeyPos=0;
}
ResultNum();//計(jì)算器結(jié)果計(jì)算
//DisPlay();//顯示計(jì)算結(jié)果
}
}
else Clear();
}
if(clr)
{
Clear();
}
DisPlay();//顯示計(jì)算結(jié)果
}
本文引用地址:
http://m.butianyuan.cn/article/201611/321399.htm}
void T0Intal(void)
{
TMOD=0x01;
TH0=(65536-20000)/256;
TL0=(65536-20000)%256;
EA=1;
ET0=1;
TR0=1;
}
void DisPlay(void)
{
//uchar one,two,three,four;
//one=result/1000;
P2=DisLed[NumBufe[3]];
P0=0xFE;
Delay_510();
//two=(result-one*1000)/100;
P2=DisLed[NumBufe[2]];
P0=0xFD;
Delay_510();
//three=(result-one*1000-two*100)/10;
P2=DisLed[NumBufe[1]];
P0=0xFB;
Delay_510();
//four=(result-one*1000-two*100)%10;
P2=DisLed[NumBufe[0]];
P0=0xF7;
Delay_510();
}
void ResultNum(void)
{
if(op)
{
if(add)
{
result=PreNum+LatNum;
}
if(dec)
{
result=PreNum-LatNum;
}
if(mul)
{
result=PreNum*LatNum;
}
if(div)
{
result=PreNum/LatNum;
}
}
//return result;
//unsigned char
//uchar one,two,three;
//one=result/1000;
NumBufe[3]=result/1000;
NumBufe[2]=(result-NumBufe[3]*1000)/100;
//NumBufe[2]=two;
NumBufe[1]=(result-NumBufe[3]*1000-NumBufe[2]*100)/10;
//NumBufe[1]=three;
NumBufe[0]=(result-NumBufe[3]*1000-NumBufe[2]*100)%10;
}
void Clear(void)
{
// if(Clear)
//{
NumBufe[0]=0;
NumBufe[1]=0;
NumBufe[2]=0;
NumBufe[3]=0;
PreNum=0;
LatNum=0;
result=0;
NumSem=0;
KeyPos=0;
clr=0;
equ=0;
add=0;
dec=0;
mul=0;
div=0;
op=0;
// }
}
評論