第四个实验 串口 查询实验
来源:互联网 发布:平板软件下载 编辑:程序博客网 时间:2024/05/16 14:30
#include "stm32f10x.h"
#include <stdio.h>
#include <stdio.h>
int main(void)
{
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure; //定义串口初始化结构体
RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA,ENABLE);
USART_InitTypeDef USART_InitStructure; //定义串口初始化结构体
RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA,ENABLE);
/*USART1_TX ->PA9*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //选中串口默认输出管脚
//复用推挽输出模式
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //定义输出最大速率
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//定义管脚9的模式
GPIO_Init(GPIOA , &GPIO_InitStructure); //调用函数,把结构体参数输入进行初始化
/*USART1_RX ->PA10*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
//浮空输入模式
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA , &GPIO_InitStructure);
/*串口通讯参数设置*/
USART_InitStructure.USART_BaudRate = 9600; //波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据位8位
USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位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; //使能接收和发送引脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //选中串口默认输出管脚
//复用推挽输出模式
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //定义输出最大速率
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//定义管脚9的模式
GPIO_Init(GPIOA , &GPIO_InitStructure); //调用函数,把结构体参数输入进行初始化
/*USART1_RX ->PA10*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
//浮空输入模式
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA , &GPIO_InitStructure);
/*串口通讯参数设置*/
USART_InitStructure.USART_BaudRate = 9600; //波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据位8位
USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位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);
USART_ClearFlag(USART1,USART_FLAG_TC);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
USART_Cmd(USART1, ENABLE);
printf("*************************************************************\r\n");
printf("* *\r\n");
printf("* Thank you for using The Development Board Of YuanDi ! ^_^ *\r\n");
printf("* *\r\n");
printf("*************************************************************\r\n");
while (1)
{
//检查指定的串口标志设置与否
while (USART_GetFlagStatus(USART1,USART_FLAG_RXNE) == RESET);
//通过外设US ARTx发送单个数据
USART_SendData(USART1,USART_ReceiveData(USART1));
}
}
USART_ClearFlag(USART1,USART_FLAG_TC);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
USART_Cmd(USART1, ENABLE);
printf("*************************************************************\r\n");
printf("* *\r\n");
printf("* Thank you for using The Development Board Of YuanDi ! ^_^ *\r\n");
printf("* *\r\n");
printf("*************************************************************\r\n");
while (1)
{
//检查指定的串口标志设置与否
while (USART_GetFlagStatus(USART1,USART_FLAG_RXNE) == RESET);
//通过外设US ARTx发送单个数据
USART_SendData(USART1,USART_ReceiveData(USART1));
}
}
int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
return ch;
}
阅读全文
0 0
- 第四个实验 串口 查询实验
- 1.5.第四个实验--跑马灯
- 【实验二】串口实验
- 串口实验
- 我的第二次实验,第四个项目
- ARM串口实验,ADC实验,I2C实验
- 串口中间件实验详解
- 单片机串口通信实验
- Uart串口实验--TQ2440
- STM32串口实验
- Uart串口实验问题
- STM32 串口IAP实验
- CC2530 串口实验
- s3c2440 uart串口实验
- STM32串口IAP实验
- stm32f103串口IAP实验
- CC2530串口实验
- 2、串口实验
- 商品的CRUD,分页查询
- SDUT-oj 链表的有序集合
- 简图记录-linux设备驱动-字符设备基础
- 云计算初识
- 个人所得税C语言
- 第四个实验 串口 查询实验
- JavaScript设置innerHTML时出现“未知的运行时错误”--我也遇上了
- Android HTTPS认证之Volley封装
- WINDOWS钩子函数
- 寄生构造函数模式
- Caffe 的可视化 (五)Caffe 中绘制 accuracy 和 loss 曲线
- 动态规划
- 第十二周 项目(4)
- Listener、Filter以及Servlet中的url-pattern