|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#include "wwdg.h"
#include "led.h"
//±£´æWWDG¼ÆÊýÆ÷µÄÉèÖÃÖµ,ĬÈÏΪ×î´ó.
u8 WWDG_CNT=0x7f;
void WWDG_Init(u8 tr,u8 wr,u32 fprer)//tr:¼ÆËãÆ÷Öµ£¬wr:´°¿ÚÖµ£¬fprer:·ÖƵϵÊý(WDGTB)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); // WWDGʱÖÓʹÄÜ
WWDG_CNT=tr&WWDG_CNT;//³õʼ»¯WWDG_CNT
WWDG_SetPrescaler(fprer);////ÉèÖÃIWDGÔ¤·ÖƵֵ
WWDG_SetWindowValue(wr);//ÉèÖô°¿ÚÖµ
WWDG_Enable(tr); //ʹÄÜ¿´ÃŹ· , ÉèÖà counter .
WWDG_ClearFlag();//Çå³ýÌáÇ°»½ÐÑÖжϱê־λ
WWDG_NVIC_Init();//³õʼ»¯´°¿Ú¿´ÃŹ· NVIC
WWDG_EnableIT(); //¿ªÆô´°¿Ú¿´ÃŹ·ÖжÏ
}
//ÖØÉèÖÃWWDG¼ÆÊýÆ÷µÄÖµ
void WWDG_Set_Counter(u8 cnt)
{
WWDG_Enable(cnt);
}
//´°¿Ú¿´ÃŹ·ÖжϷþÎñ³ÌÐò
void WWDG_NVIC_Init()
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn; //WWDGÖжÏ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //ÇÀÕ¼2£¬×ÓÓÅÏȼ¶3£¬×é2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //ÇÀÕ¼2£¬×ÓÓÅÏȼ¶3£¬×é2
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);//NVIC³õʼ»¯
}
void WWDG_IRQHandler(void)
{
// Update WWDG counter
WWDG_SetCounter(WWDG_CNT); //µ±½ûµô´Ë¾äºó,´°¿Ú¿´ÃŹ·½«²úÉú¸´Î»
// Clear EWI flag */
WWDG_ClearFlag(); //Çå³ýÌáÇ°»½ÐÑÖжϱê־λ
// Toggle GPIO_Led pin 7 */
LED1=!LED1;//LED״̬·×ª
}
#ifndef __WDG_H
#define __WDG_H
#include "sys.h"
void WWDG_Init(u8 tr,u8 wr,u32 fprer);//³õʼ»¯WWDG
void WWDG_Set_Counter(u8 cnt); //ÉèÖÃWWDGµÄ¼ÆÊýÆ÷
void WWDG_NVIC_Init(void);
#endif
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "wwdg.h"
int main(void)
{
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// ÉèÖÃÖжÏÓÅÏȼ¶·Ö×é2
uart_init(9600);
LED_Init();
LED0=0;
delay_ms(300);
WWDG_Init(0X7F,0X5F,WWDG_Prescaler_8);
while(1)
{
LED0=1;
}
} |
|