Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C5 1 language, serial communication program, AT89S52 single chip microcomputer sends an integer array data to.
C5 1 language, serial communication program, AT89S52 single chip microcomputer sends an integer array data to.
void Init_Serial(void)

{ rd 485 = 0;

SCON = 0x 50; //serial port working mode 1

TMOD =(TMOD & amp; 0x0F)| 0x 20; //Select timer 1 mode 2.

PCON = 0x 80; //Baud rate multiplication

th 1 = 0x F6; //The initial count value is 9600bps.

tr 1 = 1; //Start timer 1

IE | = 0x90// Enable serial interrupt

SBUF = 0x00

RI = 0;

}

Invalid delay (invalid)

{unsigned integer i;

for(I = 0; I & lt9500; i++);

}

void sendbit(unsigned char *ch,int len)

{

int flaglen = 0;

rd 485 = 1;

delay();

while(flaglen & lt; len) {

And (! TI) /* Check the sending mark */

{; }

TI = 0;

SBUF = *(ch+flaglen); /* Send data */

flaglen++;

}

delay();

rd 485 = 0;

} Use 3 to invalidate serial () interrupt 4.

{ if (RI)

{

if(fg & gt; =3)

fg = 0;

b[fg]= SBUF;

fg++;

RI = 0;

}

}

The single chip microcomputer crystal oscillator of this program is18.432m. When using it, the high and low eight bits of plastic data to be sent are put into a character array, which can be received by another single chip microcomputer through interruption. This program can be used to send and receive MCU.