|
100黑幣
20200710154424.png (35.38 KB, 下載次數(shù): 50)
下載附件
2020-7-10 15:47 上傳
要做一個(gè)數(shù)據(jù)采集傳輸系統(tǒng),采集以做出,不知道怎樣實(shí)現(xiàn)串口通信。下面是找的相似的程序,不知怎么改
#include<reg51.h>
unsigned char code Tab[ ]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}
void Send(unsigned char dat)
{
SUBF=dat;
while(TI==0);
TI=0;
}
void dely(void)
{
unsigned char m,n;
for(m=0;m<200;m++)
for(n=0;n<250;n++)
;
}
void main{void}
{
unsigned char i;
TMOD=0x20;
SCON=0x40;
PCON=0x00;
TH1=0xfd;
TL1=0xfd;
TR1=1;
while(1)
{
for=(i=0;i<8;i++)
{
Send(Tab[ i]);
dely();
}
}
}
|
最佳答案
查看完整內(nèi)容
// 1.不要 Tab[]
// 2 while(1) 改成:
while(溫度讀好)
{
//清溫度讀好標(biāo)志;
P23 = 1; //置485發(fā)送模式
Send(溫度低字節(jié));
dely();
Send(溫度高字節(jié));
}
// 接收那邊 U3P20 = 0 ; 置485發(fā)送模式
// 串口接收數(shù)據(jù),2個(gè)字節(jié),判斷一下高低字節(jié)。送顯示。
// 這個(gè)只是簡單的通訊測試。實(shí)際應(yīng)用是要有通訊協(xié)議的,一般RS485用Modebus通訊協(xié)議。
|