This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
我的目的是初始状态LED1,LED2 均熄灭,第一次按下按键,LED1 点亮,第二
次按下按键,LED1 熄灭,LED2 点亮,第三次按下按键,LED1,LED2 均熄灭,
第四次按下按键,LED1,LED2 持续亮灭闪烁。
程序如下:
#include"msp430.h" //包含头文件,系统自动匹配对应芯片的头文件
void delay(unsigned int i) //延时子函数
{
unsigned int j;
for(j=0;j<i;j++);
}
void main(void)
{
int n=0;
WDTCTL=WDTPW+WDTHOLD; //关看门狗
P1DIR|=BIT0; //P1.0 作输出口
P1DIR|=BIT6; //p1.6作输出口
P1DIR&=~BIT3; //P1.3 作输入口
P1REN|=BIT3; //P1.3 上/下拉电阻使能
P1OUT&=~BIT0;
P1OUT&=~BIT6;
while(1)
{
if((P1IN&0x08)==0)
{
delay(500);
if((P1IN&0x08)==0)
{
while((P1IN&0x08)==0);
n++;
switch (n)
{
case 1:
{
P1OUT|=0x01;
break;
}
case 2:
{
P1OUT^=BIT0+BIT6;
break;
}
case 3:
{
P1OUT&=0xbe;
break;
}
case 4:
{
while(1)
{
P1OUT^=BIT0|BIT6;
__delay_cycles(1000000);
n=0;
break;
}
}
}
}
}
}
}
请大神帮忙看看错在哪里了,本人新手。。。
#include"msp430.h" //包含头文件,系统自动匹配对应芯片的头文件 int n = 3; void main(void) { WDTCTL = WDTPW+WDTHOLD; //关看门狗 P1DIR |= BIT0; //P1.0 作输出口 P1DIR |= BIT6; //p1.6作输出口 P1OUT &= ~BIT0; P1OUT &= ~BIT6; P1IE |= BIT3; // P1.3 interrupt enabled P1IES |= BIT3; // P1.3 Hi/lo edge P1REN |= BIT3; // Enable Pull Up on SW2 (P1.3) P1IFG &= ~BIT3; // P1.3 IFG cleared __bis_SR_register(LPM3_bits + GIE); while(1) { switch (n) { case 0: { P1OUT |= BIT0; P1OUT &= ~BIT6; break; } case 1: { P1OUT |= BIT6; P1OUT &= ~BIT0; break; } case 2: { P1OUT &= ~(BIT0 + BIT6); break; } case 3: { P1OUT ^= BIT0|BIT6; __delay_cycles(1000000); break; } } } } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { unsigned int i; unsigned char PushKey; PushKey = P1IFG & BIT3; for(i=3000;i>0;i--) { __no_operation(); } if((P1IN & PushKey)==PushKey) { P1IFG = 0; return; } if(PushKey & BIT3) { n++; if(n == 4) n = 0; __bic_SR_register_on_exit(LPM3_bits); } P1IFG &= ~BIT3; // P1.3 IFG cleared }