烟光残照294 2021-07-28 15:49 采纳率: 100%
浏览 28
已结题

对应矩阵按键控制数码管,没有现象

#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar num,temp;
void delay(uint z)
{
uint x,y;
for(x=z;x>=0;x--)
for(y=110;y>0;y--);
}

uint code table[]={0x3f,
0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,
0x6f,0x77,0x7c,0x39,
0x5e,0x79,0x71,0x80,
0x00};
void main()
{

while(1)
{
    wela=1;
    P0=0xc0;
    wela=0;
    
    dula=1;
  P0=0;
  dula=0;
    P3=0xfe;
    temp=P3;
    temp=temp&0xf0;
    while(temp!=0xf0)
    {
        delay(5);
        temp=P3;
        temp=temp&0xf0;
        while(temp!=0xf0)
        {
            temp=P3;
        switch(temp)
        {
            case 0xee:num=1;                //11101110
                break;   
            case 0xde:num=2;                  //11011110
              break;
            case 0xbe:num=3;                  //10111110
              break;
            case 0x7e:num=4;                  //01111110
              break;
            
        }
            while (temp != 0xf0)
            {
                temp = P3;
                temp = temp & 0xf0;
            }
        }
            dula=1;
    P0=table[num-1];
    dula=0;
    }
    P3=0xfd;
    temp=P3;
    temp=temp&0xf0;
    while(temp!=0xf0)
    {
        delay(5);
        temp=P3;
        temp=temp&0xf0;
        while(temp!=0xf0)
        {
            temp=P3;
        switch(temp)
        {
            case 0xed:num=5;                  //11101101
                break;   
            case 0xdd:num=6;                  //11011101
              break;
            case 0xbd:num=7;                  //10111101
              break;
            case 0x7d:num=8;                  //01111101
              break;
            
        }
            while (temp != 0xf0)
            {
                temp = P3;
                temp = temp & 0xf0;
            }
        }
            dula=1;
    P0=table[num-1];
    dula=0;
    }
    P3=0xfb;
    temp=P3;
    temp=temp&0xf0;
    while(temp!=0xf0)
    {
        delay(5);
        temp=P3;
        temp=temp&0xf0;
        while(temp!=0xf0)
        {
            temp=P3;
        switch(temp)
        {
            case 0xeb:num=9;                  //11101011
                break;   
            case 0xdb:num=10;                  //11011011
              break;
            case 0xbb:num=11;                  //10111011
              break;
            case 0x7b:num=12;                  //01111011
              break;
            
        }
            while (temp != 0xf0)
            {
                temp = P3;
                temp = temp & 0xf0;
            }
        }
            dula=1;
    P0=table[num-1];
    dula=0;
    }
    P3=0xf7;
    temp=P3;
    temp=temp&0xf0;
    while(temp!=0xf0)
    {
        delay(5);
        temp=P3;
        temp=temp&0xf0;
        while(temp!=0xf0)
        {
            temp=P3;
        switch(temp)
        {
            case 0xe7:num=13;                  //11100111
                break;   
            case 0xd7:num=14;                  //11010111
              break;
            case 0xb7:num=15;                  //10110111
              break;
            case 0x77:num=16;                  //01110111
              break;
            
        }
            while (temp != 0xf0)
            {
                temp = P3;
                temp = temp & 0xf0;
            }
        }
            dula=1;
    P0=table[num-1];
    dula=0;
    }
}

}

  • 写回答

1条回答 默认 最新

  • 烟光残照294 2021-07-28 16:45
    关注

    是延时函数错了,延时函数延时了5ms,导致数码管的数字被覆盖,可以延时到100us左右就可以了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 8月6日
  • 已采纳回答 7月29日
  • 创建了问题 7月28日

悬赏问题

  • ¥15 MATLAB动图的问题
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名