A microcontroller is a single-chip computer that incorporates all of the functions found in a microprocessor. It has a high concentration of on-chip facilities such as RAM, ROM, I/O ports, timers, serial ports, clock circuits, and interrupts to support various applications. Microcontrollers are utilized in remote controls, vehicle engine control systems, medical devices, power tools, office machinery, toys, and other embedded systems, among other things. This article provides an overview of the 8051 microcontrollers, as well as serial communication in the 8051 Microcontroller
INTRODUCTION TO 8051
The 8051 is designed as an effectively low-power, high-performance CMOS 8-bit microcontroller. It comes with 4K bytes of in-system programmable Flash memory manufactured using Atmel’s high-density nonvolatile memory technology. Meanwhile, it is compatible with the industry-standard 80C-51 instruction set and pinout. The on-chip Flash on the chip permits the program memory to be reprogrammed in-system. Or via a standard non-volatile memory programmer.
In this Atmel microcontroller, by combining a flexible 8-bit CPU with in-system programmable Flash on a monolithic chip, Atmel 8051 becomes an effectively powerful microcontroller. In order that it delivers a highly flexible and affordable solution to various embedded control applications. Moreover, this IC features 4K bytes of Flash, 128 bytes of RAM, 32 I/O lines, two 16-bit timer/counters, a Watchdog timer, and two data pointers. And also equipped with five vectors two-level interrupt architecture, a full-duplex serial port interface, an on-chip oscillator, and clock circuitry.
In addition to it, the 8051 is equipped with static logic for operation right down to zero frequency and supports two software selectable power-saving modes. The Idle Mode stops the functioning of the CPU allowing the RAM, timer/counters, serial port, and interrupt system to continue their operation. Whereas, the Power-down mode saves the RAM contents but freezes the oscillator. Thereby disabling all other chip functions until the next external interrupt or hardware reset. These two features make it suitable for battery-operated applications.
FEATURES OF 8051 MICROCONTROLLER:
- 8-bit CPU through two Registers A & B
- It has four register banks
- 64K bytes on-chip programmable memory (ROM)
- 128 bytes of on-chip data memory (RAM)
- The address bus is a 16-bit unidirectional
- Data bus is an 8-bit bidirectional
- 128 user-defined flags
- 16-bit Timers or Counters like T0 & T1.
- Interrupts: 5
- Program Counter – 16 bit & DPRT (Data Pointer).
- I/O Pins – 32 which are arranged like four ports such as P0, P1, P2 & P3.
- Stack Pointer (SP) – 8bit & PSW (Processor Status Word).
- Serial Data Tx & Rx for Full-Duplex Operation
- Interrupts like External-2 & Internal-3
- Oscillator & CLK Circuit.
- Control Registers like PCON, SCON, TMOD, TCON, IE, and IP.
- 32 general purpose registers each of 8-bit
- 0V to 5.5V Operating Range
- Fully Static Operation: 0 Hz to 33 MHz
- Three-level Program Memory Lock
- 32 Programmable I/O Lines
- Full Duplex UART Serial Channel
- Low-power Idle and Power-down Modes
- Interrupt Recovery from Power-down Mode
- Watchdog Timer feature
- Dual Data Pointer
- Power-off Flag
- Fast Programming Time
- Flexible ISP Programming (Byte and Page Mode)
- 8051 microcontroller offers a number of special features such as ADC, UARTs, Op-amp, etc
Serial Communication in 8051 Microcontroller
Microcontrollers need to communicate with external devices such as sensors, computers and so on to collect data for processing. Data communication is generally done by means of two methods – Parallel and Serial mode. In parallel mode, data bits are transferred faster using more data pins. But when comes to a Microcontroller, we cannot afford to dedicate many pins for data transfer. UART or Serial communication in 8051 microcontrollers will allow the controller to send and receive data just by using two pins
Serial Communication uses only two data pins to establish communication between Microcontroller and external devices. In this mode of communication, data is transferred one bit at a time. This article describes the Interfacing of 8051 with PC to establish communication through its serial port RS232.
RS232 AND MAX232:
To establish communication between a controller and PC, we must use serial I/O protocol RS-232 which was widely used in PC and several devices. PC works on RS-232 standards which operate at a logic level of -25V to +25V. But Microcontrollers use TTL logic which works on 0-5V and is not compatible with the RS-232 voltage levels.
MAX232 is a specialized IC that offers an intermediate link between the Microcontroller and PC. The transmitter of this IC will convert the TTL input level to RS-232 Voltage standards. Meanwhile, the receiver of this IC will convert RS-232 input to 5V TTL logic levels. Read the complete working of MAX232 IC.
- SCON REGISTER:
It is a bit addressable register used to set the mode in which serial communication takes place in the controller. The above figure shows the configuration of the SCON register. Here is the list of functions of each bit.
|Serial Mode of 8051|
- SM0, SM1: Serial Mode Control Bits
- SM2: Multiprocessor mode control bit, logic 1 enables Multiprocessor 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 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 hardware to indicate the end of a reception. It has to be cleared by the software.
- BAUD RATE:
It is defined as a number of bits transmitted or received per second and is 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 crystal frequency whereas for modes 1 and 3 it is determined by means of timer 1.
|Baud Rate by Timer1|
- SBUF REGISTER:
It is a 8 bit register that holds the data needed to be transmitted or the data that is received recently. The serial port of 8051 is full duplex so the microcontroller can transmit and receive data using the register simultaneously.
void initialize() // Initialize Timer 1 for serial communication
TMOD=0x20; //Timer1, mode 2, baud rate 9600 bps
TH1=0XFD; //Baud rate 9600 bps
TR1=1; //Start timer 1
void receive() //Function to receive serial data
unsigned char value;
while(RI==0); //wait till RI flag is set
RI=0; //Clear the RI flag
void transmit() // Funtion to transmit serial data
SBUF=’o’; //Load ‘o’ in SBUF to transmit
while(TI==0); //Wait till TI flag is set or data transmission ends
TI=0; //Clear TI flag
Initialize() – Initialize timer for baud rate and set the mode for serial transmission. The above program will receive a character from the PC and in return transmits “ok” back to the PC. 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 the PC through RS232.
- Initialize() – Enables the Serial communication by configuring TMOD and SCON registers.
- Receive() – Check whether the microcontroller has received data from the PC.
- Transmit() – Transmit bits ‘o’ and ‘k’ to form the message “ok” back to the PC.
I hope all of you got an idea of the 8051 microcontrollers, as well as, Serial Communication in the 8051 Microcontroller. Hope all of you find this article informative. For more queries, contact our online store-MATHA ELECTRONICS