|
利用msp430g2553做独立按键,出现问题,求教
[复制链接]
我用g2553做了四个独立的按键,希望没次按下一个键就用数码管显示相应的四位数,但是后来我发现按键只工作了一次就不在工作,后来发现时当中断发生后程序就死循环在display()函数里面了,怎么办?好像如果要用到动态扫描显示LED之后,中断执行一次后就死循环在动态扫描里面出不来了,大家有更好一点的方法吗?求教
程序:
/*
* main.c
*/
/********
程序功能:74hc595演示基本位选段选
入口参数:无
出口参数:P1.0 SHCLK P1.1 wei P1.2 duan P1.3 STCLK P1.4/P1.5/P1.6/P1.7为独立键盘的I/O口
*/
#include
#define uchar unsigned char
unsigned seg[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x00,0xff};//0~9,以及全亮很全灭的段选
void delay()
{
volatile float i=0;
for(i=0;i<30;i++){}
}
void display(uchar first,uchar second,uchar third,uchar fourth) //四位数的显示函数
{
unsigned char wei,duan;
unsigned int i;
WDTCTL = WDTPW + WDTHOLD; //关闭看看门狗
P1DIR |= 0x0f; // P1.0 ,P1.1 ,P1.2,p1.3输出
while(1) //动态扫描
{
//--------------------第1位LED-----------//
wei=0x10; //可更改
duan=seg[first]; //可更改
for(i=0;i<8;i++)
{
if((wei&0x80)==0x80)
P1OUT |=BIT1;
else
P1OUT &=~(BIT1);
wei<<=1;
if((duan&0x80)==0x80)
P1OUT |=BIT2;
else
P1OUT &=~(BIT2);
duan<<=1;
P1OUT |=BIT0;
P1OUT &=~(BIT0);
P1OUT &= ~(BIT3);
P1OUT |= BIT3;
P1OUT &= ~(BIT3);
//duan=0xff;
}
delay();
//----------------第2位LED ----------------//
wei=0x20; //可更改
duan=seg[second]; //可更改
for(i=0;i<8;i++)
{
if((wei&0x80)==0x80)
P1OUT |=BIT1;
else
P1OUT &=~(BIT1);
wei<<=1;
if((duan&0x80)==0x80)
P1OUT |=BIT2;
else
P1OUT &=~(BIT2);
duan<<=1;
P1OUT |=BIT0;
P1OUT &=~(BIT0);
P1OUT &= ~(BIT3);
P1OUT |= BIT3;
P1OUT &= ~(BIT3);
//duan=0xff;
}
delay();
//----------------第3位LED ----------------//
wei=0x40; //可更改
duan=seg[third]; //可更改
for(i=0;i<8;i++)
{
if((wei&0x80)==0x80)
P1OUT |=BIT1;
else
P1OUT &=~(BIT1);
wei<<=1;
if((duan&0x80)==0x80)
P1OUT |=BIT2;
else
P1OUT &=~(BIT2);
duan<<=1;
P1OUT |=BIT0;
P1OUT &=~(BIT0);
P1OUT &= ~(BIT3);
P1OUT |= BIT3;
P1OUT &= ~(BIT3);
//duan=0xff;
}
delay();
//----------------第4位LED ----------------//
wei=0x80; //可更改
duan=seg[fourth]; //可更改
for(i=0;i<8;i++)
{
if((wei&0x80)==0x80)
P1OUT |=BIT1;
else
P1OUT &=~(BIT1);
wei<<=1;
if((duan&0x80)==0x80)
P1OUT |=BIT2;
else
P1OUT &=~(BIT2);
duan<<=1;
P1OUT |=BIT0;
P1OUT &=~(BIT0);
P1OUT &= ~(BIT3);
P1OUT |= BIT3;
P1OUT &= ~(BIT3);
//duan=0xff;
}
delay();
}
}
void main()
{
//-----------------------I/O口中断-----------------------------//
WDTCTL = WDTPW+WDTHOLD;
P1DIR &= ~(BIT4+BIT5+BIT6+BIT7);
P1IES |= BIT4+BIT5+BIT6+BIT7;
P1IE |= BIT4+BIT5+BIT6+BIT7;
_EINT();
P1IFG=0;
return;
//while(1);
//PORT1_ISR();
}
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
unsigned int i;
unsigned char PushKey;
PushKey=P1IFG & (BIT4+BIT5+BIT6+BIT7);
for(i=0;i<1000;i++){};
while(1)
{
if((P1IN & PushKey) == PushKey)
{
P1IFG=0;return;
} else
{
if(PushKey & BIT4)
{
display(10,10,10,10);
}
if(PushKey & BIT5)
{
display(0,1,7,8);
}
if(PushKey & BIT6)
{
display(5,6,0,0);
}
if(PushKey & BIT7)
{
display(1,4,7,8);
}
P1IFG=0;
return;
}
}
}
|
|