2019-07-20 11:42发布
liuliupiaoxue 发表于 2017-10-7 10:08 看起来是实验现象不对啊,你把main里的LED1=1搞错了吧,原程序是LED0=1
烟酒不沾 发表于 2017-10-7 11:00 还说一模一样,估计看门狗启作用了,就是实验现象看不见了,
最多设置5个标签!
#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]
还说一模一样,估计看门狗启作用了,就是实验现象看不见了,
看门狗起作用的话电平会翻转才对
一周热门 更多>