欢迎来到天天文库
浏览记录
ID:49770432
大小:15.83 KB
页数:4页
时间:2020-03-04
《STM32F401串口程序源码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Main.c#include"sys.h"#include"delay.h"#include"usart.h"#include"led.h"#include"beep.h"#include"key.h"intmain(void){u8t;u8len;u16times=0;NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);delay_init(168);uart_init(115200);LED_Init();while(1){if(USART_RX_STA&0x8000){len=USART_RX_STA&0x3fff;printf
2、("r输入字符为:r");for(t=0;t3、h"#include"usart.h"#ifSYSTEM_SUPPORT_OS#include"includes.h"#endif#if1#pragmaimport(__use_no_semihosting)struct__FILE{inthandle;};FILE__stdout;_sys_exit(intx){x=x;}intfputc(intch,FILE*f){while((USART1->SR&0X40)==0);USART1->DR=(u8)ch;returnch;}#endif#ifEN_USART1_RXu8USART_RX_BUF[USART_REC_LEN4、];u16USART_RX_STA=0;voiduart_init(u32bound){GPIO_InitTypeDefGPIO_InitStructure;USART_InitTypeDefUSART_InitStructure;NVIC_InitTypeDefNVIC_InitStructure;RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);GPIO_PinAFConfig(GPIOA,GPIO_PinSour5、ce9,GPIO_AF_USART1);GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);GPIO_InitStructure.GPIO_Pin=GPIO_Pin_96、GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd=GP7、IO_PuPd_UP;GPIO_Init(GPIOA,&GPIO_InitStructure);USART_InitStructure.USART_BaudRate=bound;USART_InitStructure.USART_WordLength=USART_WordLength_8b;USART_InitStructure.USART_StopBits=USART_StopBits_1;USART_InitStructure.USART_Parity=USART_Parity_No;USART_InitStructure.USART_HardwareFlowContro8、l=USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode=USART_Mode_Rx9、USART_Mode_Tx;USART_Init(USART1,&USART_InitStructure);USART_Cmd(USART1,ENABLE);//USART_ClearFlag(USART1,USART_FLAG_TC);#ifEN_USART1_RXUSART_ITConfig(USART1,USART_IT_RXNE,ENABLE
3、h"#include"usart.h"#ifSYSTEM_SUPPORT_OS#include"includes.h"#endif#if1#pragmaimport(__use_no_semihosting)struct__FILE{inthandle;};FILE__stdout;_sys_exit(intx){x=x;}intfputc(intch,FILE*f){while((USART1->SR&0X40)==0);USART1->DR=(u8)ch;returnch;}#endif#ifEN_USART1_RXu8USART_RX_BUF[USART_REC_LEN
4、];u16USART_RX_STA=0;voiduart_init(u32bound){GPIO_InitTypeDefGPIO_InitStructure;USART_InitTypeDefUSART_InitStructure;NVIC_InitTypeDefNVIC_InitStructure;RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);GPIO_PinAFConfig(GPIOA,GPIO_PinSour
5、ce9,GPIO_AF_USART1);GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9
6、GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd=GP
7、IO_PuPd_UP;GPIO_Init(GPIOA,&GPIO_InitStructure);USART_InitStructure.USART_BaudRate=bound;USART_InitStructure.USART_WordLength=USART_WordLength_8b;USART_InitStructure.USART_StopBits=USART_StopBits_1;USART_InitStructure.USART_Parity=USART_Parity_No;USART_InitStructure.USART_HardwareFlowContro
8、l=USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode=USART_Mode_Rx
9、USART_Mode_Tx;USART_Init(USART1,&USART_InitStructure);USART_Cmd(USART1,ENABLE);//USART_ClearFlag(USART1,USART_FLAG_TC);#ifEN_USART1_RXUSART_ITConfig(USART1,USART_IT_RXNE,ENABLE
此文档下载收益归作者所有