新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 基于PIC16F877单片机数码管显示矩阵键值

基于PIC16F877单片机数码管显示矩阵键值

作者: 时间:2016-11-30 来源:网络 收藏
值,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  {  				   
				
            
                
			
							
上一页 1 2 下一页

评论


技术专区

关闭