㈠ 2個51單片機怎麼實現通過1—wire單匯流排通信最好有借鑒的代碼。
用STC的吧,帶SPI匯流排,我都用這個比較好用,單線的你不是要接到從機的外部中斷口了。單線比較煩,共地的話你可以這樣干。主機將信號線拉低,從機進主中斷程序,定義一個長延時為同步頭,然後主機移位傳送數據,定義一個長延時結束。最好不要單匯流排通信,煩的呢
㈡ STC單片機的3線(+12V COM GND)單匯流排通訊,要求通訊距離100米,怎麼做呢
我有一種方案 只用2線就可以,只需要+12V GND就可以,直接在電源線通信,既供電又通信。網路來信
㈢ 單片機的通信方式有那些
單片機是一種集成在電路晶元,是採用超大規模集成電路技術把具有數據處理能力的中央處理器CPU隨機存儲器RAM、只讀存儲器ROM、多種I/O口和中斷系統、定時器/計時器等功能(可能還包括顯示驅動電路、脈寬調制電路、模擬多路轉換器、A/D轉換器等電路)集成到一塊矽片上構成的一個小而完善的計算機系統。 51 單片機內部有一個全雙工串列介面。什麼叫全雙工串口呢?一般來說,只能接受或只能發送的稱為單工串列;既可接收又可發送,但不能同時進行的稱為半雙工;能同時接收和發送的串列口稱為全雙工串列口。串列通信是指數據一位一位地按順序傳送的通信方式,其突出優點是只需一根傳輸線,可大大降低硬體成本,適合遠距離通信。其缺點是傳輸速度較低。
㈣ at89c52單片機可以通過普通IO口實現一線通信嗎求通信程序!
/*合泰單片機*/
#defineDATA_pa6
unsignedcharnub[5]={0x01,0x0b,0xfe,0xcd,0xee};
unsignedcharReceive[10]={0x00};
unsignedcharReceivetime;
unsignedcharReceiveBF=0x00;
unsignedcharReceivecount=0x00;
unsignedcharReceiveC=0x00;
void__attribute((interrupt(0x10)))isr_time(void)//100us定時器中斷函數
{
_ptma0f=0;
switch(ReceiveBF)
{
case0x00://引導碼低
{
if(DATA)
{
if(Receivetime>85)
{
if(Receivetime<100)
{
ReceiveBF=0x01;
Receivetime=0x00;
}
else
{
ReceiveBF=0x00;
Receivetime=0x00;
}
}
else
{
ReceiveBF=0x00;
Receivetime=0x00;
}
}
else
{
Receivetime++;
}
break;
}
case0x01://引導碼高
{
if(DATA)
{
Receivetime++;
}
else
{
if(Receivetime>40)
{
if(Receivetime<55)
{
ReceiveBF=0x02;
Receivetime=0x00;
Receivecount=0x00;
ReceiveC=0x00;
}
else
{
ReceiveBF=0x00;
Receivetime=0x00;
}
}
else
{
ReceiveBF=0x00;
Receivetime=0x00;
}
}
break;
}
case0x02://低電平
{
if(DATA)
{
if(Receivetime>10)//數據
{
if(Receivetime<25)
{
ReceiveBF=0x03;
Receivetime=0x00;
}
else
if(Receivetime<55)
{
ReceiveBF=0x04;
Receivetime=0x00;
}
}
}
else
{
Receivetime++;
}
break;
}
case0x03://數據碼
{
if(DATA)
{
Receivetime++;
}
else
{
if(Receivetime>25)//1
{
Receive[ReceiveC]=Receive[ReceiveC]<<1;
Receive[ReceiveC]=Receive[ReceiveC]|0x01;
Receivecount++;
if(Receivecount==8)
{
Receivecount=0x00;
ReceiveC++;
}
ReceiveBF=0x02;
Receivetime=0x00;
}
else//0
{
Receive[ReceiveC]=Receive[ReceiveC]<<1;
Receive[ReceiveC]=Receive[ReceiveC]&0xfe;
Receivecount++;
if(Receivecount==8)
{
Receivecount=0x00;
ReceiveC++;
}
ReceiveBF=0x02;
Receivetime=0x00;
}
}
break;
}
case0x04://結束碼
{
ReceiveBF=0x00;
Receivetime=0x00;
break;
}
}
}
voidSend()
{
volatileunsignedcharcount=0x05;
volatileunsignedchardatanub;
volatileunsignedchardatacount;
//引導碼
DATA=0;
dly100us(90);
DATA=1;
dly100us(45);
//數據碼
while(count)
{
datanub=nub[5-count];
datacount=0x08;
while(datacount)
{
if(datanub&0x80)
{
DATA=0;
dly100us(15);
DATA=1;
dly100us(30);
}
else
{
DATA=0;
dly100us(15);
DATA=1;
dly100us(15);
}
datanub=datanub<<1;
datacount--;
}
count--;
}
//結束碼
DATA=0;
dly100us(45);
DATA=1;
dly100us(45);
DATA=0;
dly100us(45);
DATA=1;
}