本帖最后由 手机早晚报 于 2016-9-30 22:54 编辑
[mw_shl_code=c,true]#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "adc.h"
#include "wwdg.h"
int main(void)
{
u16 adcx;
float temp;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168);
uart_init(115200);
LED_Init();
LCD_Init();
Adc_Init();
KEY_Init();
WWDG_Init(0x7f,0x50,WWDG_Prescaler_8);
POINT_COLOR=RED;
LCD_ShowString(30,50,200,16,16,"Explorer STM32F4");
LCD_ShowString(30,70,200,16,16,"ADC TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,110,200,16,16,"2014/5/6");
POINT_COLOR=BLUE;
LCD_ShowString(30,130,200,16,16,"ADC1_CH5_VAL:");
LCD_ShowString(30,150,200,16,16,"ADC1_CH5_VOL:0.000V");
SWITCH=1;
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_5,20);
LCD_ShowxNum(134,130,adcx,4,16,0);
temp=(float)adcx*(3.08/4096);
adcx=temp;
LCD_ShowxNum(134,150,adcx,1,16,0);
temp-=adcx;
temp*=1000;
LCD_ShowxNum(150,150,temp,3,16,0X80);
delay_ms(250);
}
}
[/mw_shl_code][mw_shl_code=c,true]#include "wwdg.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);
WWDG_SetWindowValue(wr);
WWDG_SetCounter(WWDG_CNT);
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();
}
[/mw_shl_code]
这个窗口看门狗, 在主函数中的wwdg初始化WWDG_Init(0x7f,0x50,WWDG_Prescaler_8);,,现在这个程序只有窗口值与T[6:0]>=计数器值时,才正常;只要窗口值比计数器值小,程序就不断复位, ,问题就在于wwdg初始化时:只要tr>wr,就不断重启;令tr<=wr,就不会重启
但是按照手册,0x40<tr<0x7f,0x40<wr<0x7f,两个并无大小的比较
这个工程是在原子的adc实验库函数工程里直接添加wwdg的文件
@ 正点原子 咱们的qq群管理员下载我的文件也找不出问题,
一周热门 更多>