新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > STM32窗口看門狗程序

STM32窗口看門狗程序

作者: 時間:2016-11-30 來源:網(wǎng)絡 收藏


軟件例程:

//---------------------------wdg.c-----------------------

#include "wdg.h"
#include "led.h"

u8 wwdg_cnt=0x7f; //窗口看門狗計數(shù)器初值

void wwdg_init(u8 tr,u8 wr,u8 fprer)
{
RCC->APB1ENR|=1<<11; //使能WWDG時鐘
wwdg_cnt=tr&wwdg_cnt; // 初始化計數(shù)器值
WWDG->CFR|=fprer<<7; //設置頻率時基
WWDG->CFR|=1<<9; //使能串口看門狗中斷
WWDG->CFR&=0xff80; //窗口值清零
WWDG->CFR|=wr; //設定窗口值
WWDG->CR|=(wwdg_cnt|1<<7); // 啟動看門狗設置7位計數(shù)器初值
MY_NVIC_Init(2,3,WWDG_IRQChannel,2);

}

void wwdg_feed(u8 cnt)
{
WWDG->CR|=(cnt&0x7f); //喂狗值

}


void WWDG_IRQHandler(void)
{
u8 tr,wr;
wr=WWDG->CFR&0x7f;
tr=WWDG->CR&0x7f;
if(tr
WWDG->SR&=0x00; //清楚提前喚醒標志位
LED1=!LED1;
}


//------------------------wdg.h---------------------
#ifndef _wdg_h
#define _wdg_h

#include "sys.h"

void wwdg_init(u8 tr,u8 wr,u8 fprer);
void wwdg_feed(u8 cnt);

#endif
//------------------led.c----------------------
#include "led.h"

void led_init(void)
{
RCC->APB2ENR|=1<<2;
RCC->APB2ENR|=1<<5;
GPIOA->CRH&=0xfffffff0;
GPIOA->CRH|=0x00000003;
GPIOD->CRL&=0xfffff0ff;
GPIOD->CRL|=0x00000300;
GPIOA->ODR|=1<<8;
GPIOD->ODR|=1<<2;

}
//---------------------led.h------------------
#ifndef _led_h
#define _led_h

#include "sys.h"

#define LED0 PAout(8)
#define LED1 PDout(2)

void led_init(void);

#endif

///-----------------------主函數(shù)------------test.c---------------
#include

#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "wdg.h"

int main(void)
{
Stm32_Clock_Init(9);
delay_init(72);
uart_init(72,9600);
led_init();
wwdg_init(0x7f,0x5f,3);
LED0=0;
delay_ms(1800);
while(1)
{
LED0=1;

}

}


上一頁 1 2 下一頁

關鍵詞: STM32窗口看門

評論


技術專區(qū)

關閉