WWW Engineersgarage Com Serial Data Received From PC Using 8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Serial data received from pc and displayed on 16×2 lcd using

8051(89c51,89c52) microcontroller UART port

February 11, 2021 By EG Projects

In this post i am going to explain how to receive serial data from your pc and display it on 16×2 lcd using 89c51 microcontroller UART port.
Hardware components of the project includes  max232(TTL to RS232 level converter/shifter ),  8051(89c51,89c52) microcontroller and 16×2
lcd. On software side i am using Hyper terminal. Hyper terminal is a program through which one can transmit and receive data serially using
personal computer(PC) serial ports. Standard  PC has two serial ports, db-9 and db-25. To these serial ports we usually connect our printers,
fax machines, mouse and joy sticks.
The block diagram of data transfer between 89c51 microcontroller UART port and personal computer is shown below. 

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
8051 microcontroller serial data transfer between pc and 89c51 uart port

Max232 Level converter


8051 microcontroller works on TTL logic and personal computers works on rs232 logic. In order to communicate between the two modules
data must be on the same carrier logic. Hence a level shiftier like max232 is used. Which transforms data from one logic to another before
sending it to the receiver. In order to learn more about max232 transceiver, its pin out, working and power requirements please take the below
tutorial. 

Max232 Pin out and Working

8051(89c51,89c52) Microcontroller UART


89c51 microcontroller Uart is used to receive data from PC. You can also use any other 8051 series microcontroller like 89c52 microcontroller.
But first be sure it has build in UART(universal asynchronous receiver transmitter)for serial communication.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Port-1 of our microcontroller is used as output Port. It is connected to data pins of 16×2 lcd. 

Port-3 pin# 5 is connected to rs(regester select) pin of 16×2 lcd. 


Port-3 pin# 6 is connected to en(enable) pin of 16×2 lcd. 
Port-3 pin# 7 is connected to rw(read write) pin of 16×2 lcd.

If you dont know how to interface lcd with 8051(89c51,89c52) microcontroller here are some good tutorial, just go through them.

16×2 LCD WORKING.


DIFFERENCE BETWEEN COMMANDS AND DATA SEND TO LCD.
DISPLAYING YOUR NAME ON LCD using 8051 MICROCONTROLLER.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
serial data receiverd from pc hyperterminal and displayed on lcd using 8051(89c51,89c52) microcontroller

Project Code
In the main function i first called the lcdinit() function to initialize the 16×2 lcd. All the commands used in the function  are deeply discussed in
the above tutorials. Then timer mode is set. TMOD=0x02 means Timer1,  Mode2 (8 bit auto reload) is selected. TH1=0xFD is actually timer one
high byte, giving 0xFD hexadecimal value to TH1 means setting communication baud rate between 8051 microcontroller and PC to 9600

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
bps(bits per second). SCON=0x50 is actually setting our serial data bits format Total=8 Data bit with 1 start bit and 1 stop bit. TR1=1 means
run timer one. This whole phenomena with full meaning of the statements (SCON,TMOD,TH) is discussed in the below two tutorials. How to
calculate baud rate values are also discussed.

HOW TO SEND SERIAL DATA TO PC(Hyperterminal).


TIMER REGISTERS OF 8051(89c51).

while(RI==0) is checking RI(receive interrupt) flag continuously. This flag automatically becomes one when 8051(89c51,89c52) receives any
data on its RXD pin(P3^0). when RI becomes 1 it means we have one byte of data in our SBUF(serial buffer) register. So in next statement i
picked the Byte from SBUF register  and save it in character variable data. Then i made the RI flag low again to receive next byte. The Byte
which i saved in data variable is now send to display function to be displayed on the 16×2 lcd. 

1
2 #include<reg51.h>
3
4 sbit rs=P3^5; //Register select
5 (RS)
6 sbit en=P3^6; //Enable (EN) pin
7 sbit rw=P3^7;
8 //Read write (RW) pin
9 void delay(unsigned int time) //Time delay function
10 {
11 unsigned
12 int i,j;
13 for(i=0;i< time;i++)
14 for(j=0;j<5;j++);
15 }
16

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
17 //Function for sending values to the command register of LCD
18 void lcdcmd(unsigned char value)
19 {
20 P1=value;
21 rs = 0;
22 rw = 0;
23 en = 1;
24 delay(50);
25 en=0;
26 delay(50);
27 }
28
29 //Function for sending values to the data register of LCD
30 void display(unsigned char value)
31 {
32 P1=value;
33 rs = 1;
34 rw = 0;
35 en = 1;
36 delay(500);
37 en=0;
38 delay(50);
39 }
40
41 //function to initialize the registers and pins of LCD
42 //always use with every lcd of hitachi
43 void lcdint(void)
44 {
45 P1=0x00; //Port 1 is used as output port
46 P3=0x03; //Port 3 higher bits from 2 to 7 are used as output and lower two
47 //bits are used to activate //UART

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
48
49 delay(15000);
50 display(0x30);
51 delay(4500);
52 display(0x30);
53 delay(300);
54 display(0x30);
55 delay(650);
56 lcdcmd(0x38);
57 delay(50);
58 lcdcmd(0x0F);
59 delay(50);
60 lcdcmd(0x01);
61 delay(50);
62 lcdcmd(0x06);
63 delay(50);
64 lcdcmd(0x80);
65 delay(50);
66 }
67 void main()
68 {
69 char data;
70 lcdint();
71 TMOD=0x20; // Timer1 Mode2 8
72 bit auto reload
73 TH1=0xFD; // 9600 bps
74 SCON=0x50; // 8 Data bit, 1 start
75 bit, 1 stop bit
76 TR1=1; // Timer1 ON
77 while(1){

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
78
79
80 while(SBUF!=0x0D)//Checking if enter key is pressed
81 {
82 while(RI==0);
83 data=SBUF;
84 RI=0;
85 display(data);
86 delay(50);
87 }
88 }}

serial-data-received-from-pc-using-8051.c hosted with by GitHub view raw

Download the project files and Code(Hex,c++) compiled using keil uvision 4 compiler. If you feel any problem in the code or
don’t understand any statement of the code just write your queries below. The code is Tested using Hardware and its free of
any bug. << />iv>
Serial data Received from PC 

Filed Under: 8051 Microcontroller, Featured Contributions, Microcontroller Projects

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and
Electro-Tech-Online.com where you can get those questions asked and answered by your peers!

EDA BOARD

ELECTRO-TECH-ONLINE

FEATURED TUTORIALS

Designing Closed Loop Non – Isolated Buck Converter (Part 6/12)

Designing Open Loop Non – Isolated Buck Converter (Part 5/12)

Designing Close Loop Non-Isolated Boost Converter With Adjustable Output (Part 4/12)

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Designing Open Loop Non-Isolated Boost Converter With Adjustable Output Voltage (Part 3/12)

Designing Closed Loop Non – Isolated Boost Converter SMPS (Part 2/12)

Designing an Open loop Boost Converter SMPS (Part 1/12)

STAY UP TO DATE

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
EE TRAINING CENTER CLASSROOMS

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
RECENT ARTICLES

How to generate PWM-based dual sine waves


Keysight brings O-RAN architect to AWS Outposts
Samsung releases beta version of its Internet 15.0
NI Connect: Learn how test and data analytics will shape new innovations
DEKRA selects Keysight’s test solutions to verify 5G devices

MOST POPULAR

555 timer circuit 8051 alarm Arduino atmega16 avr circuit clock computer connector dc motor display Electronic Part Electronic
Parts Fujitsu gsm ic infineontechnologies Intel invention IoT ir lcd ldr led maximintegratedproducts microchip Microchip Technology microchiptechnology

microcontroller motor nxpsemiconductors Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research robot


samsung sensor stepper motor STMicroelectronics switch Technology vishayintertechnology

EDABOARD.COM DISCUSSIONS

How to decompile .bin from Microchip EEPROM


PSFB current sensing
CAT5 cable wires for SPI

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Film capacitor vs Electrolytic capacitor?
Ground loops? Leaky current to ground? On RF equipment in the Lab

ELECTRO-TECH-ONLINE.COM DISCUSSIONS

convertinf Ardunio code to Swordfish basic


Will I be able to turn them off?
Mot Tesla coil not working
Funny Images Thread!
Cheap USB oscilloscopes.

Connect with Engineers Garage  

ANALOG IC TIPS POWER ELECTRONIC TIPS

CONNECTOR TIPS SENSOR TIPS

DESIGNFAST TEST AND MEASUREMENT TIPS

EDABOARD FORUMS 5G TECHNOLOGY WORLD

EE WORLD ONLINE ABOUT US

ELECTRO-TECH-ONLINE FORUMS CONTACT US

MICROCONTROLLER TIPS ADVERTISE

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Copyright © 2021 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD

You might also like