编号:40
基于STM32串口通信设计
功能描述:
本设计由STM32F103单片机+串口通信模块+LED模块组成
1、采用STM32F103C主控
2、利用虚拟串口软件实现串口助手与STM32的通信
3、通过串口助手分别发送'A'、'B'、'C'控制三个LED亮;分别发送'a'、'b'、'c'控制三个LED灭;
4、OLED显示通过串口接收到的字符数据,并且将收到的数据通过串口发送至串口助手端,实现串口双向通信
注意:必须Proteus8.11版本才能打开
视频演示链接:
仿真图:
程序源码:
/***********************************************
***********************************************/
#include "delay.h"
#include "OLED_I2C.h"
#include "led.h"
#include "usart.h"
#include "stdio.h"
#include "stdlib.h"
#include <string.h>
extern unsigned int cnt;
int main(void)
{
unsigned char buf[18];
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3); //设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
OLED_Init(); //OLED初始化操作
OLED_CLS(); //OLED清除屏幕
LED_Init();
USART1_Init(9600);
OLED_ShowStr(16*0,0," STM32 USART ",2);
while(1)
{
if(cnt>=48&&cnt<=124) //这里只处理 0-9 a-z A-Z的字符 48-124是以上字符对应的ASCII
{
sprintf((char*)buf,"Recive Dat:%c",cnt); //显示接收的数据
OLED_ShowStr(16*0,2,buf,2);
UsartPrintf(USART1,"Recive Dat:%c\r\n",cnt);
if(cnt=='A')
LED0 = 0;
else if(cnt=='a')
LED0 = 1;
else if(cnt=='B')
LED1 = 0;
else if(cnt=='b')
LED1 = 1;
else if(cnt=='C')
LED2 = 0;
else if(cnt=='c')
LED2 = 1;
cnt = 0;
}
}
}
软件免费下载地址:
1、Proteus仿真软件
文件内容:Proteus7.8安装包、Proteus8.6安装包、Proteus.8.10安装包、Proteus Professional 8.11 SP0安装包
链接:https://pan.baidu.com/s/11LNUZ9BJXWvXf1C4dPc3_w
提取码:2756
3、KEIL5 MDK软件(STM32开发软件)
链接:https://pan.baidu.com/s/1t3eY-3yRdTa7jZMlijq_jg
提取码:ab58
文件下载:
链接:https://pan.baidu.com/s/1qlp9Lrh5SP81HT4D-KKLWQ?pwd=ymmg
提取码:ymmg