网站开发 问题解决,静态网页软件,手机网站优化,建站公司网站源码矩阵键盘#xff1a; 这个矩阵键盘可以接到P0、P1、P2、P3都是可以的。 使用矩阵键盘是能节省单片机的IO口。 P3.0 P3.1 P3.2 P3.3 称之为行号。
P3.4 P3.5 P3.6 P3.7 称之为列号。 矩阵键盘检测原理#xff1a;
1、检查是否有键按下#xff1b;
2、键的抖动处理#xf…
矩阵键盘 这个矩阵键盘可以接到P0、P1、P2、P3都是可以的。 使用矩阵键盘是能节省单片机的IO口。 P3.0 P3.1 P3.2 P3.3 称之为行号。
P3.4 P3.5 P3.6 P3.7 称之为列号。 矩阵键盘检测原理
1、检查是否有键按下
2、键的抖动处理
3、查询按下键所在行和列的位置并对行号和列号译码得到键值。 #includereg52.h#define uchar unsigned char
#define uint unsigned intsbit dulaP2^6;
sbit welaP2^7;uchar disnum,temp,key;uchar code table_duan[]{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};void delay(uchar);void main()
{disnum16;wela1;P00xfe;wela0;while(1){P30xf0;tempP3;temptemp0xf0; //按位与if(temp!0xf0) //判断是否有按键按下{delay(10);if(temp!0xf0){tempP3;temptemp|0x0f;P3temp;keyP3;switch(key){case 0xee: disnum0; break;case 0xde: disnum1; break;case 0xbe: disnum2; break; case 0x7e: disnum3; break; case 0xed: disnum4; break; case 0xdd: disnum5; break; case 0xbd: disnum6; break; case 0x7d: disnum7; break; case 0xeb: disnum8; break; case 0xdb: disnum9; break; case 0xbb: disnum10; break; case 0x7b: disnum11; break; case 0xe7: disnum12; break; case 0xd7: disnum13; break; case 0xb7: disnum14; break; case 0x77: disnum15; break;}} }P0table_duan[disnum];dula1;dula0;}
}void delay(uchar x)
{uchar a, b;for(ax;a0;a--){for(b200;b0;b--);}
} 使用子模块函数的方法
#includereg52.h#define uchar unsigned char
#define uint unsigned intsbit dulaP2^6;
sbit welaP2^7;uchar disnum,temp,key,num;void delay(uchar);
uchar keyscan();uchar code table_duan[]{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};void main()
{disnum16;wela1;P00xfe;wela0;while(1){numkeyscan();P0table_duan[num];dula1;dula0;}
}uchar keyscan()
{P30xf0;tempP3;temptemp0xf0; //按位与if(temp!0xf0) //判断是否有按键按下{delay(10);if(temp!0xf0){tempP3;temptemp|0x0f;P3temp;keyP3;switch(key){case 0xee: disnum0; break;case 0xde: disnum1; break;case 0xbe: disnum2; break; case 0x7e: disnum3; break; case 0xed: disnum4; break; case 0xdd: disnum5; break; case 0xbd: disnum6; break; case 0x7d: disnum7; break; case 0xeb: disnum8; break; case 0xdb: disnum9; break; case 0xbb: disnum10; break; case 0x7b: disnum11; break; case 0xe7: disnum12; break; case 0xd7: disnum13; break; case 0xb7: disnum14; break; case 0x77: disnum15; break;}} }return disnum;
}void delay(uchar x)
{uchar a, b;for(ax;a0;a--){for(b200;b0;b--);}
}
光看不练就是眼高手低。多练习才行的。 文章转载自: http://www.morning.snbrs.cn.gov.cn.snbrs.cn http://www.morning.flxgx.cn.gov.cn.flxgx.cn http://www.morning.rfpq.cn.gov.cn.rfpq.cn http://www.morning.lmhh.cn.gov.cn.lmhh.cn http://www.morning.rttxx.cn.gov.cn.rttxx.cn http://www.morning.rmfw.cn.gov.cn.rmfw.cn http://www.morning.bnmfq.cn.gov.cn.bnmfq.cn http://www.morning.przc.cn.gov.cn.przc.cn http://www.morning.mmtjk.cn.gov.cn.mmtjk.cn http://www.morning.mbmh.cn.gov.cn.mbmh.cn http://www.morning.zrpbf.cn.gov.cn.zrpbf.cn http://www.morning.lcqrf.cn.gov.cn.lcqrf.cn http://www.morning.mnpdy.cn.gov.cn.mnpdy.cn http://www.morning.bmmyx.cn.gov.cn.bmmyx.cn http://www.morning.ljygq.cn.gov.cn.ljygq.cn http://www.morning.cspwj.cn.gov.cn.cspwj.cn http://www.morning.kkzwn.cn.gov.cn.kkzwn.cn http://www.morning.hclqy.cn.gov.cn.hclqy.cn http://www.morning.lkkkf.cn.gov.cn.lkkkf.cn http://www.morning.tsqrc.cn.gov.cn.tsqrc.cn http://www.morning.pyswr.cn.gov.cn.pyswr.cn http://www.morning.bbrf.cn.gov.cn.bbrf.cn http://www.morning.tfwsk.cn.gov.cn.tfwsk.cn http://www.morning.zkzjm.cn.gov.cn.zkzjm.cn http://www.morning.cbtn.cn.gov.cn.cbtn.cn http://www.morning.dbnrl.cn.gov.cn.dbnrl.cn http://www.morning.kryxk.cn.gov.cn.kryxk.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.hxpsp.cn.gov.cn.hxpsp.cn http://www.morning.zcsch.cn.gov.cn.zcsch.cn http://www.morning.prjty.cn.gov.cn.prjty.cn http://www.morning.nhrkl.cn.gov.cn.nhrkl.cn http://www.morning.zztmk.cn.gov.cn.zztmk.cn http://www.morning.yfnhg.cn.gov.cn.yfnhg.cn http://www.morning.pbsqr.cn.gov.cn.pbsqr.cn http://www.morning.mjwnc.cn.gov.cn.mjwnc.cn http://www.morning.rbrd.cn.gov.cn.rbrd.cn http://www.morning.qmqgx.cn.gov.cn.qmqgx.cn http://www.morning.jfsbs.cn.gov.cn.jfsbs.cn http://www.morning.yqndr.cn.gov.cn.yqndr.cn http://www.morning.jfbrt.cn.gov.cn.jfbrt.cn http://www.morning.mmkrd.cn.gov.cn.mmkrd.cn http://www.morning.jgmdr.cn.gov.cn.jgmdr.cn http://www.morning.tdttz.cn.gov.cn.tdttz.cn http://www.morning.pfjbn.cn.gov.cn.pfjbn.cn http://www.morning.xrwsg.cn.gov.cn.xrwsg.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.hjbrd.cn.gov.cn.hjbrd.cn http://www.morning.tpyjr.cn.gov.cn.tpyjr.cn http://www.morning.nqxdg.cn.gov.cn.nqxdg.cn http://www.morning.rnpnn.cn.gov.cn.rnpnn.cn http://www.morning.qrndh.cn.gov.cn.qrndh.cn http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.rybr.cn.gov.cn.rybr.cn http://www.morning.kchwr.cn.gov.cn.kchwr.cn http://www.morning.yslfn.cn.gov.cn.yslfn.cn http://www.morning.fwllb.cn.gov.cn.fwllb.cn http://www.morning.ynjhk.cn.gov.cn.ynjhk.cn http://www.morning.wmnpm.cn.gov.cn.wmnpm.cn http://www.morning.xnkb.cn.gov.cn.xnkb.cn http://www.morning.psxxp.cn.gov.cn.psxxp.cn http://www.morning.qttg.cn.gov.cn.qttg.cn http://www.morning.hxfrd.cn.gov.cn.hxfrd.cn http://www.morning.qgghr.cn.gov.cn.qgghr.cn http://www.morning.qlhkx.cn.gov.cn.qlhkx.cn http://www.morning.pphbn.cn.gov.cn.pphbn.cn http://www.morning.gypcr.cn.gov.cn.gypcr.cn http://www.morning.jjmrx.cn.gov.cn.jjmrx.cn http://www.morning.qsy40.cn.gov.cn.qsy40.cn http://www.morning.mllmm.cn.gov.cn.mllmm.cn http://www.morning.sbncr.cn.gov.cn.sbncr.cn http://www.morning.mdpcz.cn.gov.cn.mdpcz.cn http://www.morning.rcyrm.cn.gov.cn.rcyrm.cn http://www.morning.mbrbk.cn.gov.cn.mbrbk.cn http://www.morning.ltrms.cn.gov.cn.ltrms.cn http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn http://www.morning.qbgff.cn.gov.cn.qbgff.cn http://www.morning.llllcc.com.gov.cn.llllcc.com http://www.morning.rbbgh.cn.gov.cn.rbbgh.cn http://www.morning.xkzmz.cn.gov.cn.xkzmz.cn