Jp3 is connected to P0 port.
# Include <reg51.h> # define uchar unsigned charuchar flag, num; // void initser (); void main () {// initser (); While (1) {// the data received from the computer is immediately sent to the computer if (flag = 1) {// close the interruption, otherwise it is necessary to enter the interrupted service program, will cause a vicious circle es = 0; flag = 0; // send data, write data to the sending cache sbuf = num; while (! Ti); Ti = 0; es = 1 ;}}// void initser () {// T1 works in Mode 2 tmod = 0x20; // initial installation value --- 9600 baud rate smod = 0th1 = 0xfd; TL1 = 0xfd; // start the timer tr1 = 1; // Serial Port Works in Mode 1 sm0 = 0; SM1 = 1; // enable MCU to receive data Ren = 1; // on interrupt es = 1; EA = 1;} // void Ser () interrupt 4 {// software reset rI = 0; // read data p0 = sbuf; num = sbuf; flag = 1 ;}
MCU Lesson 13th: Serial Communication --- send data to a computer