int main( void )
{
WDTCTL=WDTPW+WDTHOLD; //关看门狗
BCSCTL1 =CALBC1_1MHz; //设定DCO 为1MHZ
DCOCTL =CALBC1_1MHZ;
//选择定时模式,并选时钟源为ACLK,即定时时间为ACLK/32768(WDTISx=0)
WDTCTL=WDTPW+WDTTMSEL+WDTSSEL+WDTCNTCL;
P1OUT |=BIT0; //LED 使能
P1DIR |=BIT0;
IE1 |=WDTIE; //使能WDT 定时中断
_BIS_SR(GIE+LPM3_bits); //进入LPM3 模式,ACLK(WDT 时钟源)仍工作,并使能总中断
return 0;
}
#pragma vector=WDT_VECTOR //看门狗定时中断服务
__interrupt void wdt_timer(void)
{
P1OUT ^=BIT0; //LED 翻转
}
/*********************************************************/
int main( void )
{
BCSCTL1 =CALBC1_1MHZ; //设定DCO为1MHZ
DCOCTL =CALBC1_1MHZ;
P1OUT &=~BIT0; //LED 灭
P1DIR |=BIT0;
if(WDTIFG&IFG1)
{
P1OUT |=BIT0; //如果看门狗溢出LED亮
}
else
{
P1OUT &=~BIT0;
}
while(1);
return 0;
}
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』