在线等!!!两套(51单片机+zigbee发送模块)的通信程序是这样写的吗?

#include <reg51.h>#include <string.h>#define uchar unsigned char#define uint unsigned intunsigned char data sendData[]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x9};//定义要发送的数据//设置串口工作方式void uart_init(){ TMOD=0x20; TH1=0xFD; TL1=0xFD; PCON=0x00; TR1=1; SCON=0x50;} //设置串口工作方式 void delay(uint z){ uint x,y; for(x=z;x>0;x--) for(y=125;y>0;y--); } //延时程序void shakeHand(){ do { SBUF=0x01; while(TI==0); TI=0; while(RI==0); RI=0; } while(SBUF!=0x02) ;} //握手信号void send(unsigned char sendData){ SBUF=sendData; while(TI==0); TI=0;}//发送数据程序unsigned char receive(){ while(RI==0); RI=0; return (SBUF);}void main(){uart_init();shakeHand(); while(1) { unsigned char i=0; for(;i<strlen(sendData)-1;i++) { send(sendData[i]); delay(500) ; } shakeHand();do P2=receive(); while(SBUF!=0x09) ; shakeHand(); }}已机部分#include <reg51.h>#include <string.h>#define uchar unsigned char#define uint unsigned intunsigned char data sendData[]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x9};//定义要发送的数据//设置串口工作方式void uart_init(){ TMOD=0x20; TH1=0xFD; TL1=0xFD; PCON=0x00; TR1=1; SCON=0x50;} //设置串口工作方式 void delay(uint z){ uint x,y; for(x=z;x>0;x--) for(y=125;y>0;y--); } //延时程序void shakeHand(){ do { SBUF=0x02; while(TI==0); TI=0; while(RI==0); RI=0; } while(SBUF!=0x01) ;} //握手信号void send(unsigned char sendData){ SBUF=sendData; while(TI==0); TI=0;}//发送数据程序unsigned char receive(){ while(RI==0); RI=0; return (SBUF);}void main(){ uart_init(); shakeHand(); while(1) { unsigned char i=0; do P2=receive(); while(SBUF!=0x09) ; shakeHand(); for(;i<strlen(sendData)-1;i++) { send(sendData[i]); delay(500); } shakeHand(); }} 问题补充:两个51单片机直接的通信 不管是直接用引脚连接起来,还是通过zigbee的cc2420的无线通信,是不是通过上面那个程序都能实现?谢谢。急。。。
2026年09月21日 21:54
有3个网友回答
网友(1):

这个用于两个51单片机之间串口的通信应该是可以的。不过通过zigbee的CC2420的无线通信应该是不行的吧。最起码没有完成无线发射那部分的程序。

网友(2):

你也太不容易了,发这么多了。我实在是没研究过要不就给你解决了。。不好意思。。

网友(3):

是的吧