PWC — 电源电压监控
固件库: AT32F403A_407_Firmware_Library V2.2.2
芯片: AT32
源文件: AT32/AT32F403A_407_Firmware_Library_V2.2.2/project/at_start_f403a/examples/pwc/power_voltage_monitor/src/main.c
功能简介
本示例演示电源控制功能,实现不同的低功耗模式。低功耗设计是电池供电产品的核心技术。
完整代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include "at32f403a_407_board.h"
#include "at32f403a_407_clock.h"
void pvm_exint_config(void)
{
exint_init_type exint_init_struct;
/* config the exint line of the power voltage monitor */
exint_init_struct.line_select = EXINT_LINE_16;
exint_init_struct.line_enable = TRUE;
exint_init_struct.line_mode = EXINT_LINE_INTERRUPT;
exint_init_struct.line_polarity = EXINT_TRIGGER_BOTH_EDGE;
exint_init(&exint_init_struct);
}
int main(void)
{
__IO uint32_t index = 0;
/* congfig the system clock */
system_clock_config();
/* init at start board */
at32_board_init();
/* config priority group */
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
/* turn on the led light */
at32_led_on(LED2);
at32_led_on(LED3);
at32_led_on(LED4);
/* enable pwc clock */
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
/* set the threshold voltage to 2.9v */
pwc_pvm_level_select(PWC_PVM_VOLTAGE_2V9);
/* enable power voltage monitor */
pwc_power_voltage_monitor_enable(TRUE);
/* config the exint line of the power voltage monitor */
pvm_exint_config();
/* enable power voltage monitor interrupt */
nvic_irq_enable(PVM_IRQn, 0, 0);
while(1)
{
}
}
|
代码讲解
系统时钟初始化:配置 MCU 的主频和时钟树。不同芯片的时钟配置不同,一般由工具生成。
板级初始化:初始化开发板上的 LED、按键等基础外设。
中断优先级配置:NVIC 设置中断的抢占优先级和子优先级。数字越小优先级越高。