Image may be NSFW. Clik here to view. ![]() |
Serial Communication using 8051 |
Microcontrollers need to communicate with external devices such as sensors, computers and so on to collect data for further processing. Data communication generally done by means of two methods : Parallel and Serial mode. In the parallel mode data bits are transferred in a fast manner using more number of lines. But when comes to a Microcontroller system, we cannot afford to dedicate many lines for data transfer.
Serial Communication uses only two data lines to establish communication between Microcontroller and external devices. In this communication data bits are transferred one bit at a time, so the process will be slow. This article describes the Interfacing of 8051 with PC to establish communication through a serial port RS232.
RS232 AND MAX232:
To establish communication between a controller and PC, we must use a serial I/O standard RS-232 which was widely used in PC and several devices. PC works on the RS-232 standards which operates at a logic level of -25V to +25V. But Microcontrollers use TTL logic which works on 0-5V which is not compatible with the RS-232 standards.
MAX232 is a specialized IC which offers intermediate link between the Microcontroller and PC. The transmitters of this IC will convert the TTL input level to the RS-232 Voltage standards. Meanwhile the receivers of this IC will convert RS-232 input to 5V TTL logic levels. Read the complete working of MAX232 IC.
SCON REGISTER:
Image may be NSFW. Clik here to view. ![]() |
SCON Register |
SCON is a bit addressable register is used to set the mode in which the serial communication takes in the controller. The above figure shows the configuration of the SCON register. The functions of each bit are listed below.
Image may be NSFW. Clik here to view. ![]() |
Serial Mode of 8051 |
SM0, SM1: Serial Mode control Bits
SM2: Multiprocessor mode control bit, logic 1 enables Multi processor mode and 0 for normal mode.
REN: Enables Serial reception. If set it enables the reception, otherwise the reception is disabled.
TB8: It is the 9th bit of the data that is to be transmitted.
RB8: It is used in modes 2 and 3, it is the 9th bit received by the microcontroller.
TI: It is known as Transmit Interrupt flag which is set by the hardware to indicate the end of a transmission. It has to be cleared by the software.
RI: It is known as Receive Interrupt flag which is set by the hardware to indicate the end of a reception. It has to be cleared by the software.
BAUD RATE:
It is defined as number of bits transmitted or received per second and usually expressed in Bits per second bps. For mode 0 and mode 2 the baud rate is determined by means of 1/12, 1/32 or 1/64 of the crystal frequency whereas for mode 1 and 3 it is determined by means of timer 1.
Image may be NSFW. Clik here to view. ![]() |
Baud Rate by Timer1 |
Learn how to configure Timers in 8051.
SBUF REGISTER:
It is a 8 bit register that holds the data needed to be transmitted or the data that is received. The serial port of the 8051 is full duplex so the microcontroller manages to transmit and receive data into the register simultaneously.
PROGRAM:
|
The above program is coded in such a way to receive a character from PC and in return transmits "ok" to it. This code have three parts initialize,receive and transmit to perform the process of serial communication. This can be tested using Hyperterminal software after connecting your controller to PC through RS232.
- Initialize - Initialize timer for baud rate and set mode for serial transmission
- Receive - Enable controller to receive data bit from PC.
- Transmit - Enable transmission of data from 8051 to PC.
Like this Article? Share this with others through social sites and don't forget to follow us. Post your comments and queries regarding this article below. Thank you for visiting and Enjoy Coding.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.![]()
Image may be NSFW.Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.