文档视界 最新最全的文档下载
当前位置:文档视界 > 简单计算机程序

简单计算机程序

#include

#include

#include

//#define j2h(x) (3.1415926*(x)/180)

sbit P32=P3^2;

sbit P23=P2^3;

sbit P22=P2^2;

sbit P21=P2^1;

sbit P20=P2^0;

//unsigned char timer0_count1=0;

code unsigned char Tab[10]={0x81,0xed,0x43,0x49,0x2d,0x19,0x11,0xcd,0x01,0x09}; code unsigned char Tab1[16]={0x81,0xed,0x43,0x49,0x2d,0x19,0x11,0xcd,0x01,0x09,0x05,0x00,0x93,0x80, 0x13,0x17};

unsigned intKeynumber;

unsigned int number;

unsigned char t=1;

unsigned char p=99;

unsigned char q=0;

void mDelay(unsigned int delay)

{

unsigned char i;

for(;delay>0;delay--)

{

for(i=0;i<124;i++)

{

_nop_();

_nop_();

_nop_();

}

}

}

/*键盘扫描程序*/

void Keyscan()

{ unsigned int key1;

Keynumber=20;

P1&=0x0f;

if((P2&0x0f)!=0x0f) //有键按下

{

mDelay(5);

if(!P23)

{

P1&=0x7f;P1|=0x70;

if(!P23) Keynumber=0;

else

{

P1&=0xbf;P1|=0xb0;

if(!P23) Keynumber=1;

else

{

P1&=0xdf;P1|=0xd0;

if(!P23) Keynumber=2;

else

{

P1&=0xef;P1|=0xe0;

if(!P23) Keynumber=3;

else Keynumber=20;

}

}

}

}

else if(!P22)

{

P1&=0x7f;P1|=0x70;

if(!P22) Keynumber=4;

else

{

P1&=0xbf;P1|=0xb0;

if(!P22) Keynumber=5;

else

{

P1&=0xdf;P1|=0xd0;

if(!P22) Keynumber=6;

else

{

P1&=0xef;P1|=0xe0;

if(!P22) Keynumber=7;

else Keynumber=20;

}

}

}

}

else if(!P21)

{

P1&=0x7f;P1|=0x70;

if(!P21) Keynumber=8;

else

{

P1&=0xbf;P1|=0xb0;

if(!P21) Keynumber=9;

else

{

P1&=0xdf;P1|=0xd0;

if(!P21) Keynumber=10;

else

{

P1&=0xef;P1|=0xe0;

if(!P21) Keynumber=11;

else Keynumber=20;

}

}

}

}

else if(!P20)

{

P1&=0x7f;P1|=0x70;

if(!P20) Keynumber=12;

else

{

P1&=0xbf;P1|=0xb0;

if(!P20) Keynumber=13;

else

{

P1&=0xdf;P1|=0xd0;

if(!P20) Keynumber=14;

else

{

P1&=0xef;P1|=0xe0;

if(!P20)

{

Keynumber=15;

}

else Keynumber=20;

}

}

}

}

else Keynumber=20;

}

else Keynumber=20;//无键按下

}

/*主程序*/

void main()

unsigned int a=0;

unsigned int b=0;

unsigned intnum;

unsigned int key=0;//Keynumber寄存

unsigned int key1;//数据寄存

unsigned int play;//算法判断

while(1)

{

Keyscan();

if(Keynumber<10)//数字输入

{

key=Keynumber;

}

if(Keynumber==20)

{

if(key<10)

{

a=key;

b=10*b+a;

number=b;

key=20;

}

if(Keynumber>11&Keynumber<16)//算法判断{

key=Keynumber;

}

if(Keynumber==20)

{

if(key>11&key<16)

{

key1=number;

b=0;

play=key;

key=20;

}

}

if(Keynumber==11)//加法运算(可以连加){

key=Keynumber;

}

if(Keynumber==20)

{

if(key==11)

{

if(play==12)

{

number=key1+number;

key=20;

}

}

}

if(Keynumber==11)//减法运算(可以连减){

key=Keynumber;

}

if(Keynumber==20)

{

if(key==11)

{

if(play==13)

{

number=key1-number;

key=20;

}

}

}

if(Keynumber==11)//乘法运算(可以连乘){

key=Keynumber;

}

if(Keynumber==20)

{

if(key==11)

{

if(play==14)

{

number=key1*number;

key=20;

}

}

}

if(Keynumber==11)//除法运算(可以连除){

key=Keynumber;

}

if(Keynumber==20)

{

if(key==11)

{

if(play==15)

{

number=key1/number;

key=20;

}

}

}

if(Keynumber==10)//切换进制{

key=Keynumber;

}

if(Keynumber==20)

{

if(key==10)

{

if(number<9999)

{

p++;

if(p>100) p=99;

P32!=P32;

}

else

{

t++;

if(t>2) t=1;

key=20;

}

}

}

if(p==99)

{

if(number<100000000&number>9999) {

if(t==1)

{P0=Tab[(number/10000)/1000];

P2=P2|0x80;P2=P2&0x8f;

P0=Tab[(number/10000)%1000/100]; P2=P2|0x40;P2=P2&0x4f;

mDelay(5);

P0=Tab[(number/10000)%100/10];

P2=P2|0x20;P2=P2&0x2f;

mDelay(5);

P0=Tab[(number/10000)%10];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);}

if(t==2)

{P0=Tab[(number%10000)/1000];

P2=P2|0x80;P2=P2&0x8f;

mDelay(5);

P0=Tab[(number%10000)%1000/100]; P2=P2|0x40;P2=P2&0x4f;

mDelay(5);

P0=Tab[(number%10000)%100/10];

P2=P2|0x20;P2=P2&0x2f;

mDelay(5);

P0=Tab[(number%10000)%10];

P2=P2|0x10;P2=P2&0x1f;

}

if(number<10000&number>999) {

P0=Tab[number/1000];

P2=P2|0x80;P2=P2&0x8f;

mDelay(5);

P0=Tab[number%1000/100];

P2=P2|0x40;P2=P2&0x4f;

mDelay(5);

P0=Tab[number%100/10];

P2=P2|0x20;P2=P2&0x2f;

mDelay(5);

P0=Tab[number%10];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);

}

if(number<1000&number>99)

{

P0=Tab[number/100];

P2=P2|0x40;P2=P2&0x4f;

mDelay(5);

P0=Tab[number%100/10];

P2=P2|0x20;P2=P2&0x2f;

mDelay(5);

P0=Tab[number%10];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);

}

if(number<100&number>9)

{

P0=Tab[number/10];

P2=P2|0x20;P2=P2&0x2f;

mDelay(5);

P0=Tab[number%10];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);

}

if(number<10|number==0)

{

P0=Tab[number%10];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);

}

}

if(p>99)

{

if(number<65536&number>4095) {

P0=Tab1[number/4096];

P2=P2|0x80;P2=P2&0x8f;

mDelay(5);

P0=Tab1[number%4096/256];

P2=P2|0x40;P2=P2&0x4f;

mDelay(5);

P0=Tab1[number%256/16];

P2=P2|0x20;P2=P2&0x2f;

mDelay(5);

P0=Tab1[number%16];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);

}

if(number<4096&number>255) {

P0=Tab1[number/256];

P2=P2|0x40;P2=P2&0x4f;

mDelay(5);

P0=Tab1[number%256/16];

P2=P2|0x20;P2=P2&0x2f;

mDelay(5);

P0=Tab1[number%16];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);

}

if(number<256&number>15)

{

P0=Tab1[number/16];

P2=P2|0x20;P2=P2&0x2f;

mDelay(5);

P0=Tab1[number%16];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);

}

if(number<16|number==0)

{

P0=Tab1[number%16];

P2=P2|0x10;P2=P2&0x1f;

mDelay(5);

}

}

}

}

相关文档
  • 计算机程序

  • 学计算机程序

相关推荐: