思路:
初始化——变量i(每中断一次i加一)——选择输出——循环
代码:
#include <msp430g2553.h>
unsigned char i=3;
void main(void)
{
WDTCTL = WDTPW+WDTHOLD;// Stop WDT
P1DIR |= BIT7+BIT6+BIT5+BIT4 ;
P2DIR = 0x0f;
P1OUT |= BIT3;
P1REN |= BIT3;
P1IES |= BIT3; // P1.3 IFG cleared
P1IE |= BIT3; // P1.3 interrupt enabled
P1IFG &= ~BIT3;
_BIS_SR(LPM1_bits + GIE);
while(1)
{i=i%6;
switch (i)
{
case 1:
P1OUT = 0x00;
P2OUT = 0x00;
break ;
case 2:
P1OUT = 0x00;
P2OUT = 0x03;
break ;
case 3:
P1OUT = 0x00;
P2OUT = 0x08;
break ;
case 4:
P1OUT = 0x10;
P2OUT = 0x0e;
break ;
case 5:
P1OUT = 0x50;
P2OUT = 0x00;
break;
case 6:P1OUT = 0xf0;
P2OUT = 0x0f;
break ;
}
}
}
//P1 output
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
if ((P1IN&BIT3)==0)
{_delay_cycles(5000);
if ((P1IN&BIT3)==0)
i++;
P1IFG &= ~BIT3;
// P1.3 IFG cleared
}
问题:
调试时加断点显示可以进入中断,但是i却不进行加1,在板子上运行,每个输出口都加led灯,按键不会改变灯的亮灭
请教 这是什么问题?