[Embedded system experiment] 5 independent watchdog experiment

1 Development environment

  • STM32F407ZGT6
  • Wedge uVision 5

2 Experiment content

  1. LED0 is on to indicate that the system is running. If the watchdog issues a reset, LED0 will go out (flashing).
  2. Press the external interrupt mode of KEY1 to feed the dog instead of query mode.
  3. Before the watchdog reset signal is generated, an audible and visual alarm is performed, that is, LED1 starts to flash about 1.5 seconds before the reset, and the buzzer beeps intermittently to remind the dog to feed.
  4. After pressing KEY1 to feed the dog, all alarm messages will be cancelled immediately.
  5. Long delays, such as delay_ms(1000), or disguised long delays, for loops, etc. are not allowed.
  6. Timers are not allowed.

3 Experimental code

[exti.c]

int flag=0;//喂狗标志

//外部中断3服务程序
void EXTI3_IRQHandler(void)
{
    
    
	delay_ms(10);	//消抖
	if(KEY1==0)	 
	{
    
    
		IWDG_Feed();
		BEEP=0;
		LED1=1;
		flag=1;
	}		 
	 EXTI_ClearITPendingBit(EXTI_Line3);  //清除LINE3上的中断标志位  
}

[main.c]

int main(void)
{
    
     
	u16 prer=4;					//分频系数,4*2^prer=64
	u16 rlr=500*5;				//计数重载值
	u16 count=0;				//计数变量
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	//设置系统中断优先级分组2
	delay_init(168);			//初始化延时函数
	LED_Init();					//初始化LED端口
	KEY_Init();					//初始化按键
	BEEP_Init();				//初始化蜂鸣器
	EXTIX_Init();				//初始化外部中断输入
	delay_ms(200);				//延时200ms 
	IWDG_Init(prer,rlr);		//分频系数为64,重载值为500时,溢出时间为1s
								//此实验设计溢出时间为1*5=5s
	LED0=0;						//先点亮红灯
	
	while(1){
    
    
		count++;
		if(!flag){
    
    				//当没有喂狗
			if(count>=380){
    
    		//程序大约还剩1.5s运行结束
				mywarning();	//喂狗报警提示
			}
		}
		else{
    
    					//当喂狗了
			count=0;			//重新计数
			flag=0;				//清除喂狗标志
		}
		delay_ms(10);			//小延时
	};

}

/*声光报警*/
void mywarning(void){
    
    
	LED1=!LED1;
	BEEP=!BEEP;
	delay_ms(100);
}

4 matters needing attention

After learning the timer, it can be realized by timer.

Guess you like

Origin blog.csdn.net/qq_44714521/article/details/108704695