基于mspf的矩阵按键扫描程序_第1页
基于mspf的矩阵按键扫描程序_第2页
基于mspf的矩阵按键扫描程序_第3页
基于mspf的矩阵按键扫描程序_第4页
基于mspf的矩阵按键扫描程序_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、基于msp430f5438的矩阵按键扫描程序* * function: matrix key scan program*/#include msp430x54x.h/* macro definition*/#define uint unsigned int / / definition data type abbreviation#define uchar unsigned char#define KEY_IN P4IN / / define port register#define KEY_OUT P4OUT#define KEY_DIR P4DIR#define B0 (0x01) / /

2、 a definition#define B1 (0x02)#define B2 (0x04)#define B3 (0x08)#define B4 (0x10)#define B5 (0x20)#define B6 (0x40)#define B7 (0x80)/* function declaration*/Uchar Scan (void); / / matrix keyboard scanningVoid Delay (uint delay_num); / / delay functionUint Translate (uchar code); / / scan code transl

3、ation/* global variable definition*/Uchar key_code; / / return to the keyboard scan codeUint key_value; / / the corresponding digital keyboardConst uchar / / key_table17=scan decoding table0xFF / / no key press / / four high scanning line, for the low four column scanning0x7E / / K10x7D / / K20x7B /

4、 / K30x77 / / K40xBE / / K50xBD / / K60xBB / / K70xB7 / / K80xDE / / K90xDD / / K100xDB / / K110xD7 / / K120xEE / / K130xED / / K140xEB / / K150xE7 / / K16;/* function (module) Name: Main ()* * function: call the keyboard scanner, initialize the I/O port* call the function list: scan (), Translate (

5、)* call this function list: None* input parameters: None* output parameters: None* * function return value: no* Resource watchdog I/O port module used by * * other instructions: None*/Void main (void)WDTCTL = WDTPW + WDTHOLD; / / stop watchdogKEY_DIR = (B7 + B6 + B5 + B4); / / set IO high 4 bit outp

6、ut, low input for 4KEY_OUT = 0x00; / / IO high 4 bit output low levelWhile (1)Key_code = Scan ();Call / return scanner, scan codeKey_value = Translate (key_code); / / call scan code translation function returns the digital keyboardIf (key_value! = 0) / / if a key(_NOP); / / set a breakpoint here, ob

7、serve the scan code and digital keyboard/* function (module) Name: Scan ()* function: query the key status, return the key value* call the function list: Delay ();* call this function list: None* input parameters: None* output parameters: keyboard scan code* * function return value: no* resource I/O

8、 port used by * * other instructions:*/Uchar Scan (void)Uint i;Uchar col_scan = 0; / / scan variableUchar key_code = 0xFF; / / scan codeKEY_OUT = 0x00; / / all 4 lines to zero, to determine whether a key is pressedIf (KEY_IN & 0x0F)! = / / 0x0F) to determine whether a key is pressedDelay (5000); / /

9、 keyboard debounce delay 20 msIf (KEY_IN & 0x0F)! = 0x0F) / / again determine the key is validKey_code = KEY_IN & 0x0F; / / save column scan codeCol_scan = B7; / / the first scan line 1For (i=4; i0; i-) / / scan lineKEY_OUT = 0xFF & (col_scan); / / the corresponding line scan set low levelIf (KEY_IN

10、 & 0x0F)! = 0x0F) / / if theres a buttonBreak;Col_scan = col_scan 1; / / scan lineCol_scan = (col_scan & 0xF0); / / get the line scan codeKey_code |= col_scan; / / get the full keyboard scan codeKEY_OUT = 0x00; / / all 4 lines to zero, to determine whether a key is pressedWhile (KEY_IN & 0x0F)! = 0x

11、0F); / / wait for the press releaseReturn (key_code); / / return key/* function (module) Name: Translate* * function: scan code translation* call the function list: None* call this function list: None* input parameters: None* output parameter: keyboard corresponds to the number, if the output is 0, indicating no key press* * function return value: no* * resources are

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论