欢迎来到天天文库
浏览记录
ID:12411079
大小:18.01 KB
页数:11页
时间:2018-07-16
《基于mspf的矩阵按键扫描程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、基于msp430f5438的矩阵按键扫描程序**function:matrixkeyscanprogram*************************************************/#include"msp430x54x.h""/**************************************************macrodefinition*************************************************/#defineuintunsignedint//definitiondatatypeab
2、breviation#defineucharunsignedchar#defineKEY_INP4IN//defineportregister#defineKEY_OUTP4OUT#defineKEY_DIRP4DIR#defineB0(0x01)//adefinition#defineB1(0x02)#defineB2(0x04)#defineB3(0x08)#defineB4(0x10)#defineB5(0x20)#defineB6(0x40)#defineB7(0x80)/*******************************************
3、*******functiondeclaration*************************************************/UcharScan(void);//matrixkeyboardscanningVoidDelay(uintdelay_num);//delayfunctionUintTranslate(ucharcode);//scancodetranslation/**************************************************globalvariabledefinition*********
4、****************************************/Ucharkey_code;//returntothekeyboardscancodeUintkey_value;//thecorrespondingdigitalkeyboardConstuchar//key_table[17]={scandecodingtable0xFF//nokeypress//fourhighscanningline,forthelowfourcolumnscanning0x7E//K10x7D//K20x7B//K30x77//K40xBE//K50xBD/
5、/K60xBB//K70xB7//K80xDE//K90xDD//K100xDB//K110xD7//K120xEE//K130xED//K140xEB//K150xE7//K16};/**************************************************function(module)Name:Main()**function:callthekeyboardscanner,initializetheI/Oport*callthefunctionlist:scan(),Translate()*callthisfunctionlist:N
6、one*inputparameters:None*outputparameters:None**functionreturnvalue:no*ResourcewatchdogI/Oportmoduleusedby***otherinstructions:None*************************************************/Voidmain(void){WDTCTL=WDTPW+WDTHOLD;//stopwatchdogKEY_DIR=(B7+B6+B5+B4);//setIOhigh4bitoutput,lowinputfor
7、4KEY_OUT=0x00;//IOhigh4bitoutputlowlevelWhile(1){Key_code=Scan();Call/returnscanner,scancodeKey_value=Translate(key_code);//callscancodetranslationfunctionreturnsthedigitalkeyboardIf(key_value!=0)//ifakey{(_NOP);//setabreakpointhere,observethescancodeanddigitalkeyboard}}}/***********
此文档下载收益归作者所有