首页 > 代码库 > MSP430入门程序之(02)WDT(看门狗模式)
MSP430入门程序之(02)WDT(看门狗模式)
#include "in430.h"
#include "io430x14x.h"
//定义使用主频
#define CPU_F ((double)8000000)
//定义延时函数
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define _EINT() __enable_interrupt()
void wdt_init(void)
{
WDTCTL = WDTPW + WDTHOLD;//禁止看门狗
WDTCTL = WDT_ARST_1000;//设置看门狗
}
void clk_init(void)
{
unsigned char i;
BCSCTL1 &= ~XT2OFF;
do
{
IFG1 &= ~OFIFG;
for(i = 0xFF;i > 0;i--);
}while(IFG1 & OFIFG);
BCSCTL2 |= SELM_2;
DCOCTL |= DCO2 + DCO1 + DCO0;
}
void port_init(void)
{
P2DIR |= 0x01;
P2OUT |= 0x01;
P5DIR |= 0x70;
P5SEL = BIT4+BIT5+BIT6;
P4DIR |= 0xFF;
}
void init_devices(void)
{
wdt_init();
clk_init();
port_init();
}
void main( void )
{
init_devices();
//IE1 |= WDTIE;
P2OUT &= ~0x01;
delay_ms(50);
P2OUT |= 0x01;
//_EINT();
while(1)
{
delay_ms(200);
P2OUT &= ~0x01;
delay_ms(200);
P2OUT |= 0x01;
WDTCTL = WDTPW + WDTCNTCL + (WDTCTL & 0x00FF);
delay_ms(5000);
}
}
M1与M2间隔1s,为看门狗定时器复位时间;
四个低脉冲为P2.0拉低,窄脉冲为50ms,宽脉冲为200ms.
MSP430入门程序之(02)WDT(看门狗模式)