找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1403|回复: 0
打印 上一主题 下一主题
收起左侧

这是仅仅有一小部分功能的计算器程序,但液晶去没反应;求各位指出问题

[复制链接]
跳转到指定楼层
楼主
ID:284007 发表于 2018-3-7 13:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是仅仅有一小部分功能的计算器程序,但液晶去没反应;求各位指出问题;


  #include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^6;
sbit wr=P2^5;
sbit len=P2^7;
uchar annum,num,date;
uchar dis[16];

void delay(uint z)
{
        uint x,y;
        for(x=z;z>0;x--)
                for(y=110;y>0;y--);
}

void  write_com(uchar com)
{
        rs=0;
        P0=com;
        delay(5);
        len=1;
        delay(5);
        len=0;
        
}

void write_date(uchar date)
{
        rs=1;
        P0=date;
        delay(5);
        len=1;
        delay(5);
        len=0;
}

void keyscan()
{
        uchar temp,key;
        P3=0xfe;
        temp=P3;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(10);
                temp=P3;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                         temp=P3;
                        switch(temp)
                        {
                                case 0xee:
                                num=0;
                                break;
                                annum++;
                                case 0xde:
                                num=1;
                                annum++;
                                break;
                                case 0xbe:
                                num=2;
                                annum++;
                                break;
                                case 0x7e:
                                num=3;
                                annum++;
                                break;
                        }
                        while(temp!=0xf0);
                        {
                                P3=temp;
                                temp=temp&0xf0;
                        }                        
                }
        }
        P3=0xfd;
        temp=P3;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(5);
                temp=P3;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P3;
                        switch(temp)
                        {
                                case 0xed:
                                num=4;
                                annum++;
                                break;
                                case 0xdd:
                                num=5;
                                annum++;
                                break;
                                case 0xbd:
                                num=6;
                                annum++;
                                break;
                                case 0x7d:
                                num=7;
                                annum++;
                                break;
                        }
                        while(temp!=0xf0)
                        {
                        
                                temp=P3;
                                temp=temp&0xf0;
                        }
                }
        }
        P3=0xfb;
        temp=P3;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(10);
                temp=P3;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P3;
                        switch(temp)
                        {
                                case 0xeb:
                                num=8;
                                annum++;
                                break;
                                case 0xdb:
                                num=9;
                                annum++;
                                break;
                                case 0xbb:
                                num=10;
                                break;
                                case 0x7b:
                                num=11;
                                break;


                        }
                        while(temp!=0xf0)
                        {
                                temp=P3;
                                temp=temp&0xf0;
                        }
                }
        }
        P3=0xf7;
        temp=P3;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                delay(10);
                temp=P3;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P3;
                        switch(temp)
                        {
                                case 0xe7:
                                num=12;
                                break;
                                case 0xd7:
                                num=13;
                                case 0xb7:
                                num=14;
                                break;
                                case 0x77:
                                num=15;
                                break;
                        }
                        while(temp!=0xf0)
                        {
                                temp=P3;
                                temp&0xf0;

                        }
                }


        }

}

uchar keysuan(uchar date)
{
          if(num==0)
                date=date+(num*annum*10);
        if(num==1)        
                date=date+(num*annum*10);
        if(num==2)
                date=date+(num*annum*10);
        if(num==3)
                date=date+(num*annum*10);
        if(num==4)
                date=date+(num*annum*10);
        if(num==4)
                date=date+(num*annum*10);
        if(num==5)
                date=date+(num*annum*10);
        if(num==6)
                date=date+(num*annum*10);
        if(num==7)
                date=date+(num*annum*10);
        if(num==8)
                date=date+(num*annum*10);
        
        if(num==9)
                {date=date+(num*annum*10);}
                return date;
         
}

void jisuan()
{
        write_com(0x80+0x40+16);
        dis[0]=date%10+0x30;
        dis[1]=date/10%10+0x30;
        dis[2]=date/100%10+0x30;
        dis[3]=date/1000%10+0x30;
        dis[4]=date/10000%10+0x30;
        dis[5]=date/100000%10+0x30;
        dis[6]=date/1000000%10+0x30;
        dis[7]=date/10000000%10+0x30;
        dis[8]=date/100000000%10+0x30;
        dis[9]=date/1000000000%10+0x30;
        dis[10]=date/10000000000%10+0x30;
}

void display()
{
  uchar i=0;
        write_com(0x80+0x50);
        while(dis[i]!='\0')
        {
                write_date(dis[i]);
                i++;
        }
        i=0;
}

void init()
{
    date=0;
        wr=0;
        write_com(0x38);
        write_com(0x0f);
        write_com(0x04);
        write_com(0x01);
}

void main()
{
        init();
        while(1)
        {
          keyscan();
          keysuan();
          jisuan();
          display();

        }

}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表