关于STM32的可编程电压检测器的使用方法

关于STM32的可编程电压检测器的使用方法

思维导图总览:

关于STM32的可编程电压检测器的使用方法_第1张图片

代码:

  1 #include "sys.h"
  2 #include "delay.h"
  3 #include "usart.h"
  4 #include "led.h"
  5 #include "oled.h"
  6 #include "24cxx.h"
  7 #include "w25qxx.h" 
  8 
  9 #include "key.h"
 10 #include "adc.h"
 11 #include "npa.h"
 12 #include "bluetooth.h"
 13 #include "rtc.h"
 14 
 15 const u8 TEXT_Buffer[]={"SPI3 TEST"};
 16 
 17 const u8 AT_Buffer[]={"AT\n\r"};
 18 #define SIZE sizeof(TEXT_Buffer)    
 19 #define At_SIZE sizeof(AT_Buffer)    
 20     
 21 void PVD_Config(void);
 22 int main(void)
 23 { 
 24         PVD_Config();
 25     
 26     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
 27     delay_init(168);     //初始化延时函数
 28     //uart_init(115200);    //初始化串口波特率为115200
 29     //AT24CXX_Init();    
 30     LED_Init();                    //初始化LED
 31     oled_init();
 32     //W25QXX_Init();
 33     KEY_Init();
 34     //Adc_Init();
 35     //    NPAsensor_Bar_Init();
 36     LED_Init();
 37     LED0=1;
 38     //My_RTC_Init();                 //初始化RTC
 39     //RTC_Set_WakeUp(RTC_WakeUpClock_CK_SPRE_16bits,0);        //配置WAKE UP中断,1秒钟中断一次
 40 
 41     //BLUT_Init();
 42     //BLUT_SW=0;
 43 
 44 
 45     //oled_memery_clear(0x00);
 46     oled_display_chs((unsigned char *)"ok:",0,0,16,0);
 47     oled_display_refresh();
 48     
 49     
 50 
 51     
 52 
 53         while(1)
 54     {
 55         
 56         if(PWR_GetFlagStatus(PWR_FLAG_PVDO)==RESET)
 57         {
 58                 oled_display_chs((unsigned char *)"reset:",0,32,16,0);
 59             oled_display_refresh();
 60         }
 61         else
 62         {
 63                 oled_display_chs((unsigned char *)"set:",0,46,16,0);
 64             oled_display_refresh();
 65         }
 66     }
 67 }
 68 /**
 69 00083   * @brief  Configures the PVD resources.
 70 00084   * @param  None
 71 00085   * @retval None
 72 00086   */
 73 void PVD_Config(void)
 74 {
 75         NVIC_InitTypeDef NVIC_InitStructure;
 76         EXTI_InitTypeDef EXTI_InitStructure;
 77 
 78         /* Enable PWR clock */
 79         RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
 80 
 81         /* Configure one bit for preemption priority */
 82         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
 83 
 84         /* Enable the PVD Interrupt */
 85         NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;
 86         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 87         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 88         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 89         NVIC_Init(&NVIC_InitStructure);
 90         /* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and
 91         falling edges */
 92         EXTI_ClearITPendingBit(EXTI_Line16);
 93         EXTI_InitStructure.EXTI_Line = EXTI_Line16;
 94         EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
 95         EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//change  EXTI_Trigger_Rising_Falling
 96         EXTI_InitStructure.EXTI_LineCmd = ENABLE;
 97         EXTI_Init(&EXTI_InitStructure);
 98 
 99         /* Configure the PVD Level to 3 (PVD detection level set to 2.5V, refer to the
100         electrical characteristics of you device datasheet for more details) */
101         PWR_PVDLevelConfig(PWR_PVDLevel_5);
102 
103         /* Enable the PVD Output */
104         PWR_PVDCmd(ENABLE);
105 }
106  
107 /******************************************************************************/
108  /*                 STM32F4xx Peripherals Interrupt Handlers                   */
109  /*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
110  /*  available peripheral interrupt handler's name please refer to the startup */
111  /*  file (startup_stm32f40xx.s.startup_stm32f427x.s).                         */
112  /******************************************************************************/
113   
114  /**
115    * @brief  This function handles the PVD Output interrupt request.
116    * @param  None
117    * @retval None
118  */
119  void PVD_IRQHandler(void)
120  {
121    if(EXTI_GetITStatus(EXTI_Line16) != RESET)
122    {
123      /* Toggle LED1 */
124     // STM_EVAL_LEDToggle(LED1);
125          LED0=0;
126        oled_display_chs((unsigned char *)"low",0,16,16,0);
127          oled_display_refresh();
128          
129          
130          
131      /* Clear the Key Button EXTI line pending bit */
132      EXTI_ClearITPendingBit(EXTI_Line16);
133    }
134 }

来源自 STM32官方的帮助文档,这部分资料在帮助文档中都有,而且有代码

 

转载于:https://www.cnblogs.com/qdrs/p/9794945.html

你可能感兴趣的:(关于STM32的可编程电压检测器的使用方法)