欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
51單片機RS485數據通信程序和Proteus仿真
[打印本頁]
作者:
筱豆先生
時間:
2021-4-13 17:26
標題:
51單片機RS485數據通信程序和Proteus仿真
RS485仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.png
(17.32 KB, 下載次數: 77)
下載附件
2021-4-13 18:15 上傳
單片機源程序如下:
#include <reg51.h>
#include <absacc.h>
#define TR 1
#define uchar unsigned char
#define uint unsigned int
//uchar idata buf[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
uchar data1,data2;
uchar pf;
uchar flag,flag1;
sbit key1=P1^0;
sbit key2=P2^0;
/************延時程序************/
void delay(uchar k)
{
uchar j;
while((k--)!=0)
{
for(j=0;j<125;j++)
{;}
}
}
void init(void)
{
TMOD=0x20;
TH1=0xe8;
TL1=0xe8;
PCON=0x00; //本次調節發現485通信而言,波特率對傳輸信息有很
TR1=1; //重要的作用,因為波特率低的話,不是傳輸速度慢,
SCON=0x90; //而是無法傳輸數據,這是調試時發現的致命錯誤。
} //還有在485通信中無論是單機通信,還是多機通信,
//串行通信的方式必須是-----方式2或者是方式3,不能是方式0或者方式1,這一點特別的重要。
void send(void)
{
key2=1;
SBUF=0x01;
while(TI==0)
{
;
}
TI=0;
key2=0;
while(RI==0)
{
;
}
data1=SBUF;
RI=0;
key2=1;
if(data1!=0x01)
{
SBUF=0x0f;
while(TI==0)
{
;
}
TI=0;
}
else{
SBUF=0x09;
while(TI==0)
{
;
}
TI=0;
}
}
void main(void)
{
//delay(500);
init();
while(1)
{
//keyscan();
send();
delay(100);
}
}
復制代碼
#include <reg51.h>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
//uchar idata buf[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
uchar dat1,dat2;
uchar pf;
uchar flag,flag1;
sbit key1=P1^0;
sbit key2=P2^0;
/************延時程序************/
void delay(uchar k)
{
uchar j;
while((k--)!=0)
{
for(j=0;j<125;j++)
{;}
}
}
void init(void)
{
TMOD=0x20;
TH1=0xe8;
TL1=0xe8;
PCON=0x00;
TR1=1;
SCON=0x90;
}
void receive(void)
{
key2=0;
RI=0;
while(RI==0)
{
;
}
dat1=SBUF;
RI=0;
key2=1;
if(dat1==0x01)
{
SBUF=0x01;
while(TI==0)
{
;
}
TI=0;
}
key2=0;
while(RI==0)
{
;
}
dat2=SBUF;
RI=0;
}
void main(void)
{
//delay(500);
init();
while(1)
{
receive();
delay(100);
P1=dat2;
}
}
復制代碼
51hei.png
(10.08 KB, 下載次數: 69)
下載附件
2021-4-13 18:15 上傳
所有資料51hei提供下載:
485單數據通信.rar
(36.27 KB, 下載次數: 112)
2021-4-13 17:26 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
Gwl1202
時間:
2022-8-4 13:58
你這個位定義key2是不是錯的
作者:
學51的菜雞
時間:
2022-12-29 22:22
請問不能使用方式0和1的原因是?
作者:
所示
時間:
2023-3-21 00:04
樓主說的RS485的通信波特率的設置還真是重要,剛解決了一個問題
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1