锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

矩阵键盘简单使用

时间:2024-04-29 13:07:10

#include#include#define uchar unsigned char#define uint unsigned intsbit SER = P2^0;sbit SRCLK = P2^1;sbit SRCLR = P2^2;sbit RRCLK =  P2^3;sbit E = P2^4;uchar table595[16]={0x30,0x7e,0x29,0x2c,0x66,0xa4,0xa0,0x3e,0x20,0x24,0x22,0xe0,0xb1,0x68,0xa1,0xa3};void delay(uchar z){ uchar x,y; for(x=0;x<110;x++)  for(y=0;y矩阵键盘扫描程序{ uchar num,temp; while(1) {  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=0;     break;     case 0xde:num=1;     break;     case 0xbe:num=2;     break;     case 0x7e:num=3;     break;    }    while(temp!=0xf0)    {     temp=P3;     temp=temp&0xf0;    }    return num;   }  }  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=4;     break;     case 0xdd:num=5;     break;     case 0xbd:num=6;     break;     case 0x7d:num=7;     break;    }    while(temp!=0xf0)    {     temp=P3;     temp=temp&0xf0;    }    return num;   }  }  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=8;     break;     case 0xdb:num=9;     break;     case 0xbb:num=10;     break;     case 0x7b:num=11;     break;    }    while(temp!=0xf0)    {     temp=P3;     temp=temp&0xf0;    }    return num;   }  }  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=12;     break;     case 0xd7:num=13;     break;     case 0xb7:num=14;     break;     case 0x77:num=15;     break;    }    while(temp!=0xf0)    {     temp=P3;     temp=temp&0xf0;    }    return num;   }  } }}void X74HC595(uchar j){ uchar i,temp; E = 1; _nop_(); _nop_(); E = 0; SRCLR = 1; temp=table595[j]; for(i=0;i<8;i++) {  temp=_crol_(temp,1);  SER = temp & 0x80; //p2.0连J9的1口  SRCLK = 0;  _nop_();  SRCLK = 1;   _nop_();  RRCLK= 0;   _nop_();  RRCLK = 1;  _nop_();  }}void main(){ uchar p; while(1) {  p=keyscan();  X74HC595(p); }}

-电子元器件采购网(www.ruidan.com)是本土元器件目录分销商,采用“小批量、现货、样品”销售模式,致力于满足客户多型号、高质量、快速交付的采购需求。 自建高效智能仓储,拥有自营库存超过50,000种,提供一站式正品现货采购、个性化解决方案、选型替代等多元化服务。
锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章