导航:首页 > 操作系统 > 单片机单线通讯

单片机单线通讯

发布时间:2023-06-10 18:30:15

㈠ 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;

}

阅读全文

与单片机单线通讯相关的资料

热点内容
头条app如何设置横屏模式 浏览:355
clion怎么使用终端编译 浏览:766
服务器地址部署到公网 浏览:492
新桑塔纳安卓大屏导航怎么拆 浏览:382
程序员送给女友的礼物 浏览:430
ftp命令行查看文件数量 浏览:496
linux查看设备的命令 浏览:827
pythongolang学哪个 浏览:349
金蝶加密锁驱动下载 浏览:300
python编程基于自然语言处理库 浏览:133
javaseruntime 浏览:902
cad如何将命令放在鼠标旁边 浏览:746
程序员对粉色 浏览:125
编译器命令java 浏览:989
云服务器怎么数据同步 浏览:685
c盘文件修复命令语 浏览:966
文件夹中文件怎么上下移动 浏览:831
魅族手机用什么软件解压 浏览:763
加密币糖果 浏览:300
c编译调试是什么 浏览:631