文档详情

基于ats的矩阵键盘(Matrix keyboard based on ATS).doc

发布:2018-06-24约3.25千字共12页下载文档
文本预览下载声明
基于at89s52的矩阵键盘(Matrix keyboard based on AT89S52) /****************************************** Function: matrix keyboard (press the corresponding button, digital tube from 0~F display) Single chip microcomputer: AT89S52 ******************************************/ #include reg52.h #define uint unsigned int #define uchar unsigned char Sbit DAT=P0^3; Sbit CLK=P0^2; Uchar, temp, h; Void delay (uint); / / delay procedures Void sendbyte (uchar); / / digital display Void (keyscan); / / key scan Uchar code tab[]={ 0xed, 0x09,0xbc, 0x9d, 0x59,0xd5, 0xf5,0x0d, 0xfd, 0xdd, 0x7d, 0xf1, 0xe4,0xb9,0xf4,0x74,0x00}, //0-F, total elimination Void main (void) { Sendbyte (16); / / initial digital tube display While (1) { (keyscan); / / key scan } } Void delay (uint z) { Uint, x, y; For (x=z; x0; x--) For (y=100; y0; y--); } Void sendbyte (uchar byte) { Uchar, num, c; Num=tab[byte]; For (c=0; c8; c++) { CLK=0; DAT=num0x01; CLK=1; Num=1; / / right shift assignment } } Void, keyscan () { The first line of the key scan / * P2=0xfe; / / determine the first line of the key is effective Temp=P2; / / assign it to a variable (I/O port, the first general assignment to a variable, and then through the processing variables to handle the I/O port) Temp=temp0xf0; / / for which the first line of the press button detection While (temp! =0xf0) / * this part as long as is used to eliminate the jitter / press { Delay (5); Temp=P2; Temp=temp0xf0; While (temp! =0xf0) / / this place has been eliminated, press the jitter, P2 values have been determined { Temp=P2; / / P2 port value assigned to the variable Switch (Temp) / / the switch statement is used to determine which button is pressed, the digital tube display value { Case 0x7e:h=0; Break break; / / this is very important, if there is a matching value, jump out of the switch statement, to prevent the program jump out. Case 0xbe:h=1; Break; Case 0xde:h=2; Break; Case 0xee:h=3; Break; Default: h=16; Break; } While (temp! =0xf0) / * this part as long as is us
显示全部
相似文档