您的位置 首页 数字

根据PIC16F877单片机数码管显现矩阵键值

PIC16F877单片机数码管显示矩阵键值,4X4矩阵键盘一共有16个按键,对应的是0~F,十六进制数,本程序是利用行扫描法,进行循环扫描矩阵键盘

PIC16F877单片机数码管显现矩阵键值,4X4矩阵键盘一共有16个按键,对应的是0~F,十六进制数,本程序是使用行扫描法,进行循环扫描矩阵键盘,当每一行有一个按键被按下,它都会检测得到键值,然后数码管就会显现对应的数值啦。

#include   typedef unsigned char  uchar;  typedef unsigned int   uint;  uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0XD8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; //数码管共阳段码  uchar table_we[]={0xfe,0xfd,0xfb,0x7f,0xef,0xdf}; // 位码uchar temp;  //***********延时z毫秒***********/  void delay(uint z)  {  uint x,y;  for(x=z;x>0;x--)  for(y=110;y>0;y--);  }  void init()  {  TRISC=0X0f;//设置c端口高4位为输出,低4位为输入;  TRISD=0;  //设D口为输出TRISB=0;  //设B口为输出PORTB=0XFF;  }  void keyscan()  //矩阵键盘扫描子程序{  //uchar temp;  //榜首行扫描  PORTC=0X7f;//1110 1111  temp=PORTC;  temp=temp&0x0f;  if(temp!=0x0f)//有键按下  {  delay(10);  temp=PORTC;  temp=temp&0x0f;  if(temp!=0x0f)  {  temp=temp|0x70;  }  }  else  {  //第二行扫描  PORTC=0Xbf;  temp=PORTC;  temp=temp&0x0f;  if(temp!=0x0f)  {  delay(10);  temp=PORTC;  temp=temp&0x0f;  if(temp!=0x0f)  {  temp=temp|0xb0;  }  }  else  {  //第三行扫描  PORTC=0Xdf;  temp=PORTC;  temp=temp&0x0f;  if(temp!=0x0f)  {  delay(10);  temp=PORTC;  temp=temp&0x0f;  if(temp!=0x0f)  {  temp=temp|0xd0;  }  }  else  {  				   

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/shuzi/317951.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部