初级会员
积分 94
金钱 94
注册时间 2015-8-1
在线时间 11 小时
10 金钱
#define portCase(sPort,x,y1,y2,y3,y4,y5) switch(sPort){\
case 1: \
x = y1; \
break; \
case 2: \
x = y2; \
break; \
case 3: \
x = y3; \
break; \
case 4: \
x = y4; \
break; \
case 5: \
x = y5; \
break; \
}
void comInit(uint8_t sPort){
USART_InitTypeDef USART_InitStructure;
USART_TypeDef* USARTx;
/* USART232 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
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;
portCase(sPort,USARTx,USART1,USART2,USART3,UART4,UART5);
/* Configure USART232 */
USART_Init(USARTx, &USART_InitStructure);
/* Enable USART232 Receive and Transmit interrupts */
USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE);
/* Enable the USART232 */
USART_Cmd(USARTx, ENABLE);
USART_ClearFlag(USARTx, USART_FLAG_TC);
}
怎么把USART1_IRQHandler,USART2_IRQHandler,USART3_IRQHandler,UART4_IRQHandler,UART5_IRQHandler函数也用一个部分搞定
我来回答