Exemplo n.º 1
0
void WDT_init(void)
{
	IWDG_WriteAccessEnable();
	IWDG_SetPrescaler(IWDG_Prescaler_256);
	IWDG_SetReload(0xFFF);
	IWDG_Enable();
	IWDG_ReloadCounter();
}
Exemplo n.º 2
0
void main(void)
#endif
{
  /* Enables the HSI clock for PORTC */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTC, ENABLE);

  /* Configure all unused PORT pins to low power consumption */
  PORT_StructInit(&PORT_InitStructure);
  PORT_InitStructure.PORT_Pin = (PORT_Pin_All & ~(PORT_Pin_0));
  PORT_Init(MDR_PORTC, &PORT_InitStructure);

  /* Configure PORTC pin 0 for output to switch LEDs on/off */
  PORT_InitStructure.PORT_Pin   = PORT_Pin_0;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;

  PORT_Init(MDR_PORTC, &PORT_InitStructure);

  /* Enables the HSI clock for IWDG */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_IWDG,ENABLE);

  /* Enable IWDG */
  IWDG_Enable();

  /* Enables write access to IWDG_PR,IWDG_RLR registers */
  IWDG_WriteAccessEnable();

  /* Set IWDG Prescaler value */
  IWDG_SetPrescaler(IWDG_Prescaler_128);

  /* Wait when Prescaler Value was updated */
  while (IWDG_GetFlagStatus(IWDG_FLAG_PVU) != 1)
  {
  }

  /* Set IWDG Reload value */
  IWDG_SetReload(0xFFF);

  /* Infinite loop */
  while (1)
  {
    /* Load counter value and blink LED after delay */
    Delay(1000000);
    IWDG_ReloadCounter();
    BlinkLED1(1,30000);
  }
}