新手入门
- 积分
- 6
- 金钱
- 6
- 注册时间
- 2018-12-13
- 在线时间
- 1 小时
|
发表于 2022-5-9 21:37:44
|
显示全部楼层
#include "stm32f10x.h" void USART1_Init(void) { GPIO_InitTypeDef GPIO_InitStrue; USART_InitTypeDef USART_InitStrue; NVIC_InitTypeDef NVIC_InitStrue; //1¡¢ê1Äüê±Öó RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); /*2¡¢IO¿ú3õê¼»ˉ*/ //Pin_9 GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP; GPIO_InitStrue.GPIO_Pin=GPIO_Pin_9; GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz; GPIO_Init(GPIOA,&GPIO_InitStrue); //Pin_10 GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_InitStrue.GPIO_Pin=GPIO_Pin_10; GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz; GPIO_Init(GPIOA,&GPIO_InitStrue); /*3¡¢′®¿ú3õê¼»ˉ*/ USART_InitStrue.USART_BaudRate=9600; USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_InitStrue.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; USART_InitStrue.USART_Parity=USART_Parity_No; USART_InitStrue.USART_StopBits=USART_StopBits_1; USART_InitStrue.USART_WordLength=USART_WordLength_8b; USART_Init(USART1,&USART_InitStrue); USART_Cmd(USART1,ENABLE); USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//¿aÆô½óêÕÖD¶Ï NVIC_InitStrue.NVIC_IRQChannel=USART1_IRQn; NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE; NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStrue.NVIC_IRQChannelSubPriority=1; NVIC_Init(&NVIC_InitStrue); } void USART1_IRQHandler(void) { u8 Rev_Byte_data; if(USART_GetFlagStatus(USART1,USART_IT_RXNE)) { Rev_Byte_data=USART_ReceiveData(USART1); USART_SendData(USART1,Rev_Byte_data); } } int main(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); USART1_Init(); while(1); } |
|