现在想将程序加入看门狗功能,搞了半天也不明白该如何使用,小弟不才,希望能够获得大家指点
#include "msp430x14x.h"
#define UINT8 unsigned char
#define UINT16 unsigned int
#define False 0
#define True 1
UINT16 Timer_Counter = 0;
UINT8 Timer_Flag = False;
UINT8 Light_Start = False;
UINT8 Fun_Choose = False;
/***********时钟初始化函数***********/
void clk_init()
{
UINT8 i;
BCSCTL1&=~XT2OFF; //打开高频晶体振荡器
BCSCTL2|=SELM_2+SELS; //MCLK和SMCLK都选择XT2,8MHZ
do
{
IFG1&=~OFIFG; //清除振荡器失效标志
for(i=0xff;i>0;i--); //延迟待稳定
}
while((IFG1&OFIFG)!=0);
}
void GPIO_Init()
{
P1DIR &= ~BIT5;
P1OUT |= 0xFF;
P2DIR |= BIT6;
P2OUT &= 0x00;
P5DIR |= BIT4;
P5OUT &= ~BIT4;
}
/*****************TimerA_Init*******************/
void TimerA_Init()
{
TACTL|=TASSEL_2+MC0+TACLR+TAIE+ID_3;
CCTL0 = CCIE;
TACCR0=29999;
}
//******************************************************
//352微秒延时程序
void delay_352us(UINT16 i)//352us延时程序
{
UINT8 j;
while(i--)
{
for(j=0;j<255;j++)
{
_NOP();
_NOP();
_NOP();
_NOP();
}
}
}
/************************************************/
/* 主函数 */
/************************************************/
void main(void)
{
// WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
WDTCTL = WDTPW + WDTCNTCL;
P5DIR |= BIT4; // Set P5.4 to output direction
P5OUT ^= BIT4;
clk_init();
GPIO_Init();
TimerA_Init();
_EINT();
LPM0;
WDTCTL = WDTPW + WDTCNTCL;
}
/************定时器A中断函数******************/
#pragma vector=TIMERA0_VECTOR
__interrupt void timer0()
{
switch(TAIV)
{
case TAIV_TACCR1:break;
case TAIV_TACCR2:break;
case TAIV_TAIFG:
{
Timer_Counter++;
if(((P1IN & BIT5)>>5) == 1)
{
Fun_Choose = False;
}
else
{
Fun_Choose = True;
}
if(Fun_Choose == True)
{
if(Timer_Counter >= 11)
{
Timer_Flag = 0;
}
if(Timer_Counter >= 33)
{
Timer_Counter = 0;
Timer_Flag = 1;
}
if(Timer_Flag == True)
{
P2OUT |= BIT6;
P5OUT |= BIT4;
}
else
{
P2OUT &= ~BIT6;
P5OUT &= ~BIT4;
}
}
else
{
P5OUT |= BIT4;
P2OUT |= BIT6;
}
}
break;
}
}
此帖出自
小平头技术问答
一周热门 更多>