您的位置 首页 方案

轻松搞定独立键盘操控与4*4行列式矩阵键盘扫描

电路图很简单就不画了,电路的接法是p1口接矩阵键盘,p3口接独立键盘,8个led灯接在p0口上的includereg52h>defineucharunsign

电路图很简单就不画了,电路的接法是p1口接矩阵键盘,p3口接独立键盘,8个led灯接在p0口上的.

#include#define uchar unsigned char#define uint unsigned int#define on 0#define off 1sbit led1=P0^0;sbit led2=P0^1;sbit led3=P0^2;sbit led4=P0^3;sbit led5=P0^4;sbit led6=P0^5;sbit led7=P0^6;sbit led8=P0^7;sbit key1=P3^0;sbit key2=P3^1;sbit key3=P3^2;sbit key4=P3^3;sbit key5=P3^4;sbit key6=P3^5;sbit key7=P3^6;sbit key8=P3^7;void delay_ms(uchar time){uchar i,j;for(i=time;i>0;i--){for(j=85;j>0;j++){;}}}uchar scan_key(){//uchar i,j;//P3=0xff;if((P3&0xff)!=0xff){delay_ms(30);if((P3&0xff)!=0xff){if(key1==0)return(1);if(key2==0)return(2);if(key3==0)return(3);if(key4==0)return(4);if(key5==0)return(5);if(key6==0)return(6);if(key7==0)return(7);if(key8==0)return(8);}}return 0;}void main(void){uchar key_value;key_value=scan_key();switch(key_value){case 1:led1=on;break;case 2:led2=on;break;case 3:led3=on;break;case 4:led4=on;break;case 5:led5=on;break;case 6:led6=on;break;case 7:led7=on;break;case 8:led8=on;break;default:P0=0xff;}}4*4行列式矩阵键盘#includesbit led1 =P0^0  ;sbit led2 =P0^1  ;sbit led3 =P0^2  ;sbit led4 =P0^3  ;sbit led5 =P0^4  ;sbit led6 =P0^5  ;sbit led7 =P0^6  ;sbit led8 =P0^7  ;#define on 0#define off 1#define uchar unsigned char#define uint unsigned intvoid delay_ms(uint time){uint i,j;for(i=time;i>0;i--)for(j=112;j>0;j--){}}//d/*uchar s_scan(void){uchar scan_code,temp;P1=0xf0;if((P1&0xf0)!=0x0f){delay_ms(30);if((P1&0xf0)!=0xf0){scan_code=0xfe;while((scan_code&0x10)!=0){P1=scan_code;if((P1&0xf0)!=0xf0){temp=(P1&0xf0)|0x0f;while((P1&0xf0)!=0xf0)return ((~scan_code)+(~temp));}elsescan_code=(scan_code<<1)|0x01;}}}return 0;}//*//*uchar s_scan(void){uchar scanh,scanl;P1=0xf0;if((P1&0xf0)!=0xf0){P1=0xf0;delay_ms(30);if((P1&0xf0)!=0xf0){ P1=0xfe ;//P1=scanh;if((P1&0xf0)!=0xf0){P1&=0xf0;if(P1==0xe0)return(1);if(P1==0xd0)return(2);if(P1==0xb0)return(3);if(P1==0x70)return(4);}P1=0xfd;if((P1&0xf0)!=0xf0){P1&=0xf0;if(P1==0xe0)return(5);if(P1==0xd0)return(6);if(P1==0xb0)return(7);if(P1==0x70)return(8);}P1=0xfb;if((P1&0xf0)!=0xf0){P1&=0xf0;if(P1==0xe0)return(9);if(P1==0xd0)return(10);if(P1==0xb0)return(11);if(P1==0x70)return(12);}  P1=0xf7;if((P1&0xf0)!=0xf0){P1&=0xf0;if(P1==0xe0)return(13);if(P1==0xd0)return(14);if(P1==0xb0)return(15);if(P1==0x70)return(16);}}}return 0;}*/void main(void){ uchar key_code;while(1){key_code=s_scan();if(key_code)P0=key_code;/*    delay_ms(300);led1=~led1;delay_ms(300);switch(key_code){case 1:led1=on;break;case 2:led2=on;break;case 3:led3=on;break;case 4:led4=on;break;case 5:led5=on;break;case 6:led6=on;break;case 7:led7=on;break;case 8:led8=on;break;default:P0=0xff;}*/}}

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

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

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

微信扫一扫关注我们

返回顶部