資源描述:
《基于mspf的矩陣按鍵掃描程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
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}}}/***********