| 
 
初级会员 
 
	积分151金钱151 注册时间2017-7-19在线时间31 小时 | 
 
 
 楼主|
发表于 2017-10-7 09:55:15
|
显示全部楼层 
| [mw_shl_code=c,true]#include "delay.h" #include "led.h"
 #include "wwdg.h"
 
 int main(void)
 {
 
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
 delay_init(168);
 LED_Init();
 
 LED0 = 0;
 delay_ms(300);
 WWDG_Init(0x7F,0x5F,WWDG_Prescaler_8);
 while(1)
 {
 LED1 = 1;
 }
 }
 
 #ifndef __WWDG_H_
 #define __WWDG_H_
 #include "sys.h"
 
 void WWDG_Init(u8 tr, u8 wr, u32 fprer);
 
 #endif
 
 #include "wwdg.h"
 #include "led.h"
 #include "delay.h"
 u8 WWDG_CNT=0x7F;
 
 void WWDG_Init(u8 tr, u8 wr, u32 fprer)                //计数器值,上限窗口值,分频系数
 {
 NVIC_InitTypeDef        NVIC_InitStructure;
 
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG,ENABLE);
 
 WWDG_CNT = tr&WWDG_CNT;
 WWDG_SetPrescaler(fprer);//        <0x7F
 WWDG_SetWindowValue(wr);
 WWDG_Enable(WWDG_CNT);
 
 NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 
 NVIC_Init(&NVIC_InitStructure);
 
 WWDG_ClearFlag();                //清除一下中断标志位
 
 WWDG_EnableIT();                //开启以前唤醒中断
 }
 
 void WWDG_IRQHandler(void)
 {
 WWDG_SetCounter(WWDG_CNT);
 WWDG_ClearFlag();                //清除中断
 //        LED0 = !LED0;
 //        delay_ms(5);
 LED1 = !LED1;
 //        delay_ms(5);
 }
 
 
 #ifndef __LED_H_
 #define __LED_H_
 #include "sys.h"
 
 #define LED0 PFout(9)
 #define LED1 PFout(10)
 
 void LED_Init(void);
 
 #endif
 
 
 #include "led.h"
 
 void LED_Init(void)
 {
 GPIO_InitTypeDef        GPIO_InitStructure;
 
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
 
 GPIO_Init(GPIOF,&GPIO_InitStructure);
 
 GPIO_SetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);
 
 }
 
 
 
 [/mw_shl_code]
 | 
 |