stm8s_iwdg(独立看门狗)

//内部时钟源128Khz,硬件2分频=64khz

这里写代码片
IWDG_Initializes();     //初始化
IWDG_ReloadCounter();   //喂狗(重载计数值)
初始化流程:
void IWDG_Initializes(void)
{
  IWDG_Enable();                                 //使能看门狗
  IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);  //允许写分频值和重载值
  IWDG_SetPrescaler(IWDG_Prescaler_256);         //分频值
  IWDG_SetReload(250);                           //重载值(8位寄存器 最大255)
  IWDG_ReloadCounter();                          //重载计数值
}

这里写代码片


函数体:
void IWDG_Enable(void)
{
  IWDG->KR = IWDG_KEY_ENABLE;//0xCC
}
void IWDG_WriteAccessCmd(IWDG_WriteAccess_TypeDef IWDG_WriteAccess)
{
  /* Check the parameters */
  assert_param(IS_IWDG_WRITEACCESS_MODE_OK(IWDG_WriteAccess));
  IWDG->KR = (uint8_t)IWDG_WriteAccess; /* Write Access 0x55 */
}
void IWDG_SetPrescaler(IWDG_Prescaler_TypeDef IWDG_Prescaler)
{
  /* Check the parameters */
  assert_param(IS_IWDG_PRESCALER_OK(IWDG_Prescaler));
  IWDG->PR = (uint8_t)IWDG_Prescaler;
}
void IWDG_SetReload(uint8_t IWDG_Reload)
{
  IWDG->RLR = IWDG_Reload;
}
void IWDG_ReloadCounter(void)
{
  IWDG->KR = IWDG_KEY_REFRESH;//0xAA
}
/** IWDG prescaler enumaration */
typedef enum
{
  IWDG_Prescaler_4   = (uint8_t)0x00, /*!< Used to set prescaler register to 4 */
  IWDG_Prescaler_8   = (uint8_t)0x01, /*!< Used to set prescaler register to 8 */
  IWDG_Prescaler_16  = (uint8_t)0x02, /*!< Used to set prescaler register to 16 */
  IWDG_Prescaler_32  = (uint8_t)0x03, /*!< Used to set prescaler register to 32 */
  IWDG_Prescaler_64  = (uint8_t)0x04, /*!< Used to set prescaler register to 64 */
  IWDG_Prescaler_128 = (uint8_t)0x05, /*!< Used to set prescaler register to 128 */
  IWDG_Prescaler_256 = (uint8_t)0x06  /*!< Used to set prescaler register to 256 */
} IWDG_Prescaler_TypeDef;

你可能感兴趣的:(stm8s_iwdg(独立看门狗))