矩阵键盘驱动及例程.docxVIP

  • 1
  • 0
  • 约 11页
  • 2017-10-16 发布于重庆
  • 举报
矩阵键盘驱动及例程

4X5矩阵键盘驱动及例程右下是一4X5的薄膜矩阵键盘,有9条引出线,从左到右分别对应4列5排。为节省IO口,我把第一条线节GND其余8条线按顺序接到STC IAP15W4K61S4的P2口上,由于该键盘,没有小数点按键,我将“#”设成了小数点。以下是驱动及测试例程的源代码。/***********************************例程主函数main.c*********************************//#include lcd2004a.h#include keyboard.h#include string.h#include stdlib.hBYTE String[21]=;BYTE StringNull[21]= ;void main(){Io_Init(0,0x00, 0x00);//初始化P0口Io_Init(2,0x00, 0x00);//初始化P2口Io_Init(4,0x00, 0x00); //初始化P4口LCDInit();//初始化LCD2004Awhile(1){BYTE tem;strcpy(String,Your key value is:);LCDDisplayString(1, 0,String);tem=GetKeyIn();DisplayLongInt(2,0,tem);strcpy(String,StringNull);String[0]=GetKeyIn();LCDDisplayString(3, 0,String);DisplayLongInt(4,0,KEY_DATAPINS);Delay1000ms();//@20.000MHz}}/**************************************keyboard.h/***************************************************Mtrix keyboard driver, by Bill Liu2015,03,28 rev 0. ***************************************************/ #ifndef __KEYBOARD_H__ #define __KEYBOARD_H__ #include mytype.h #include stdlib.h #include ctype.h #include myport.h BYTE GetKeyIn(); //Get push down key #endif/*********************************Keyboard.c**********************************//***************************************************Matrix keyboard drive program, by Bill Liu2015,03,28 rev 0. ***************************************************/ /*************************************************** 5X4 matrix keyboard, 5 rows, 4 columns, 9 lines, 1~4 lines are columns 5~9 are rows. 1 to GND, 2~4 to P27~P25,5~9 to P24~P20, cloumn drive(Low). KEY value: Arrow(L)-239(0xEF), 7-247(0xF7), 4-251(0xFB), 1-253(0xFD), F1-254(0xFE),0-111(0x6F), 8-119(0x77), 5-123(0x7B), 2-125(0x7D), F2-126(0x7E),Arrow(R)-175(0xAF), 9-183(0xB7), 6-187(0xBB), 3-189(0xBD), #-190(0xBE),Ent-207(0xCF), Esc-215(0xD7), Arrow(down)-219(0xDB), Arrow(up)-221(0xDD), *-222(0xDE) ****************************************************/#include keyboard.h//*****************************************************BYTE GetKeyIn() //Get pu

文档评论(0)

1亿VIP精品文档

相关文档