//--------------------------- Variable --------------------------//
unsigned long int time_delay = 0;
//--------------------- Function Prototype ----------------------//
static void delay(unsigned long int ms);
//--------------------------- Function --------------------------//
/*
* Name : main
* Description : ---
* Author : ysloveivy.
*
* History
* --------------------
* Rev : 0.00
* Date : 11/21/2015
*
* create.
* --------------------
*/
int main(void)
{
int i;
for(i = 0;i < 10000000;i++);
led.initialize();
key.initialize();
systick.initialize();
wwdg.initialize();
LED_RED_ON;
while(1){
while(!KEY_INPUT);
delay(30); //30ms喂狗
wwdg.feed_dog();
}
}
/*
* Name : delay
* Description : ---
* Author : ysloveivy.
*
* History
* --------------------
* Rev : 0.00
* Date : 11/21/2015
*
* create.
* --------------------
*/
static void delay(unsigned long int ms)
{
time_delay = ms;
while(time_delay != 0);
}
/*
* Name : initialize
* Description : ---
* Author : ysloveivy.
*
* History
* -------------------
* Rev : 0.00
* Date : 11/21/2015
*
* create.
* -------------------
*/
static int initialize(void)
{
//21.06ms 49.9ms之间喂狗
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); //使能窗口看门狗时钟
WWDG_SetPrescaler(WWDG_Prescaler_8); //设置预分频值
WWDG_SetWindowValue(100); //设置窗口值
WWDG_Enable(127); //设置计数器初值,并使能窗口看门狗
return 0;
}
/*
* Name : feed_dog
* Description : ---
* Author : ysloveivy.
*
* History
* -------------------
* Rev : 0.00
* Date : 11/21/2015
*
* create.
* -------------------
*/
static void feed_dog(void)
{
WWDG_SetCounter(127); //重置计数器,喂狗
}
/*
* Name : SysTick_Handler
* Description : ---
* Author : ysloveivy.
*
* History
* -------------------
* Rev : 0.00
* Date : 11/21/2015
*
* create.
* -------------------
*/
void SysTick_Handler(void)
{
static int counter = 0;
if((counter ++ % 1000) == 0){
systick.second_flag = 1;
}
time_delay --;
}
更多回帖