编号:56
基于51单片机的双机通信系统
功能描述:
本设计由51单片机最小系统+串口通讯模块+液晶1602显示模块+键盘模块+声光报警模块 1、主控制器是89C52单片机。 2、设计一个点对点双机通信系统,能用按键设置通信参数,能够对当前通信信息、通信参数进行显示,并能对接收到的信息进行甄别报警。 3、设计两套单片机系统A/B,连接好A/B系统的串行通信线路,上电或按键复位后显示器件自动显示待发送/接收状态 (例如显示“Send?”“Receive ?”),进入准备阶段通过按键“OK”选择确认功能。 4、可以通过按键修改设置通信参数,例如串行通信的速率,数据位数等。 5、对接收到的数据进行甄别,接收到特定数据后触发蜂鸣器报警。
Proteus7.8以上版本均可使用
视频演示链接:
56、基于51单片机的双机通信系统
仿真图:
![](https://img-blog.csdnimg.cn/ba89cf1256b84f979603c3021f35a0d8.png)
![](https://img-blog.csdnimg.cn/bd365c77c8354b8da1c477379d52a02c.png)
电路图:
![](https://img-blog.csdnimg.cn/37241cda05c84ed9ac6dcdf484e388fc.jpeg)
实物图:
![](https://img-blog.csdnimg.cn/a5f8fee8786d436db7dab7748835d820.jpeg)
程序源码:
#include "reg52.h"
#include "delay.h"
#include "uart.h"
#include "lcd1602.h"
#include "stdio.h"
#include "string.h"
sbit LED = P3^6; //LED控制接口
void Uart1_BAUD(unsigned char BD);
sbit KEY0 = P2^0;
sbit KEY1 = P2^1;
sbit KEY2 = P2^2;
sbit KEY3 = P2^3;
sbit KEY4 = P2^4;
unsigned char lv = 0;
void main(void)
{
unsigned char TT = 0;
static unsigned char num = 0;
unsigned char mode = 0;
unsigned char send[2];
Lcd1602_Init(); //LCD1602液晶初始化
Lcd1602_String(0,0,"Send? KEY0 ");
Lcd1602_String(0,1,"Recevie? KEY1 ");
while(1)
{
if(KEY0==0)
{
while(KEY0==0);
Lcd1602_Write_Com(0x01); //清屏光标复位
Lcd1602_String(0,1,"Send: ");
mode = 0; //发送模式
break;
}
else if(KEY1==0)
{
while(KEY1==0);
Lcd1602_Write_Com(0x01); //清屏光标复位
Lcd1602_String(0,1,"Recevie: ");
mode = 1; //接收
break;
}
}
Uart1_BAUD(1);
Lcd1602_String(12,0,"8Bit");
while(1)
{
if(KEY2==0)
{
while(KEY2==0);
lv++;
Uart1_BAUD(lv);
if(lv>=5)
lv = 0;
}
if(KEY4==0) //数据位
{
while(KEY4==0);
if(TT==0)
{
TT = 1;
Uart2_Dat(TT);
Lcd1602_String(12,0,"9Bit");
}
else if(TT==1)
{
TT = 0;
Uart2_Dat(TT);
Lcd1602_String(12,0,"8Bit");
}
}
if(mode==0)
{
if(KEY3==0) //发送
{
while(KEY3==0);
send[0]='A';
send[1]=num%10+0x30;
Uart1_SendString(send);
num++;
if(num>9)
num = 0;
Lcd1602_String(8,1,send);
Lcd1602_String(10,1," ");
}
}
else if(mode==1)
{
if(Uart1_WaitRecive()==0) //收到了数据
{
Lcd1602_String(8,1,uart1_buf);
Lcd1602_String(10,1," ");
//判断uart1_buf里边有没有LED0
if(strstr((char *)uart1_buf,(char *)"A0")!=NULL)
{
LED = 0;
Uart1_ClearRecive(); //清除
}
else if(strstr((char *)uart1_buf,(char *)"A1")!=NULL)
{
LED = 1;
Uart1_ClearRecive(); //清除
}
}
delay_ms(10);
}
}
}
软件免费下载地址:
1、Proteus仿真软件 文件内容:Proteus7.8安装包、Proteus8.6安装包、Proteus.8.10安装包、Proteus Professional 8.11 SP0安装包
链接:https://pan.baidu.com/s/11LNUZ9BJXWvXf1C4dPc3_w 提取码:2756
2、KEIL4 C51软件安装包
链接:https://pan.baidu.com/s/1CTZBqDsPsyIbjCIjI_birA 提取码:sy2a
文件下载:
链接:https://pan.baidu.com/s/1DglBQX1rPIa20VIxn12cnQ?pwd=xmwf 提取码:xmwf
|