Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1499210
  • 博文数量: 204
  • 博客积分: 4013
  • 博客等级: 中校
  • 技术积分: 4030
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-29 06:34
文章分类

全部博文(204)

文章存档

2012年(204)

分类: C/C++

2012-07-18 16:06:15

如果VDD或者VDDA电压高于或低于PVD设定阈值都产生中断,表现为每中断一次,LED1就亮变灭或者灭变亮。

点击(此处)折叠或打开

  1. /********************************************************************************
  2.   * @file PWR/PVD/main.c
  3.   * @author MCD Application Team
  4.   * @version V3.4.0
  5.   * @date 10/15/2010
  6.   * @brief Main program body.
  7.   ******************************************************************************/
  8. /* Includes ------------------------------------------------------------------*/
  9. #include "stm32f10x.h"
  10. #include "stm32_eval.h"

  11. void EXTI_Configuration(void);
  12. void NVIC_Configuration(void);

  13. /**
  14.   * @brief Main program.
  15.   * @param None
  16.   * @retval None
  17.   */
  18. int main(void)
  19. {
  20.   /*!< At this stage the microcontroller clock setting is already configured,
  21.        this is done through SystemInit() function which is called from startup
  22.        file (startup_stm32f10x_xx.s) before to branch to application main.
  23.        To reconfigure the default setting of SystemInit() function, refer to
  24.        system_stm32f10x.c file
  25.      */
  26.   /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */
  27.   STM_EVAL_LEDInit(LED1);
  28.   
  29.   GPIO_SetBits(GPIOC, GPIO_Pin_7);

  30.   /* Enable PWR and BKP clock */
  31.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);//电源管理部分时钟开启

  32.   /* Configure EXTI Line to generate an interrupt on falling edge */
  33.   EXTI_Configuration();

  34.   /* NVIC configuration */
  35.   NVIC_Configuration();
  36.  
  37.   /* Configure the PVD Level to 2.9V */
  38.   PWR_PVDLevelConfig(PWR_PVDLevel_2V9);// 设定监控阀值

  39.   /* Enable the PVD Output */
  40.   PWR_PVDCmd(ENABLE);// 使能PVD
  41.   
  42.   while (1)
  43.   {
  44.   }
  45. }

  46. /**
  47.   * @brief Configures EXTI Lines.
  48.   * @param None
  49.   * @retval None
  50.   */
  51. void EXTI_Configuration(void)
  52. {
  53.   EXTI_InitTypeDef EXTI_InitStructure;

  54.   /* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and
  55.      falling edges */
  56.   EXTI_ClearITPendingBit(EXTI_Line16);
  57.   EXTI_InitStructure.EXTI_Line = EXTI_Line16;// PVD连接到中断线16上
  58.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//使用中断模式
  59.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//电压上升或下降越过设定阀值时都产生中断。
  60.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;// 使能中断线
  61.   EXTI_Init(&EXTI_InitStructure);// 初始
  62. }

  63. /**
  64.   * @brief Configures NVIC and Vector Table base location.
  65.   * @param None
  66.   * @retval None
  67.   */
  68. void NVIC_Configuration(void)
  69. {
  70.   NVIC_InitTypeDef NVIC_InitStructure;
  71.   
  72.   /* Configure one bit for preemption priority */
  73.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//中断优先级配置
  74.   
  75.   /* Enable the PVD Interrupt */ //设置PVD中断
  76.   NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;
  77.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  78.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  79.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  80.   NVIC_Init(&NVIC_InitStructure);
  81. }
  82. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
注意:GPIO驱动LED模式为GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;还是推挽输出。
中断处理函数:
点击(此处)折叠或打开
  1. void PVD_IRQHandler(void)
  2. {
  3. if(EXTI_GetITStatus(EXTI_Line16) != RESET)
  4. {
  5. /* LED1翻转 */
  6. STM_EVAL_LEDToggle(LED1);
  7. /* Clear the Key Button EXTI line pending bit */
  8. EXTI_ClearITPendingBit(EXTI_Line16);
  9. }
  10. }

阅读(13896) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~