求基于AT89C51单片机简易计算器设计的程序,请帮帮忙,谢谢。

这是我的原理图,最好能用C语言来实现,因为汇编我比较不懂。。。请高手帮忙哈!

#include<reg52.h>

delay10ms()

{

unsigned char a,b;

for(a=100;a>0;a--)

for(b=50;b>0;b--);

}

delay1ms()

{

unsigned char a,b;

for(a=10;a>0;a--)

for(b=50;b>0;b--);

}

unsigned char code tab[]=

{

0x3f,6,0x5b,0x4f,0x66,0x6d,0x7d,7,

0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71

};

 main()

{

unsigned char m,i,j,k,l,p,cc2,cc3,cc4,cc5,o;

unsigned long c1,c2,cc;

unsigned int cc1;

unsigned char aa0,aa1,aa2,aa3,bb0,bb1,bb2,bb3;

unsigned char a0,a1,a2,a3,b0,b1,b2,b3;

bit q,n;

while(1)

   {static dian=0x80,fuhao=0;

   for (j=0;j<=3;j++)

      {

      k=0xfe<<j;

      l=0xfe>>(8-j);

      P0=k|l;

      if(P0_4==0)

         {

         delay10ms();

         if(P0_4==0)

         {

         while(P0_4==0)

   {   

      P2=b0;

   P1=0xfe;

   delay1ms();

   P2=0;

   P2=b1;

   P1=0xfd;

   delay1ms();

   P2=0;

   P2=b2;

   P1=0xfb;

   delay1ms();

   P2=0;

      P2=b3;

   P1=0xf7;

   delay1ms();

   P2=0;

   P2=a0;

   P1=0xef;

   delay1ms();

   P2=0;

   P2=a1;

   P1=0xdf;

   delay1ms();

   P2=0;

   P2=a2;

   P1=0xbf;

   delay1ms();

   P2=0;

   P2=a3;

   P1=0x7f;

   delay1ms();

   P2=0;

   P2=dian;

      P1=0xef;

      delay1ms();

   P2=0;

      

   P2=fuhao;

      P1=0xef;

      delay1ms();

   P2=0;

   }

         if(tab[4*j]==0x39)

            {

            n=1;

            i=3;

            }

else

   {m++;

    if(m<=4&n==0)

    {

       a3=a2;

       a2=a1;

       a1=a0;

       a0=tab[4*j];

       aa3=aa2;

       aa2=aa1;

       aa1=aa0;

       aa0=4*j;

       }

    else

       {

          if(p<=3&n==1)

             {

    b3=b2;

          b2=b1;

          b1=b0;

          b0=tab[4*j];

    bb3=bb2;

          bb2=bb1;

          bb1=bb0;

          bb0=4*j;

            

  p++;

         }

         }

      }

   }

}

 if(P0_5==0)

{

delay10ms();

if(P0_5==0)

{

while(P0_5==0)

{   

      P2=b0;

   P1=0xfe;

   delay1ms();

   P2=0;

   P2=b1;

   P1=0xfd;

   delay1ms();

   P2=0;

   P2=b2;

   P1=0xfb;

   delay1ms();

   P2=0;

      P2=b3;

   P1=0xf7;

   delay1ms();

   P2=0;

   P2=a0;

   P1=0xef;

   delay1ms();

   P2=0;

   P2=a1;

   P1=0xdf;

   delay1ms();

   P2=0;

   P2=a2;

   P1=0xbf;

   delay1ms();

   P2=0;

   P2=a3;

   P1=0x7f;

   delay1ms();

   P2=0;

   P2=dian;

      P1=0xef;

      delay1ms();

   P2=0;

      

   P2=fuhao;

      P1=0xef;

      delay1ms();

   P2=0;

   }

if(tab[4*j+1]==0x5e)

{

  i=4;

  n=1;

}

else

   {m++;

    if(m<=4&n==0)

    {

       a3=a2;

       a2=a1;

       a1=a0;

       a0=tab[4*j+1];

    aa3=aa2;

       aa2=aa1;

       aa1=aa0;

       aa0=4*j+1;

       }

    else

       {

          if(p<=3&n==1)

             {

    b3=b2;

          b2=b1;

          b1=b0;

          b0=tab[4*j+1];

    bb3=bb2;

          bb2=bb1;

          bb1=bb0;

          bb0=4*j+1;

             

  p++;

         }

      }

      }

   }

}

if(P0_6==0)

{

delay10ms();

if(P0_6==0)

{

while(P0_6==0)

{   

      P2=b0;

   P1=0xfe;

   delay1ms();

   P2=0;

   P2=b1;

   P1=0xfd;

   delay1ms();

   P2=0;

   P2=b2;

   P1=0xfb;

   delay1ms();

   P2=0;

      P2=b3;

   P1=0xf7;

   delay1ms();

   P2=0;

   P2=a0;

   P1=0xef;

   delay1ms();

   P2=0;

   P2=a1;

   P1=0xdf;

   delay1ms();

   P2=0;

   P2=a2;

   P1=0xbf;

   delay1ms();

   P2=0;

   P2=a3;

   P1=0x7f;

   delay1ms();

   P2=0;

   P2=dian;

      P1=0xef;

      delay1ms();

   P2=0;

      

   P2=fuhao;

      P1=0xef;

      delay1ms();

   P2=0;

   }

if(tab[4*j+2]==0x77)

  {

  i=1;

  n=1;

  }

  else

     {

  if(tab[4*j+2]==0x79)

  {

  q=1;

  n=1;

  }

else

   {

   m++;

    if(m<=4&n==0)

    {

       a3=a2;

       a2=a1;

       a1=a0;

       a0=tab[4*j+2];

    aa3=aa2;

       aa2=aa1;

       aa1=aa0;

       aa0=4*j+2;

       }

    else

       {

          if(p<=3&n==1)

             {

    b3=b2;

          b2=b1;

          b1=b0;

          b0=tab[4*j+2];

    bb3=bb2;

          bb2=bb1;

          bb1=bb0;

          bb0=4*j+2;

             

  p++;

            }

         }

         }

      }

   }

}

 if(P0_7==0)

{

delay10ms();

if(P0_7==0)

{

while(P0_7==0)

{   

      P2=b0;

   P1=0xfe;

   delay1ms();

   P2=0;

   P2=b1;

   P1=0xfd;

   delay1ms();

   P2=0;

   P2=b2;

   P1=0xfb;

   delay1ms();

   P2=0;

      P2=b3;

   P1=0xf7;

   delay1ms();

   P2=0;

   P2=a0;

   P1=0xef;

   delay1ms();

   P2=0;

   P2=a1;

   P1=0xdf;

   delay1ms();

   P2=0;

   P2=a2;

   P1=0xbf;

   delay1ms();

   P2=0;

   P2=a3;

   P1=0x7f;

   delay1ms();

   P2=0;

   P2=dian;

      P1=0xef;

      delay1ms();

   P2=0;

      

   P2=fuhao;

      P1=0xef;

      delay1ms();

   P2=0;

   }

if(tab[4*j+3]==0x71)

  {

  i=6;

  n=1;

  }

  else

     {

if(tab[4*j+3]==0x7c)

  {

  i=2;

  n=1;

  }

else

   {m++;

    if(m<=4&n==0)

    {

       a3=a2;

       a2=a1;

       a1=a0;

       a0=tab[4*j+3];

    aa3=aa2;

       aa2=aa1;

       aa1=aa0;

       aa0=4*j+3;

       }

    else

       {

          if(p<=3&n==1)

             {

    b3=b2;

          b2=b1;

          b1=b0;

          b0=tab[4*j+3];

    bb3=bb2;

          bb2=bb1;

          bb1=bb0;

          bb0=4*j+3;

             

       p++;

            }

         }

         }

      }

   }

}

if(i==6)//复位

{

a0=a1=a2=a3=b0=b1=b2=b3=0;

dian=0x80;

fuhao=0;

m=i=j=k=l=n=p=q=0;

aa0=aa1=aa2=aa3=bb0=bb1=bb2=bb3=0;

c1=c2=cc=cc1=cc2=cc3=cc4=cc5=0;

}

if(q==0)

   {   

      P2=b0;

   P1=0xfe;

   delay1ms();

   P2=0;

   P2=b1;

   P1=0xfd;

   delay1ms();

   P2=0;

   P2=b2;

   P1=0xfb;

   delay1ms();

   P2=0;

      P2=b3;

   P1=0xf7;

   delay1ms();

   P2=0;

   P2=a0;

   P1=0xef;

   delay1ms();

   P2=0;

   P2=a1;

   P1=0xdf;

   delay1ms();

   P2=0;

   P2=a2;

   P1=0xbf;

   delay1ms();

   P2=0;

   P2=a3;

   P1=0x7f;

   delay1ms();

   P2=0;

   P2=dian;

      P1=0xef;

      delay1ms();

   P2=0;

      

   P2=fuhao;

      P1=0xef;

      delay1ms();

   P2=0;

   }

else

{

q=0;

c1=aa0+aa1*10+aa2*100+aa3*1000;

c2=bb0+bb1*10+bb2*100+bb3*1000;

if(i==1)//加法运算

{

cc=c1+c2;

}

if(i==2)//减法运算

{

if(c1>=c2)

   {

   cc=c1-c2;

   }

   else

   {

      cc=c2-c1;

      fuhao=0x40;

   }

}

if(i==3)//乘法运算

{

cc=c1*c2;

}

a3=tab[cc/10000000];

aa3=cc/10000000;

a2=tab[(cc%10000000)/1000000];

aa2=(cc%10000000)/1000000;

a1=tab[(cc%1000000)/100000];

aa1=(cc%1000000)/100000;

a0=tab[(cc%100000)/10000];

aa0=(cc%100000)/10000;

b3=tab[(cc%10000)/1000];

bb3=(cc%10000)/1000;

b2=tab[(cc%1000)/100];

bb2=(cc%1000)/100;

b1=tab[(cc%100)/10];

bb1=(cc%100)/10;

b0=tab[cc%10];

bb0=cc%10;

dian=0;//消除点

if(aa3==0)//消除多余的零

{

a3=0;

if(aa2==0)

   {

   a2=0;

   if(aa1==0)

      {

   a1=0;

   if(aa0==0)

      {

   a0=0;

   if(bb3==0)

      {

   b3=0;

   if(bb2==0)

      {

      b2=0;

      if(bb1==0)

         {

      b1=0;

      }

      }

   }

   }

   }

   }

}

if(i==4)//除法运算

{

if(c2==0)

   {

   for(o=100;o>0;o--)

      {

   b2=b1=b0=0;

      a3=0x79;

      a2=a1=b3=0x77;

      a0=0x3f;

   P2=b0;

   P1=0xfe;

   delay1ms();

   P2=0;

   P2=b1;

   P1=0xfd;

   delay1ms();

   P2=0;

   P2=b2;

   P1=0xfb;

   delay1ms();

   P2=0;

      P2=b3;

   P1=0xf7;

   delay1ms();

   P2=0;

   P2=a0;

   P1=0xef;

   delay1ms();

   P2=0;

   P2=a1;

   P1=0xdf;

   delay1ms();

   P2=0;

   P2=a2;

   P1=0xbf;

   delay1ms();

   P2=0;

   P2=a3;

   P1=0x7f;

   delay1ms();

   P2=0;

      delay10ms();

      }

      i=6;

   }

   else

{

cc1=c1/c2;

a3=tab[cc1/1000];

aa3=cc1/1000;

a2=tab[(cc1%1000)/100];

aa2=(cc1%1000)/100;

a1=tab[(cc1%100)/10];

aa1=(cc1%100)/10;

a0=tab[cc1%10];

aa0=cc1%10;

dian=0x80;

cc2=(c1%c2)*10/c2;

b3=tab[cc2];

cc3=((c1%c2)*10%c2)*10/c2;

b2=tab[cc3];

cc4=(((c1%c2)*10%c2)*10%c2)*10/c2;

b1=tab[cc4];

cc5=((((c1%c2)*10%c2)*10%c2)*10%c2)*10/c2;

b0=tab[cc5];

if((((((c1%c2*10)%c2)*10%c2)*10%c2)*10%c2)*10/c2>=5)

{

b0=tab[cc5+1];

}

if(aa3==0)//消除多余的零

{

a3=0;

if(aa2==0)

   {

   a2=0;

   if(aa1==0)

      {

   a1=0;

      }

   }

}

               }

            }

   }

      }

   }

}  

这个是数码管的

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-01-20
这个是我原来点的1602驱动。你对照看看,判忙,发数据,发命令函数是不是一样的。 你的程序我没具体看。你尝试在某些命令后加上延时试看。 还有第二行的地址是40H开头的。
/********************************************************************************
*Design: qinhao
*********************************************************************************/
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
volatile char bf;

sbit rs=P3^0;
sbit rw=P3^1;
sbit e=P3^2;
#define bf P1^7

uchar code qin[]={
0x1F,0x11,0x11,0x11,0x11,0x11,0x11,0x1F, //方框
0x0E,0x0A,0x04,0x1F,0x04,0x0E,0x0A,0x1B, //小人
0x0A,0x15,0x0A,0x15,0x0A,0x15,0x0A,0x15, //黑白格子
0x1F,0x15,0x1F,0x1B,0x1B,0x1F,0x11,0x1F, //脸
0x0E,0x11,0x11,0x15,0x15,0x0E,0x04,0x04, //树
0x0f,0x09,0x0f,0x09,0x0f,0x09,0x0b,0x11, // 月
0x1F,0x00,0x1F,0x00,0x1F,0x00,0x1F,0x00, //黑白横条
0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, //黑白竖条

};

void delay(unsigned int n)
{
unsigned int i,j;
for(j=n;j>0;j--)
for(i=112;i>0;i--);
} /////// 精确MS,

void check() // 判忙
{

rs=0;
rw=1;
e=0;
P1=0xff;
e=1;
_nop_();
_nop_();
while(P1&0x80){};
delay(10);
}

void sendc(uchar com) // 发命令字
{
check();
rs=0;
rw=0;
e=1;
P1=com;
_nop_();
e=0;
_nop_();
}

void sendd(uchar word) // 发显示字
{
check();
rs=1;
rw=0;
e=1;
P1=word;
_nop_();
e=0;
_nop_();
}

void inti() // 初始化
{
sendc(0x01);
sendc(0x38);
sendc(0x0f);
sendc(0x06);
delay(10);
}

void setcgram() ////// 写cgram
{
uchar x;
sendc(0x40);
for(x=0;x<64;x++)
{
sendd(*(qin+x));
};
}

void main()
{
unsigned char i;
setcgram();
inti();
sendc(0x80); /// 第一行
for(i=0;i<8;i++)
{
sendd(i+0x00);
};
sendc(0xc0); /// 第二行
for(i=0;i<8;i++)
{
sendd(0x07-i);
};

while(1){};

}本回答被提问者和网友采纳
第2个回答  2011-01-22
用键盘扫描程序完成
这是我对AVR编写的函数,参考一下思路吧
/*******************************************
函数名称: Key_scan
功 能: 扫描所按的键并返回键值
参 数: 无
返回值 : keycode--被按下键值
/********************************************/
uchar Mkey_scan(void)
{
uchar i=0x7F,keycode=0xFF; //i为扫描码,
Delayms(15); //延时消抖
if(Mkey_press()==TRUE) //如果有键按下
{
do
{
i=(i<<1|i>>7); //进行行扫描
KEY_DDR=0x0F; //定义数据端口低四位为输出,高四位为输入
KEY_PORTO=i; //输出扫描码
Delayms(1); //防止读入出错,加入延时
keycode=KEY_PORTI; //读入原始键码
}while((keycode&0xF0)==0xF0); //是否检测到被按下按键(扫描到就跳出循环,否则继续扫描)
do
{
}while(Mkey_press()==TRUE); //等待按键释放(为了防止按一次,执行多次的现象)
Delayms(15); //延时消抖
switch(keycode) //将原始键码翻译成0~F
{
case 0xEE:
keycode=0x0;
break;
case 0xDE:
keycode=0x1;
break;
case 0xBE:
keycode=0x2;
break;
case 0x7E:
keycode=0x3;
break;
case 0xED:
keycode=0x4;
break;
case 0xDD:
keycode=0x5;
break;
case 0xBD:
keycode=0x6;
break;
case 0x7D:
keycode=0x7;
break;
case 0xEB:
keycode=0x8;
break;
case 0xDB:
keycode=0x9;
break;
case 0xBB:
keycode=0xA;
break;
case 0x7B:
keycode=0xB;
break;
case 0xE7:
keycode=0xC;
break;
case 0xD7:
keycode=0xD;
break;
case 0xB7:
keycode=0xE;
break;
case 0x77:
keycode=0xF;
break;
}
}
return keycode; //返回经过翻译的键码
}
第3个回答  2011-01-19
下次画图的时候不要看电影,电脑屏幕不要搞的那么花,

求用单片机设计一个秒表AT89C51
SETB EX1 SETB EA ;定时器初始化结束,下面循环显示即可 MOV R1, #99H ;0~99计数.MOV R7, #1 ;50ms计数.MOV P0, #0C0H MOV P2, #0C0H LOOP:SJMP LOOP ;--- DELAY: ;延时子程序.AA4: MOV R4, #0 DJNZ R4,DJNZ R4,RET ;---...

急求基于单片机AT89C51的多功能数字电子钟的汇编程序,高手进!~_百度知...
用89C51控制3个HC595,前两个595接8段数码显示管,显示“0”~“9”每秒跳动一次.第3个HC595接8个LED灯,每隔1秒闪烁1次.include<at89x52.h> include<intrins.h> define uchar unsigned char define uint unsigned int uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90...

用C语言编写AT89C51单片机程序,设计一个智能数字钟。
这是我的课程设计,6个数码管,显示时分秒,三个按钮P0.0、P0.1、P0.2可以调时,有8个彩灯(可以不要),没闹钟、倒计时之类的。呵呵。include<AT89X52.H> define uchar unsigned char int i;\/\/***时钟的 uchar one[10]={0xbf,0xb0,0xdb,0xcf,0xe6,0xed,0xfd,0x07,0xff,0xef}...

1、 基于AT89C51单片机,利用定时器设计一个两位数码管显示电路。 设计...
1、 基于AT89C51单片机,利用定时器设计一个两位数码管显示电路。 设计要求:每隔2S显示数字加1,显示初值 5 我下周就要用了 ,麻烦大家了 谢谢啊 zzc3981 | 浏览1494 次 |举报 我有更好的答案推荐于2017-12-15 14:23:16 最佳答案 这个我仿真过了 是有用的,,,是从00开始显示 到了99会从新开始从00开始加...

以AT89C51单片机为核心,设计一个二进制计数器
直接赋值,就是二进制显示:比如:uchar dat = 3;P0 = dat; \/\/LED灯二进制方式显示数据dat.

用AT89C51单片机编写一个C语言程序实现2个数码管秒计数器,用4个按键...
uchar num=0;sec,key;void delay(unsigned int a){ unsigned int i,j;for(i=0;i<a;i++)for(j=0;j<120;j++);} void display(){ LED1=sec\/10;LED2=sec%10;P2=0x01;P0=distab[LED1];delay(3);P2=0x02;P0=distab[LED2];delay(3);} void t0isr() interrupt 1 { TH0=(...

求一个基于AT89C51单片机的数字时钟程序,显示时、分、秒不要求闹钟!就...
TMOD = 0x11;\/\/ 定时器0, 1工作模式1, 16位定时方式 TH1 = 0xdc;TL1 = 0;TH0 = 0xFC;TL0 = 0x17;hour = 12;min = 00;sec = 00;sec100 = 0;dis_buf[0] = dis_code[hour \/ 10];\/\/ 时十位 dis_buf[1] = dis_code[hour % 10];\/\/ 时个位 dis_buf[3] = dis_code...

用AT89C51单片机,4位共阴极数码管,显示出1234 程序怎么写??? 请各位...
MOV 34H,#04H MOV 35H,#05H MOV 36H,#06H ACALL D0 JMP $-2 D0: MOV R0,#31H MOV R2,#11111110B MOV DPTR,#TAB D1: ORL P1,#00111111B MOV A,@R0 MOVC A,@A+DPTR MOV R3,#8 D2: RLC A MOV P3.2,C SETB P3.3 CLR ...

at89c51单片机实现电子时钟,不带闹铃。显示时分秒。求图求程序
\/*---延时子程序---*\/ void delay(uint count) \/\/delay { uint i;while(count){ i=200;while(i>0)i--;count--;} } void dsreset(void) \/\/send reset and initialization command { uint i; \/\/DS18B20初始化 DS=0;i=103;while(i>0)i--;DS=1;i=4;while(i>0)i--;} bit ...

求助!有谁比较懂硬件技术基础,AT89C51,单片机,帮我写个控制信号灯的程序...
流水灯呀:你把单片机的P0口就是左上角的32~39号引脚接上拉电阻(10K排阻)后,分别与1K电阻和发光二级管串联另一端接地,因为P0口带负载能力比较强所以用它。硬件连好了就可以编程了(最小系统你会吧我就不说了)C语言是根据硬件编程的程序如下:include<reg52.h> define uint unsigned int defin...

相似回答