找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 15920|回复: 16
收起左侧

分享几个STM32F103RCT6例程(USART串口实验)

  [复制链接]
ID:392181 发表于 2018-8-31 23:54 | 显示全部楼层 |阅读模式
包含UART、KEY、LED、USB-Flash、RTC几个完整工程的例程给新手铺路
0.jpg

=============================
下载方式
=============================
·SWD JTAG



=============================
程序功能
=============================
·USART串口实验



=============================
硬件连接
=============================
·将串口调试板连接到USART1接口上


======================================
软件设置
======================================
·并且打开串口助手  选择好相应的COM口   如下设置
----------------
波特率 | 115200 |
----------------
数据位 |   8    |
----------------
停止位 |   1    |
----------------
校验位 | None   |
----------------
流控制 | None   |
----------------

======================================
实验现象
======================================
·串口助手输出相应信息

单片机源程序如下:
  1. #include <stm32f10x.h>
  2. #include "usart.h"
  3. //#define CTRT

  4. void  Delay (uint32_t nCount);


  5. #define LED1(x)        x ? GPIO_SetBits(GPIOB,GPIO_Pin_12): GPIO_ResetBits(GPIOB,GPIO_Pin_12)
  6. #define LED2(x)        x ? GPIO_SetBits(GPIOB,GPIO_Pin_13): GPIO_ResetBits(GPIOB,GPIO_Pin_13)
  7. #define LED3(x)        x ? GPIO_SetBits(GPIOB,GPIO_Pin_14): GPIO_ResetBits(GPIOB,GPIO_Pin_14)
  8. #define LED4(x)        x ? GPIO_SetBits(GPIOB,GPIO_Pin_15): GPIO_ResetBits(GPIOB,GPIO_Pin_15)

  9. uint8_t TxBuffer[] = "\n\rUSART Hyperterminal Hardware Flow Control Example: USART - \
  10. Hyperterminal communication using hardware flow control\n\r";

  11. #ifndef CTRT
  12. //配置矢量中断,矢量的意思就是有顺序,有先后的意思。
  13. void NVIC_Configuration(void)
  14. {
  15.   NVIC_InitTypeDef NVIC_InitStructure;        //定义数据结构体
  16.   
  17.   NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);//将中断矢量放到Flash的0地址

  18.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置优先级配置的模式,详情请阅读原材料中的文章

  19.   //使能串口中断,并设置优先级
  20.   NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  21.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  22.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  23.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  
  24.   NVIC_Init(&NVIC_InitStructure);        //将结构体丢到配置函数,即写入到对应寄存器中
  25. }
  26. #endif

  27. int main(void)
  28. {
  29.         u32 i=0xffffff;
  30.         SystemInit();

  31. #ifdef CTRT                  /*使用CTS RTS硬件流模式*/
  32.         USART_CTRT_Configuartion();
  33.         while(NbrOfDataToTransfer--)
  34.           {
  35.                     USART_SendData(USART1, TxBuffer[TxCounter++]);
  36.                     while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);         
  37.           }
  38.   
  39.           /*Receive a string (Max RxBufferSize bytes) from the Hyperterminal ended by '\r' (Enter key) */
  40.           while(1)
  41.           {         
  42.                     if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET)
  43.                     {
  44.                        USART_SendData(USART1,USART_ReceiveData(USART1));
  45.                     }   
  46.           }
  47. #else                /*普通串口模式*/
  48.         usart_Configuration();        
  49.         NVIC_Configuration();
  50.           while(1)
  51.         {
  52.                 printf("Waveshare!\r\n");
  53.                 while(--i);
  54.                 i=0xffffff;
  55.         }
  56. #endif
  57. }

  58. /*******************************************************************************
  59. * Function Name  : Delay
  60. * Description    : Delay Time
  61. * Input          : - nCount: Delay Time
  62. * Output         : None
  63. * Return         : None
  64. * Attention                 : None
  65. *******************************************************************************/
  66. void  Delay (uint32_t nCount)
  67. {
  68.   for(; nCount != 0; nCount--);
  69. }
复制代码

所有资料51hei提供下载:

Port103R.rar (1.97 MB, 下载次数: 404)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:20672 发表于 2018-10-3 08:55 | 显示全部楼层
谢谢分享!!!!
回复

使用道具 举报

ID:405264 发表于 2018-10-13 15:12 | 显示全部楼层
谢谢分享,,,
回复

使用道具 举报

ID:409110 发表于 2018-10-13 17:31 | 显示全部楼层

谢谢分享!!!!
回复

使用道具 举报

ID:129184 发表于 2019-1-2 09:45 | 显示全部楼层
GOOD GUY
回复

使用道具 举报

ID:219315 发表于 2019-1-7 15:23 | 显示全部楼层
谢谢分享,,,
回复

使用道具 举报

ID:370657 发表于 2019-1-25 09:37 | 显示全部楼层
感谢分享
回复

使用道具 举报

ID:206350 发表于 2019-5-27 11:07 | 显示全部楼层
多谢分享
回复

使用道具 举报

ID:588752 发表于 2019-7-23 15:52 | 显示全部楼层
谢谢分享!!!!
回复

使用道具 举报

ID:588752 发表于 2019-7-23 15:53 | 显示全部楼层
硬件连接,还不错
回复

使用道具 举报

ID:624671 发表于 2019-10-15 19:57 | 显示全部楼层
感谢分享,下载试试
回复

使用道具 举报

ID:2700 发表于 2019-10-21 22:19 | 显示全部楼层
谢谢分享!!!
回复

使用道具 举报

ID:617305 发表于 2019-12-17 10:55 | 显示全部楼层
感谢分享
回复

使用道具 举报

ID:440715 发表于 2019-12-26 18:43 | 显示全部楼层
谢谢分享!!!!
回复

使用道具 举报

ID:334148 发表于 2020-3-6 21:53 | 显示全部楼层

谢谢分享!!!!
回复

使用道具 举报

ID:721090 发表于 2020-4-2 16:42 | 显示全部楼层
多谢分享,分儿不够
回复

使用道具 举报

ID:785153 发表于 2020-6-20 17:19 | 显示全部楼层
谢谢分享,感谢大佬
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表