MSP430單片機(jī)看門狗操作
intmain(void)
{
WDTCTL=WDTPW+WDTHOLD;//關(guān)看門狗
BCSCTL1=CALBC1_1MHz;//設(shè)定DCO為1MHZ
DCOCTL=CALBC1_1MHZ;
//選擇定時(shí)模式,并選時(shí)鐘源為ACLK,即定時(shí)時(shí)間為ACLK/32768(WDTISx=0)
WDTCTL=WDTPW+WDTTMSEL+WDTSSEL+WDTCNTCL;
P1OUT|=BIT0;//LED使能
P1DIR|=BIT0;
IE1|=WDTIE;//使能WDT定時(shí)中斷
_BIS_SR(GIE+LPM3_bits);//進(jìn)入LPM3模式,ACLK(WDT時(shí)鐘源)仍工作,并使能總中斷
return0;
}
#pragmavector=WDT_VECTOR//看門狗定時(shí)中斷服務(wù)
__interruptvoidwdt_timer(void)
{
P1OUT^=BIT0;//LED翻轉(zhuǎn)
}
/*********************************************************/
intmain(void)
{
BCSCTL1=CALBC1_1MHZ;//設(shè)定DCO為1MHZ
DCOCTL=CALBC1_1MHZ;
P1OUT&=~BIT0;//LED滅
P1DIR|=BIT0;
if(WDTIFG&IFG1)
{
P1OUT|=BIT0;//如果看門狗溢出LED亮
}
else
{
P1OUT&=~BIT0;
}
while(1);
return0;
}