各位,调了半天了,怎么貌似都不得行啊,麻烦各位大神帮我看一看~,谢谢!
#include "msp430g2553.h"
unsigned char H[]={0xe0,0xd0,0xb0,0x70}; //行
unsigned char L[] ={BIT0,BIT1,BIT2,BIT3}; //列
unsigned int keyvalue;
unsigned int keyscan(void);
int main( void )
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to prevent time out reset
P1SEL=0X00;
P1DIR =0Xf0;
P2DIR |= BIT0; // 设置输出
// P2OUT &=~BIT0;
for(;;)
{
keyscan();
if(keyvalue<16)
{
P2OUT &=~BIT0;
_delay_cycles(500);
}
}
}
unsigned int keyscan(void)
{
unsigned int i=0,lie=0,j=0,hang=0;
P1REN=0X0F; //上拉使能
// P1IN=0X0f;
P1OUT=0xf0;
if((P1IN & 0X0F)!=0X0F)
{
_delay_cycles(100);
if((P1IN & 0X0F)!=0X0F)
{
_delay_cycles(100);
for(i=0;i<4;i++) //行检测
{
P1OUT = H
;
for(j=0;j<4;j++)//列检测
{
if((P1IN & L[j])!=L[j])
{
// P1OUT=0X00;
hang=i;
lie=j;
keyvalue=lie+hang*4;
}
}
}
}
}
return keyvalue;
}
此帖出自小平头技术问答
[ 本帖最后由 carlnerv 于 2012-8-3 09:41 编辑 ]
一周热门 更多>