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

单片机单线通讯

发布时间: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;

}

阅读全文

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

热点内容
股市操练大全八册pdf 浏览:120
c传递指针到python 浏览:163
手动添加引导的命令 浏览:54
740服务器小蓝条是做什么的 浏览:523
linux文件操作命令 浏览:127
安卓手机图片文件夹加锁 浏览:781
steam提示音在哪个文件夹 浏览:339
项目开发全程实录pdf 浏览:532
单片机reset 浏览:597
pdf怎么是英文 浏览:971
旗云2压缩机保险 浏览:374
做程序员压力大吗表情包 浏览:312
pdf下拉 浏览:372
php去掉小数后面的0 浏览:954
阿里备案买什么服务器 浏览:262
网络驱动下载到哪个文件夹 浏览:482
达内程序员培训西安 浏览:506
人保送车主惠app上怎么年检 浏览:605
android手机开机密码 浏览:482
linux查看某个进程命令 浏览:530