The block diagram of data transfer between UART port of 89c51 microcontroller and personal computer is shown below.
Max232 Level Converter
8051(89c51,89c52) UART Microcontroller
89c51 Uart microcontroller is used to receive data from PC. You can also use any other 8051 series microcontroller like 89c52 microcontroller. But first make sure it has built-in UART (universal asynchronous receiver transmitter) for serial communication.
Port 1 of our microcontroller is used as the output port. It is connected to the data pins of the 16×2 LCD.
- Pin #5 of port 3 is connected to the rs (register select) pin of the 16×2 LCD.
- Pin #6 of port 3 is connected to the en (enable) pin of the 16×2 LCD.
- Pin #7 of port 3 is connected to rw (read and write) pin of 16×2 LCD.
If you don't know how to interface LCD with 8051 microcontroller (89c51,89c52), here are some good tutorials, just go through them.
- LCD 16×2 WORKING.
- DIFFERENCE BETWEEN COMMANDS AND SENDING DATA TO LCD.
- DISPLAYING YOUR NAME ON LCD using 8051 MICROCONTROLLER.
Project code
In the main function, I first called the lcdinit function to initialize the 16×2 lcd. All commands used in the function are discussed in depth in the above tutorials. Then the timer mode is set. TMOD=0x02 means Timer1, Mode2 (8-bit auto reload) is selected. TH1=0xFD is actually a one byte high timer, providing hexadecimal value 0xFD to TH1 means setting the communication baud rate between 8051 microcontroller and PC to 9600 bps (bits per second). SCON=0x50 is actually defining our serial data bit format Total = 8 Data bit with 1 start bit and 1 stop bit. TR1=1 means running timer one. This entire phenomenon with the full meaning of the statements (SCON,TMOD,TH) is discussed in the two tutorials below. How to calculate baud rate values is also discussed.
- HOW TO SEND SERIAL DATA TO PC (Hyperterminal).
- 8051(89c51) TIMER RECORDS.
while(RI==0) is checking the RI (receive interrupt) flag continuously. This flag automatically becomes one when 8051(89c51,89c52) receives any data on its RXD( P3^0 ) pin. When RI becomes 1, it means we have one byte of data in our SBUF register (serial buffer). Then in the next instruction I took the Byte from the SBUF register and saved it in character variable data. Then I left the RI flag low again to receive the next byte. The Byte that I saved in the data variable is now sent to the display function to be displayed on the 16×2 LCD.