基于msp430f149矩阵键盘

tcvsdonnnie   2012-8-10 20:51 楼主

#ifndef __KEY_H__
#define __KEY_H__
#include "delay.h"

uchar keys_scan()
{
            delay(10);
            uchar keyno=16;
            P1DIR=0Xf0;//高四位输出,低四位输入
            P1OUT=0xef;
            switch(P1IN&0x0f)
           {
                case 0x0e:  keyno=4;
                        break;
                case 0x0d:  keyno=3;
                        break;
                case 0x0b:  keyno=2;
                        break;
                case 0x07:  keyno=1;
                        break;
           }
            P1OUT=0xDf;       
            switch(P1IN&0x0f)
           {
                case 0x0e:  keyno=8;
                        break;
                case 0x0d:  keyno=7;
                        break;
                case 0x0b:  keyno=6;
                        break;
                case 0x07:  keyno=5;
                        break;
           }
            P1OUT=0xBf;       
            switch(P1IN&0x0f)
           {
                case 0x0e:  keyno=12;
                        break;
                case 0x0d:  keyno=11;
                        break;
                case 0x0b:  keyno=10;
                        break;
                case 0x07:  keyno=9;
                        break;
           }          
            P1OUT=0x7f;       
            switch(P1IN&0x0f)
           {
                case 0x0e:  keyno=16;
                        break;
                case 0x0d:  keyno=15;
                        break;
                case 0x0b:  keyno=14;
                        break;
                case 0x07:  keyno=13;
                        break;
           }               
           delay(20);
           return keyno;
}
#endif

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复