51单片机串口通信,232通信,485通信,程序 代码1:232通信 #include<>
#define uchar unsigned char #define uint unsigned int uchar flag,a,i;
uchar code table[]=\ void init() { }
void main() {
TMOD=0X20; TH1=0XFD; TH0=0XFD; TR1=1; REN=1; SM0=0; SM1=1; EA=1; ES=1;
init();
}
while(1) { }
if(flag==1) { } ES=0; for(i=0;i<6;i++) { } SBUF=a; while(!TI); TI=0; ES=1; flag=0;
SBUF=table[i]; while(!TI); TI=0;
void ser() interrupt 4 {
}
RI=0; a=SBUF; flag=1;
代码2:485通信 #include<> #include\
#define uchar unsigned char #define uint unsigned int unsigned char flag,a,i; uchar code table[]=\ void init() {
TMOD=0X20; TH1=0Xfd; TL1=0Xfd; TR1=1; REN=1; SM0=0; SM1=1; EA=1; ES=1;