📄 target board code
字号:
/******************************
系统配置文件
******************************/
#include "config.h"
/*****GPIO口配置程序*****/
void GPIO_User_Init(void)
{
//GPIO参数初始化
GPIO_InitTypeDef GPIO_InitStructure;
//启动GPIO口时钟
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE );
//GPIO口复用时钟
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE );
//LED输出端口:推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//AD输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //管脚2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //AD模拟输出
GPIO_Init(GPIOA, &GPIO_InitStructure); //AD初始化
// 串口1端口配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //管脚9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure); //TX初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //管脚10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/*****串口配置函数*****/
void USART_User_Init(void) //串口初始化函数
{
USART_InitTypeDef USART_InitStructure; //串口参数初始化
//UART 总线时钟配置
//RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1, ENABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2 , ENABLE );
//RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2 | RCC_APB1Periph_USART3 , ENABLE );
USART_InitStructure.USART_BaudRate = 115200; //波特率115200
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //字长8位
USART_InitStructure.USART_StopBits = USART_StopBits_1; //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;//打开Rx接收和Tx发送功能
USART_Init(USART2, &USART_InitStructure); //串口2初始化参数载入
//串口中断表示使能
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //串口2接收中断标志使能
//串口功能使能
USART_Cmd(USART2, ENABLE); //启动串口2
}
/*****中断配置函数*****/
void NVIC_User_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure; //中断参数初始化
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //通道设置为串口1中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //中断占先等级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //中断响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //打开中断
NVIC_Init(&NVIC_InitStructure);
}
/*****ADC配置*****/
void ADC_User_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_55Cycles5);
ADC_Cmd(ADC1, ENABLE);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
/*****片上外设初始化*****/
void initOnChipHal(void)
{
GPIO_User_Init(); //IO口初始化
USART_User_Init(); //串口初始化
NVIC_User_Init(); //中断配置初始化
ADC_User_Init(); //ADC初始化
LED_REC_OFF();
}
/*****片外设备初始化*****/
void initOffChipHal(void)
{
;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -