| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1955 人关注过本帖
标题:郭天祥51单片机 矩阵键盘的程序问题,求解
只看楼主 加入收藏
梦的飞翔
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-3-7
结帖率:100%
收藏
 问题点数:0 回复次数:0 
郭天祥51单片机 矩阵键盘的程序问题,求解
要求如下:在没有键摁下的情况下,数码管没有显示。但是每摁下一个键后,会在六个数码上同时显示相同的数字,释放是数码管灭掉。
 
下面是我写的一个程序,运行的结果不对,没键摁下是数码管也有显示,键被摁下之后被释放,数码管依然有显示,这个问题要怎么解决呀?进主函数我就把数码管的位选全部关掉了,结果数码管是乱码,怎么回事???求高手解决,怎么改动这个程序
 
#include<reg52.h>
 #define uchar unsigned char
 #define uint  unsigned int
 sbit wela=P2^7;
 sbit dula=P2^6;
 uchar code table[]=
 {0x3f,0x06,0x5b,0x4f,
 0x66,0x6d,0x7d,0x07,
 0x7f,0x6f,0x77,0x7c,
 0x39,0x5e,0x79,0x71};
 uchar temp,num;
 
uchar keyscan();
 void display(uchar aa);
 void delay(uint z);
 
//主函数
 void main()
 {
 
        wela=1;
         P0=0xc0;    //开所有位选
         wela=0;
 
        dula=1;
         P0=0x00;
         dula=0;
 
        while(1)
                 {
                         display(keyscan());
                 }        
}
 //延时函数
 void delay(uint z)
 {
         uint x,y;
         for(x=z;x>0;x--)
                 for(y=110;y>0;y--);
 }
 //键盘扫描函数
 uchar keyscan()
 {
                         P3=0xfe;
                         temp=P3;
                         temp=temp&0xf0;
                         if(temp!=0xf0)
                                 {
                                         delay(8);                   //去抖
                                         temp=P3;
                                         temp=temp&0xf0;
                                         if(temp!=0xf0)
                                                 {
                                                         temp=P3;
                                                         switch(temp)
                                                                 {
                                                                         case 0xee:num=0;break;
                                                                         case 0xde:num=1;break;
                                                                         case 0xbe:num=2;break;
                                                                         case 0x7e:num=3;break;        
                                                                }
                                                 }
                                 }
 
                        P3=0xfd;
                         temp=P3;
                         temp=temp&0xf0;
                         if(temp!=0xf0)
                                 {
                                         delay(8);                   //去抖
                                         temp=P3;
                                         temp=temp&0xf0;
                                         if(temp!=0xf0)
                                                 {
                                                         temp=P3;
                                                         switch(temp)
                                                                 {
                                                                         case 0xed:num=4;break;
                                                                         case 0xdd:num=5;break;
                                                                         case 0xbd:num=6;break;
                                                                         case 0x7d:num=7;break;        
                                                                }
                                                 }
                                 }
 
                        P3=0xfb;
                         temp=P3;
                         temp=temp&0xf0;
                         if(temp!=0xf0)
                                 {
                                         delay(8);                   //去抖
                                         temp=P3;
                                         temp=temp&0xf0;
                                         if(temp!=0xf0)
                                                 {
                                                         temp=P3;
                                                         switch(temp)
                                                                 {
                                                                         case 0xeb:num=8;break;
                                                                         case 0xdb:num=9;break;
                                                                         case 0xbb:num=10;break;
                                                                         case 0x7b:num=11;break;        
                                                                }
                                                 }
                                 }
 
                        P3=0xf7;
                         temp=P3;
                         temp=temp&0xf0;
                         if(temp!=0xf0)
                                 {
                                         delay(8);                   //去抖
                                         temp=P3;
                                         temp=temp&0xf0;
                                         if(temp!=0xf0)
                                                 {
                                                         temp=P3;
                                                         switch(temp)
                                                                 {
                                                                         case 0xe7:num=12;break;
                                                                         case 0xd7:num=13;break;
                                                                         case 0xb7:num=14;break;
                                                                         case 0x77:num=15;break;        
                                                                }
                                                 }
                                 }
         return num;        
}
 
//数码管显示函数
 void display(uchar aa)
 {
                 dula=1;
                 P0=table[aa];
                 dula=0;        
}
搜索更多相关主题的帖子: 单片机 include 数码管 
2012-04-08 14:19
快速回复:郭天祥51单片机 矩阵键盘的程序问题,求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016932 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved