Professional Documents
Culture Documents
8051(89c51,89c52) Microcontroller
This is a simple project on how to transfer serial data to PC(personal computer) using 8051(89c51) microcontroller usart(universal
synchronous asynchronous receiver transmitter). Learning about 8051 microcontroller serial communication is the main task of the tutorial.
Serial data can be transferred to PC(personal computer) using serial port of the computer. Serial port of computers are used to connect
printers, scanners, fax machines and old shaped/pined round shaped mouse and keypad connectors.
There are two serial ports in all the systems(computer, laptop) DB-9 and DB-25. You can transfer data serially to PC using these ports, DB-9 has
9 pins and DB-25 has 25 pins, both ports comes in male and female package. Below is pin out of both the male and female connectors
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
db9 , db25 serial ports of personal computers
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
set few things on both the receiver and transmitter side. First both must be working on the same BAUD RATE. Baud rate is data transfer rate.
Such as 9600 bps OR 9600 bits per second. Secondly we have to define the code bits in transfer data. Like 8- bit data transfer, stop bits and
parity etc. Once on the both the side we defined the same settings its time to talk with each other.
Why use of Level converter – Max232
8051 series microcontrollers works on TTL(transistor transistor logic) and our PC(personal computers) works on rs-232 level wave form. 8051
microcontroller outputs data serially as TTL wave form, and our PC works on rs-232 level so we have to convert TTL level wave form in to
equivalent rs-232 level wave form before sending it to PC. To carry out this task we use MAX-232. It is an ic whic converts TTL wave form in its
equivalent rs-232 level and rs232 signal in to its equivalent TTL signal. I recommend you to first take a small tutorial on MAX-232 ic its pin-
out and working etc.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
TMOD register of 89c51 microcontroller – Timer settings register
Then the timer 1 high byte TH1 is loaded with 0xFD to generate a baud rate of 9600 bps(bits per second). Now what does baud rate means. Its
actually the protocol between the two machines which are going to transfer data between them serially. Baud rate is measured in bps bits per
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
second, both of the systems should be at the same baud rates for successful data transfer. There are many baud rates now how to calculate
the value for each baud rate below is a simple formula for it.
8051 microcontrollers completes one machine cycle after every 12 clock cycles. So our Instruction execution frequency is crystal
frequency/12. Now if our crystal is of 11.0592 MHz then our effective frequency is 11.0592/12 MHz => 921.6 KHz. 8051 UART further divides
this frequency (921.6 KHz) by 32 to generate its baud rate. Therefore effective frequency available to generate baud rates is 921.6 KHz/32 =
28800 Hz.
For different baud rates the values of TH1 will be different for Baud Rate 9600 TH1 will be=0xFD because 28800/9600 = 3. 3 is 11 in binary
take its two’s complement -3 and load the value in TH1 for 9600 baud rate. Calculate different baud rates for different crystals using the same
above formula. Different baud rates with 11.0592 MHz crystal are below. SCON(serial control) register is used to control the flow of data. This
is an 8-bit register and also it is bit addressable You can access its single bit. Here is a diagram of SCON with individual bits and modes which
you can specify.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
SCON serial control register – 8051 microcontroller
I am using mode 1, to select Scon in mode 1 make SM0=0 and SM1=1, you can also use other modes mentioned in the above diagram. SM2
enables the multiprocessing capability of the 8051, here we make SM2=0 because we are not dealing with 8th bit. REN is Receive Enable, when
REN=1 it allows the 8051 to receive data . If you want 8051 to both transfer and receive data, REN must be set to ‘1’. when REN=0 it means
receiver is disabled. TB8 and RB8 is used for serial modes 2 and 3, so here we make them 0. TI and RI are important bits.
TI is Transmit Interrupt flag, When 8051 microcontroller finishes the transfer of 8-bit character, it raises the TI flag to indicate that it is ready to
transfer another byte.
RI is Receive Interrupt flag, When 8051 receive data via RxD, it get rid of the start and stop bits and places the byte in the SBUF. Then it raises
the RI flag to indicate that a byte has been received and should be picked up before it is lost.
SBUF(serial buffer) is an 8-bit register it is not bit addressable when we have to transfer character we place it in SBUF register and poles the TI
flag. When data is received which is sended by some other source it is also placed in SBUF register, and we pick it from here.The circuit
diagram is simple and is shown below.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
serial data transmission to pc with 8051
After you make connections go to Start->Programs->Accessories->Communications->HyperTerminal open new connection name it what ever
you want then click OK. Now a window appears select COM1 from connect using drop down menu click OK Now set COM1 properties bits per
second as you specified in your program in mine case 9600, Data bits=8, Parity=none, Stop bits=1, Flow control=none then click OK. Now
switch on the power of your circuit, you will see what you specified in your code.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
1
2 #include<reg51.h>
3
4 void main()
5 {
6
7 char A[]="www.microcontroller-project.com";
8 unsigned int i=0;
9 P3=0x03; //Initializing 8051 UART
10 TMOD=0x20; // Timer1 Mode2 8 bit auto reload
11 TH1=0xFD; // 9600 bps
12 SCON=0x50; // 8 Data bit, 1 start bit, bit 1 stop
13
14 TR1=1; // Timer1 ON
15
16 while(1)
17 {
18
19 while(A[i]!='\0'){
20 SBUF=A[i]; // Placing character one by one in the serial buffer register
21
22 while(TI==0); // It automatically poles up to 1 when character is transmitted
23 TI=0;
24 i++;
25 }
26 i=0;
27 }
28 }
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
I am sending my web site name www.microcontroller-project.com to PC on UART protocol. The final output received on Hyperterminal of PC is
given below.
Download the project files and code compiled in keil uvision 4 with hex file , and if you have any queries let me know
that.Please Write your comments below.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Filed Under: 8051 Microcontroller, Microcontroller Projects
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
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Designing Open Loop Non – Isolated Buck Converter (Part 5/12)
Designing Close Loop Non-Isolated Boost Converter With Adjustable Output (Part 4/12)
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)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
STAY UP TO DATE
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
RECENT ARTICLES
MOST POPULAR
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
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
ELECTRO-TECH-ONLINE.COM DISCUSSIONS
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Connect with Engineers Garage
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