#include
typedef unsigned char uchar;
typedef unsigned int uint;
uchar NUM_LED[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar key_value, key_temp1, key_temp2;
void Delay_1ms(uint i)
{
uint x,j;
for(j=0;j
for(x=0;x<=148;x++);
}
void led_Display(uchar tmp)
{
P5OUT=BIT0;
P4OUT= NUM_LED[tmp/10];
Delay_1ms(8);
P5OUT=BIT1;
P4OUT= NUM_LED[tmp%10];
Delay_1ms(8);
}
//检查按键,确认键值
uchar Check_Key(void)
{
uchar i,j, temp, kk,Buffer[4] = {0xfe, 0xfd, 0xfb, 0xf7};
kk=P1IN;
for(j=0; j<4; j++)
{
kk= Buffer[j];
Delay_1ms(2);
temp = 0x01;
for(i=0; i<4; i++)
{
if(!(kk& temp))
{
return (i+j*4); //返回取得的
}
temp <<= 1;
}
}
return 16;
}
void main (void)
{
WDTCTL = WDTHOLD + WDTPW ;
P1DIR|=0X0F;
P1OUT=0X0F;
P5DIR |= 0x01;
P5DIR |= 0x02;
P4DIR=0xff;
while(1)
{
P1OUT|=0xFF;;
key_temp1=Check_Key();
if(key_temp1!=16)
{
Delay_1ms(5);
key_temp2=Check_Key();
Delay_1ms(2);
if((key_temp1==key_temp2)&&(key_temp2!=16))
key_value=key_temp1;
}
led_Display(key_value);
}
}
P1.0-P1.3是行。
我上电后怎么没有高电平,全是低电平的。对430不熟悉,麻烦大家看看,谢谢。