How to use a computer to send data to a single-chip microcomputer, how to receive data from a single-chip microcomputer?
The JP3 is connected to the P0 port.
Send a hexadecimal data from the computer to the microcontroller and watch the display of the digital tube.
#include <reg51.h>/** send a hexadecimal data to the microcontroller to display the digital tube */void initser (); void Main () {<span></span>initser () ;
while (1) {//queries the value of RI. If it is 1, then the data is received. The software should be zeroed at this time. RI = 0if (ri = = 1) {ri = 0;//gets data sent from the computer from the buffer, assigned to P0P0 = Sbuf;}}} Initialize function void Initser () {//Let timer T1 work in mode 2 Tmod = 0x20;//Assignment TH1 = 0xfd; TL1 = 0xfd;//Serial Port working mode is 1SM0 = 0; SM1 = 1;//agreed serial port accepts ren = 1;//start timer TR1 = 1; P0 = 0xc0;}
Serial Communication Query Method steps:
1---Determine how the timer T1 works
2---Assigning two registers to a timer
3---start timer T1
4---Determine how the serial port works
5---Assuming that a single piece of data is obtained from the computer, ren = 1 should be
6---Query the value of RI, assuming that it is 1, then receive the data, note that the software should immediately be set to RI = 0
SCM 11th Lesson: Serial Communication Query Method---accept data from computer