admin 管理员组

文章数量: 887021


2024年1月26日发(作者:div溢出隐藏)

void usart_init(u32 bound){ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);

GPIO__Mode=GPIO_Mode_AF_PP; GPIO__Pin=GPIO_Pin_9; GPIO__Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO__Mode=GPIO_Mode_IN_FLOATING; GPIO__Pin=GPIO_Pin_2; GPIO__Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure);

USART__BaudRate=bound; USART__HardwareFlowControl=USART_HardwareFlowControl_None; USART__Mode=USART_Mode_Rx|USART_Mode_Tx; USART__Parity=USART_Parity_No; USART__StopBits=USART_StopBits_1; USART__WordLength=USART_WordLength_8b; USART_Init(USART1,&USART_InitStructure);

NVIC__IRQChannel=USART1_IRQn; NVIC__IRQChannelCmd=ENABLE; NVIC__IRQChannelPreemptionPriority=3; NVIC__IRQChannelSubPriority=3; NVIC_Init(&NVIC_InitStructure);

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_Cmd(USART1, ENABLE);

}void USART1_IRQHandler(void){ if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { uint8_t res; res=(uint8_t)USART_ReceiveData(USART1); if(USART_RX_STA>=len) { USART_RX_STA=len;

return; } bufff[USART_RX_STA++]=res; } else if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) { ; }}


本文标签: 隐藏 溢出 作者