找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1693|回复: 0
收起左侧

STM32简单串口通信程序

[复制链接]
ID:570682 发表于 2019-6-24 11:35 | 显示全部楼层 |阅读模式
基于stm32f103rb的串口通信

单片机源程序如下:
  1. /******************************************************************************/
  2. // 任务分类:非周期非连续(随机任务)、周期非连续(定时任务)、周期连续(循环)
  3. // 本程序:单个周期连续性任务
  4. // 通过查询方式进行USART1数据发送
  5. // 连线:USART1缺省连线
  6. /******************************************************************************/

  7. /* Includes ------------------------------------------------------------------*/
  8. #include <stm32f10x.h>
  9. #include "drv_usart.h"
  10. #include <stdio.h>
  11. //uint8_t TxBuffer[] = "USART Hyperterminal Hardware Flow Control Example!\n";

  12. void Delay1ms(uint32_t nCount);

  13. // 主程序
  14. int main(void)
  15. {
  16.         unsigned char k = 0;
  17.         float ft = 0.0f;
  18.        
  19.         USART2_Config();                // 串口初始化

  20.         while(1)                                // 死循环
  21.         {
  22.                 k++;
  23.                 ft = (float)k / 10.0f;
  24.                 printf("\r\n this is a printf demo \r\n");
  25.                 printf("Integer and float dispaly is  %d, \t %f\r\n", k, ft);
  26.                 Delay1ms(1000);                // 延时1s
  27.         }
  28. }


  29. /*----------------------------------------------------------*\
  30. |  Delay1ms 延时 Inserts a delay time.(系统时钟为8MHz*9)   |
  31. |  nCount: 延时时间 specifies the delay time length.       |
  32. \*----------------------------------------------------------*/
  33. void Delay1ms(uint32_t nCount)
  34. {
  35.         int k;
  36.        
  37.         for(; nCount != 0; nCount--)
  38.                 for(k=0; k<10282; k++)
  39.                         __nop();
  40. }
复制代码

所有资料51hei提供下载:
串口.rar (4.16 KB, 下载次数: 13)



回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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