LunchPad MCU MSP430G2452 写了段程序学习,IAR 6.5版本,用看门狗中时间中断, 中断始终没有触发,是否可以帮忙看一下,谢谢
程序如下
#include "io430.h"
#include "io430g2452.h"
unsigned char const led_tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共阴数码管编码表
void Delay(int t)
{
int i;
while (t--)
for(i=500;i>0;i--);
}
int main( void )
{
int p;
p=0;
WDTCTL = WDT_ADLY_16;// 设置内部看门狗工作在定时器模式,1.6ms中断
IE1|= WDTIE; // 使能看门狗中断
P1SEL = 0X00;
P1DIR |= 0xFF; //定义P1为输出方向,端口1用来驱动LED共阴极数码管
P1OUT = 0x00; //定义P1输出为 0 ,
P2OUT =0xF7;
P2DIR |=(BIT0+BIT1+BIT2+BIT3+BIT5+BIT6+BIT7);
P2DIR &= ~BIT4; //先把BIT3 取反后和P1DIR与 P1DIR=PIDIR & ~BIT3
while(1)
{
p++;
if (p>=15000) p=0;
}
}
#pragma vector = WDT_VECTOR
__interrupt void Watchdog_timer(void)
{
int n;
for(n=0;n<10;n++)
P1OUT=led_tab[n];
Delay(600);
if(n>=9) P2OUT =0xF3;
Delay(600);
}
你可能是没开全局中断,另外,你的中断函数的for循环没加大括号,可能得不到你想要的结果。
- #include <msp430.h>
- int main(void)
- {
- WDTCTL = WDT_MDLY_32; // Set Watchdog Timer interval to ~30ms
- IE1 |= WDTIE; // Enable WDT interrupt
-
- /* Initialization Code */
- P1REN = 0x1B; // Terminate unavailable Port1 pins (P1.0/1/3/4) properly
- // Config as Input with pull-down enabled
- BCSCTL3 |= LFXT1S_2; // Select VLO as low freq clock
- /* End Initialization Code */
-
- P1DIR |= BIT2; // Set P1.2 to output direction
- __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
- }
- // Watchdog Timer interrupt service routine
- #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
- #pragma vector=WDT_VECTOR
- __interrupt void watchdog_timer(void)
- #elif defined(__GNUC__)
- void __attribute__ ((interrupt(WDT_VECTOR))) watchdog_timer (void)
- #else
- #error Compiler not supported!
- #endif
- {
- P1OUT ^= BIT2; // Toggle P1.2 using exclusive-OR
- }
新手入门,每天努力中
版主,还有个问题就是程序上电后程序无法运行,除非在IAR中用StepIn 单步走到中断后,中断就会运行.