OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 8811|回复: 4

谁能帮我看看这个窗口看门狗的程序,谢谢

[复制链接]

3

主题

10

帖子

0

精华

新手上路

积分
42
金钱
42
注册时间
2012-6-27
在线时间
0 小时
发表于 2012-7-7 22:31:05 | 显示全部楼层 |阅读模式
#include "stm32f10x.h"
//#include "stm32_eval.h"
#include "stdio.h"

void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void EXTI_Configuration(void);
void USART_Configuration(void);
void WWDG_Configuration(void);

int fputc(int ch , FILE *f)
{
USART_SendData(USART1 , (u8) ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC) == RESET);
return ch;
}

int main(void)
{
 RCC_Configuration( );
NVIC_Configuration( );
GPIO_Configuration( );
EXTI_Configuration( );
  USART_Configuration( );
    WWDG_Configuration( );
printf("ready");
if(RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
  {
  printf("/n has been reset by wwdg");
RCC_ClearFlag();
  }
else
  {
   WWDG_Configuration();
printf("has been reset by wwdg before/n");
  }
  while(1);
}


void RCC_Configuration(void)
{
ErrorStatus  HSEStartUpStatus;
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PCLK2Config(RCC_HCLK_Div1);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1 , RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource() != 0x08);
}
}

void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//设置PA13管脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA , &GPIO_InitStructure);
//配置PA13为外部中断线
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA , GPIO_PinSource0);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA , &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA , &GPIO_InitStructure);
}

void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;

EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOA , GPIO_PinSource0); 
}

void WWDG_Configuration(void)
{
WWDG_SetPrescaler(WWDG_Prescaler_8);   //设置窗口看门狗频率36M/4096/8
    WWDG_Enable(0x7f);  //设置窗口看门狗计数器值
WWDG_ClearFlag();  //清除早期唤醒中断
WWDG_EnableIT();
// printf("2");
}

void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);


NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
 
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure);
}

void USART_Configuration(void)
{
USART_InitTypeDef  USART_InitStructure;
USART_ClockInitTypeDef  USART_ClockInitStructure;

USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART1 , &USART_ClockInitStructure);

USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1 , &USART_InitStructure);
USART_Cmd(USART1 , ENABLE);
}



void WWDG_IRQHandler(void)
{
WWDG_SetCounter(0x7f);
WWDG_SetWindowValue(0x50);
WWDG_ClearFlag();
printf("\n the wwdg has been flash");
}

void EXTI15_10_IRQHandler(void)
{
printf("da  duan WWDG");
while(1);
}






新建 WinRAR 压缩文件.rar

4.21 MB, 下载次数: 74

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

3

主题

10

帖子

0

精华

新手上路

积分
42
金钱
42
注册时间
2012-6-27
在线时间
0 小时
 楼主| 发表于 2012-7-7 22:32:58 | 显示全部楼层
我通过串口和KEY0看串口打印出的消息,现在打印不出,帮帮我
回复 支持 反对

使用道具 举报

3

主题

10

帖子

0

精华

新手上路

积分
42
金钱
42
注册时间
2012-6-27
在线时间
0 小时
 楼主| 发表于 2012-7-7 23:08:34 | 显示全部楼层
找到原因了少写了两句话


RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1 , ENABLE);
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165371
金钱
165371
注册时间
2010-12-1
在线时间
2110 小时
发表于 2012-7-8 01:00:08 | 显示全部楼层
自己解决了就好.
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

3

主题

10

帖子

0

精华

新手上路

积分
42
金钱
42
注册时间
2012-6-27
在线时间
0 小时
 楼主| 发表于 2012-7-8 09:27:41 | 显示全部楼层
嗯嗯,谢谢哈
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-26 14:13

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表