WWW Engineersgarage Com Serial Data Received From PC Using 8
WWW Engineersgarage Com Serial Data Received From PC Using 8
WWW Engineersgarage Com Serial Data Received From PC Using 8
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
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.
If you dont know how to interface lcd with 8051(89c51,89c52) microcontroller here are some good tutorial, just go through them.
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.
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 }}
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
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 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)
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
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
EDABOARD.COM DISCUSSIONS
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
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