河北水利局项目

This commit is contained in:
2025-12-15 16:07:49 +08:00
commit f11a7c2b95
1146 changed files with 452892 additions and 0 deletions

53
APP/wdg.c Normal file
View File

@@ -0,0 +1,53 @@
#include "wdg.h"
/*****************************************************************************
* Function : Iwdg_Init
* Description : none
* Input : u8 timeout 为以秒为单位的看门狗超时时间不得低于1s,看门狗定时器的数据不能超过u16的大小65536
* Output : None
* Return :
* Others :
* Record
* 1.Date : 20170412
* Author : barry
* Modification: Created function
*****************************************************************************/
void Iwdg_Init(u8 timeout)
{
#define WDG_PRE 256
#define WDG_PER_COUNT (40000/WDG_PRE)
#define IWDG_Prescaler IWDG_Prescaler_256
u8 max_timeout = 0xFFF / WDG_PER_COUNT;
u16 reloadCount = 0;
timeout = (timeout == 0)? 1:timeout;
timeout = (timeout >= max_timeout)? max_timeout: timeout;
reloadCount = timeout* WDG_PER_COUNT;
/* Check if the system has resumed from IWDG reset */
if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
{
RCC_ClearFlag();
}
/* IWDG timeout equal to 280 ms (the timeout may varies due to LSI frequency
dispersion) */
/* Enable write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz */
IWDG_SetPrescaler(IWDG_Prescaler);
/* Set counter reload value to 1250, 1s timeout */
IWDG_SetReload(reloadCount);
/* Reload IWDG counter */
IWDG_ReloadCounter();
/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
IWDG_Enable();
}