资源描述:
《基于mspf的矩阵按键扫描程序(matrix key scanning program based on mspf)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、基于msp430F5438的矩阵按键扫描程序(Matrixkeyscanningprogrambasedonmsp430F5438)**function:matrixkeyscanningprogram*************************************************/#include"msp430x54x.H"/***************************************************amacrodefinition*********************************************
2、****/#defineuintunsignedint//definedatatypeabbreviation#defineucharunsignedchar#definekey_inP4IN//defineportregisters#defineKEY_OUTP4OUT#defineKEY_DIRP4DIR#defineB0(0x01)//bitdefinition#defineB1(0x02)#defineB2(0x04)#defineB3(0x08)#defineB4(0x10)#defineB5(0x20)#defineB6(0x40)#defineB7(0
3、x80)/*************************************************Functiondeclaration*************************************************/UcharScan(void);//matrixkeyboardscanningVoidDelay(uintdelay_num);//delayfunctionUintTranslate(ucharcode);//scancodetranslation/************************************
4、***************globalvariabledefinition*************************************************/Ucharkey_code;//thekeyboardscancodereturnedUintkey_value;//thenumbercorrespondingtothekeyboardConstucharkey_table[17]={//scancodetable0xFF,//nobuttonpress//high4arescanrow,andlowfourarescancolumns0
5、x7e,//K10x7d,//K20x7b,//K30x77,//K40xbe,//K50XBD,//K60XBB,//K70xb7,//K80xde,//K90XDD,//k10/19dated0XDB,//K110xd7,//K120xee,//K130xed,//K140xeb,//K150xe7,//K16};/***************************************************function(module)name:main()**function:callthekeyboardscanningprogram,initi
6、alizingI/Oport**callfunctionlist:scan(),Translate()**callthisfunctionlist:no**inputparameters:no**outputparameters:no**functionreturnvaluedescription:no**useoftheresourcewatchdogI/Oportmodule**otherinstructions:no*************************************************/Voidmain(void){WDTCTL=W
7、DTPW+WDTHOLD;//stopthewatchdogKEY_DIR=(B7+B6+B5+B4);//setIOfor4bitsforoutputand4forinputKEY_OUT=0x00;//IOhigh4bitoutputlowlevelWhile(1){Key_code=Scan();//callthescannerandreturnthescancodeKey_value=Translate(key_code);//thescancodetranslationfunction,whichreturnsthekeyboardnumberIf(k