fbpx

Serial Communication In 8051 (UART/USART)

8051 has one of the powerful features is UART it is also know as serial communication.

  • In 8051 has integrated serial port means that you may very easily read and write values to serial port.
  • If integrated serial port is not present it would be tedious process.
  • We need to simply configure the serial ports operation mode and baud rate.
  • UART its name implies it is universal.
  • It can establish a communication between a microcontroller and another devices such as Bluetooth,GSM,GPS,RF module, Personal computer.
  • UART port of a microcontroller can be used to interface to a RS232 port of a personal computer, hence voltage level of UART must be converted to voltage level compatible to RS232.
  • To convert UART voltage level to RS232 voltage level ,you may use max232.
  • Other devices with UART ports such as GSM module, GPS module, Bluetooth module, RF module does not require the UART converter.
  • This devices can be interface to microcontroller directly as long as voltage level for both end are compatible with each other.

Type Of Communication

  • Device transmit and receive data in two way communication
    1.Parallel Communication,
    2.Serial Communication.

Parallel Communication

  • Multiple data bits are transmit and receive simultaneously.
  • It is used for point to point communication.
  • Wireless communication is not possible.

Serial Communication

  • It sends data one bit at a time,sequentially,over a communication channel.
  • It require only one data bus.
  • Wireless communication is possible.

Uart

  • Universal Asynchronous Receiver Transmitter allow serial communication between two system having different clock frequencies.
  • In 8051 Data is received and transmitted through RXD and TXD Pins.
  • 8051 provides two registers to access serial communication
    1.SCON.
    2.SBUF.

Circuit

SCON Registor

Code

 #include <REGX51.H>
 char A;
 // Initialize uart
 void uart()
 {
 TMOD=0X02;    // 16 BIT TIMER
 TH1=0XFD;    // 9600 BAUD RATE
 TR1=1;
 SCON=0X50;
 }
 // Syntax to transmit data over uart
 void transmit(unsigned char a)
 {
 SBUF=a;
 while(TI==0);    // WAIT UNTIL DATA TRANSMIT
 TI=0;
 }
 // Syntax to receive data over uart
 void receive()
 {
 while(RI==0);    // WAIT UNTIL DATA RECEIVE
 A=SBUF;
 }
 void main()
 {
 uart();
 transmit();
 receive();
 } 

Leave a Reply

Your email address will not be published. Required fields are marked *