#include "system.h" #include "app_demo.h" int main() { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //添加中断优先级分组 分2组 RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); //设置系统时钟为内部高速晶振 appdemo_show();//调用函数 while(1) { } }
时间: 2023-07-14 10:13:00 浏览: 104
这段代码是一个简单的嵌入式系统的主函数,主要包括以下几个步骤:
1. 配置中断优先级分组,这里设置为分成2组。
2. 设置系统时钟为内部高速晶振。
3. 调用一个名为appdemo_show()的函数,可能是用来展示某个应用程序的界面或者功能。
4. 进入一个死循环,等待系统运行。
需要注意的是,这段代码可能只是整个系统的一部分,还需要其他代码和硬件驱动才能正常工作。
相关问题
#include "delay.h" #include "sys.h" #include "oled.h" #include "bmp.h" #include "pwm.h" #include "stm32f10x_tim.h" #include "adc.h" #include "irq.h" #include "pid.h" #include "key.h" #include "dht11.h" #include "usart.h" //#include "dht11.h" int wendu=0,shidu=0; int yewei=0; int time=0; int Accelerated=0; int Accelerated_z=0; int Accelerated_x=0; int main(void) { //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //IRQ_INT(999,79);//Öжϳõʼ»¯ 500ms 7199·ÖƵ key_init(); uart_init(9600); //´®¿Ú³õʼ»¯Îª9600 delay_init(); Adc_Init(); while(1) { //ADCÉèÖúà Accelerated=Get_Adc(6); Accelerated_z=Accelerated/256; Accelerated_x=Accelerated-Accelerated_z; delay_ms(10); USART_SendData(USART1,Accelerated_z); delay_ms(10); USART_SendData(USART1,Accelerated_x); }解释一下这个程序并在每一行加上备注
程序主要实现了读取ADC值,并通过串口发送到上位机。下面是每一行的注释:
```
#include "delay.h"
#include "sys.h"
#include "oled.h"
#include "bmp.h"
#include "pwm.h"
#include "stm32f10x_tim.h"
#include "adc.h"
#include "irq.h"
#include "pid.h"
#include "key.h"
#include "dht11.h"
#include "usart.h"
int wendu=0,shidu=0; //定义温度湿度变量
int yewei=0; //定义液位变量
int time=0; //定义时间变量
int Accelerated=0; //定义加速度变量
int Accelerated_z=0; //定义加速度Z轴变量
int Accelerated_x=0; //定义加速度X轴变量
int main(void) {
key_init(); //按键初始化
uart_init(9600); //串口初始化为9600波特率
delay_init(); //延时函数初始化
Adc_Init(); //ADC初始化
while(1) {
Accelerated=Get_Adc(6); //读取ADC6通道的值
Accelerated_z=Accelerated/256; //计算Z轴加速度
Accelerated_x=Accelerated-Accelerated_z; //计算X轴加速度
delay_ms(10); //延时10ms
USART_SendData(USART1,Accelerated_z); //通过串口发送Z轴加速度值
delay_ms(10); //延时10ms
USART_SendData(USART1,Accelerated_x); //通过串口发送X轴加速度值
}
}
```
这个程序主要是读取ADC的值,并通过串口发送到上位机。其中,加速度传感器的输出值被连接到了ADC6通道,计算Z轴和X轴加速度的方法是将ADC值除以256和取余。通过USART_SendData函数将数据发送到串口1,以便上位机读取。
#include <nvic.h> void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); /* Enable the USARTy Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
这是一个配置STM32F4微控制器中NVIC(Nested Vectored Interrupt Controller)的函数。在STM32F4中,NVIC用于管理中断,并且可以配置中断优先级。在这个函数中,首先通过调用NVIC_PriorityGroupConfig函数配置NVIC的优先级分组,然后通过配置NVIC_InitStructure结构体中的各个参数来初始化NVIC。在这个函数中,配置了USART1_IRQn和TIM3_IRQn两个中断的优先级和使能状态。USART1_IRQn用于USART1串口通信的中断处理函数,而TIM3_IRQn用于定时器3的中断处理函数。配置NVIC后,就可以启用这两个中断,并且可以在中断处理函数中进行相应的操作。
阅读全文
相关推荐

















