写一个STM32F103C8T6的中断初始化模块化函数
时间: 2023-05-13 14:05:33 浏览: 87
好的,以下是一个简单的STM32F103C8T6中断初始化模块化函数的示例代码:
```c
#include "stm32f10x.h"
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USART1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART1_IRQHandler(void)
{
/* Handle USART1 interrupt */
}
int main(void)
{
/* Initialize USART1 */
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_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;
USART_Init(USART1, &USART_InitStructure);
/* Enable USART1 interrupt */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
/* Configure NVIC */
NVIC_Configuration();
/* Start USART1 */
USART_Cmd(USART1, ENABLE);
while (1)
{
/* Do something */
}
}
```
这个函数初始化了USART1的中断,并配置了NVIC。在这个示例中,当USART1接收到数据时,会触发USART1_IRQHandler()函数。
阅读全文