8051 microcontroller and embedded applications — Unit 5 Notes (Microprocessors and Microcontrollers)

BCS605 · Unit 5

8051 microcontroller and embedded applications notes — Unit 5

Free unit-wise study notes on 8051 microcontroller and embedded applications for Microprocessors and Microcontrollers, Semester 6 of B.Tech — Computer Science & Engineering — key concepts, examples, important questions and a revision checklist for semester exams.

8051 microcontroller and embedded applications

Notebook — 14 pages

Page 1

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

1. Microprocessors vs Microcontrollers

While they sound similar, microprocessors (like the 8086 or Intel Core i9) and microcontrollers (like the 8051 or Arduino/AVR) serve entirely different purposes.

1.1 The Microprocessor (CPU)

It is just the processing engine. It contains NO RAM, NO ROM, and NO I/O ports on the chip itself. You must solder external RAM, ROM, and I/O chips onto a motherboard to make a working system. It is designed for general-purpose, high-performance computing (PCs, laptops).

Next — The Microcontroller

1 of 14

Page 2

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

2. The Microcontroller (MCU)

2.1 System on a Chip

A microcontroller integrates the CPU, a small amount of RAM, ROM (Flash memory for the program), I/O ports, timers, and serial ports all onto a single silicon chip.

It is a complete, self-contained computer. You just apply power, and it runs.

2.2 Embedded Systems

Because they are compact and incredibly cheap, MCUs are used for dedicated embedded applications where high processing power is unnecessary. They run washing machines, microwaves, TV remotes, and car engine control units.

Next — 8051 Architecture

2 of 14

Page 3

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

3. Introduction to the 8051

Designed by Intel in 1981, the 8051 is an 8-bit microcontroller. Despite its age, its architecture forms the basis for thousands of modern derivatives still used heavily in industry today.

3.1 Key Specifications of the Original 8051

  • 8-bit ALU and Accumulator.
  • 4 KB of internal ROM (for program storage).
  • 128 bytes of internal RAM (for variables).
  • Four 8-bit I/O ports (32 total I/O pins).
  • Two 16-bit Timer/Counters.
  • One full-duplex Serial Port.

Next — 8051 Memory Organization

3 of 14

Page 4

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

4. 8051 Memory Organization

Unlike the 8085/8086 which use a single unified memory space (Von Neumann architecture), the 8051 uses a Harvard Architecture. It has strictly separate memory spaces for Programs (ROM) and Data (RAM).

4.1 Program Memory (ROM)

The internal ROM is 4 KB (addresses 0000H to 0FFFH). The Program Counter (PC) only points to this memory space. If a program is larger than 4 KB, the 8051 can address up to 64 KB of external ROM.

Next — Data Memory

4 of 14

Page 5

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

5. 8051 Data Memory (RAM)

The internal RAM is 128 bytes (addresses 00H to 7FH). It is highly compartmentalized to maximize efficiency.

5.1 The RAM Map

  • Register Banks (00H to 1FH): 32 bytes divided into four banks of 8 registers (R0-R7). Only one bank is active at a time (selected via the PSW register). Highly efficient for fast context switching during interrupts.
  • Bit-Addressable RAM (20H to 2FH): 16 bytes. The 8051 has a unique feature: it can mathematically manipulate individual bits (boolean logic) in this memory area. It contains 128 individually addressable bits.
  • General Purpose RAM (30H to 7FH): 80 bytes used for the Stack and general variables.

Next — Special Function Registers

5 of 14

Page 6

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

6. Special Function Registers (SFRs)

The 8051 controls its internal hardware (Timers, Serial ports, I/O ports) using Special Function Registers located in a memory space directly above the internal RAM (addresses 80H to FFH).

6.1 Key SFRs

  • ACC (Accumulator): Math operations.
  • B Register: Used in conjunction with ACC for multiplication and division.
  • PSW (Program Status Word): The flag register (Carry, Zero, etc.).
  • P0, P1, P2, P3: Writing data to these SFR addresses literally changes the voltage on the physical pins of the microchip.

Next — 8051 I/O Ports

6 of 14

Page 7

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

7. 8051 I/O Ports

The 8051 has four 8-bit ports (P0, P1, P2, P3), totaling 32 pins. Unlike the 8255 which requires complex configuration software, 8051 ports are 'quasi-bidirectional'.

7.1 How they work

To use a pin as an Input, you simply write a '1' to it. This activates an internal pull-up resistor. The external hardware can then pull the pin low to send a '0'. To use it as an Output, you just write your data (0 or 1) to the port register.

7.2 Alternate Functions

To save pins, Port 3 pins have dual purposes. P3.0 is RXD (Serial Receive), P3.1 is TXD, P3.2 is external interrupt 0, etc. If you need serial comms, you lose those two I/O pins.

Next — 8051 Timers

7 of 14

Page 8

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

8. 8051 Timers and Counters

The 8051 has two 16-bit Timer/Counters (Timer 0 and Timer 1).

8.1 Timer vs Counter

Inside, they are just 16-bit registers (TH0 and TL0) that increment.

  • Timer Mode: The register increments automatically based on the internal oscillator clock. Used to generate precise time delays without wasting CPU cycles in software loops.
  • Counter Mode: The register increments when a pulse is received on an external pin (T0 or T1). Used to count external events (e.g., counting products on a conveyor belt).

Next — Timer Operation

8 of 14

Page 9

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

9. Timer Operation and Interrupts

9.1 Overflows

A 16-bit timer counts from 0000H to FFFFH. When it hits FFFFH and increments one more time, it rolls over to 0000H. This is called an Overflow.

When an overflow occurs, it sets a hardware flag (TF0). The programmer can configure the 8051 so that this overflow triggers an Interrupt. This allows the CPU to run its main program, and every exactly 10 milliseconds, the timer interrupts it to run a brief subroutine (e.g., checking a sensor).

Next — 8051 Serial Communication

9 of 14

Page 10

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

10. 8051 Serial Communication

The 8051 has a built-in UART (Universal Asynchronous Receiver-Transmitter), eliminating the need for an external chip like the 8251.

10.1 The SBUF Register

Serial communication is handled via the SBUF (Serial Buffer) SFR.

To transmit data, the software simply executes `MOV SBUF, A`. The hardware automatically takes that byte, adds start/stop bits, and shifts it out of the TXD pin at a specific baud rate. When a byte is received on the RXD pin, the hardware strips the bits and places the clean byte in SBUF, triggering a 'Receive Interrupt'.

Next — Baud Rate Generation

10 of 14

Page 11

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

11. Baud Rate Generation

In asynchronous serial communication (like RS-232), the sender and receiver do not share a clock line. They must both agree beforehand on the speed of transmission (the Baud Rate, bits per second).

11.1 Using Timer 1

The 8051 UART does not have a dedicated baud rate generator. It uses Timer 1 to generate the baud rate clock. The programmer must configure Timer 1 in 'Auto-Reload' mode, load a specific calculated number into the timer register, and start the timer. The overflow rate of the timer dictates the baud rate.

Next — Embedded App: LED Interfacing

11 of 14

Page 12

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

12. Embedded App: Interfacing LEDs

The most basic embedded application. Eight LEDs are connected to Port 1.

12.1 Program: Blinking LEDs

```asm
MAIN: MOV A, #00H ; Load Accumulator with 00000000 (Binary)
MOV P1, A ; Send to Port 1 (Turns LEDs ON if sinking current)
ACALL DELAY ; Call a delay subroutine
MOV A, #FFH ; Load Accumulator with 11111111 (Binary)
MOV P1, A ; Send to Port 1 (Turns LEDs OFF)
ACALL DELAY
SJMP MAIN ; Short Jump back to MAIN (Infinite loop)
```

Next — Embedded App: LCD Interfacing

12 of 14

Page 13

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

13. Embedded App: Interfacing an LCD

Interfacing a standard 16x2 alphanumeric LCD display (like the HD44780).

13.1 The Connections

The LCD requires an 8-bit data bus (connected to Port 1) and three control pins: Register Select (RS), Read/Write (RW), and Enable (E), connected to Port 2.

13.2 Command vs Data

If RS=0, the data sent on Port 1 is treated as a Command (e.g., 'Clear Screen', 'Move cursor to line 2'). If RS=1, the data is treated as a character to be printed on the screen (e.g., sending the ASCII code for the letter 'A').

Next — Embedded App: Stepper Motor

13 of 14

Page 14

Wink Notes

B.Tech CSE — 6th Semester

Microprocessors and Microcontrollers

Unit - 5

14. Embedded App: Stepper Motor Interfacing

A stepper motor rotates in discrete steps rather than spinning continuously. Used in robotics, 3D printers, and disk drives for precise positioning.

14.1 The Control Sequence

The motor has 4 magnetic coils. To rotate it, the 8051 must send a specific repeating sequence of 4-bit binary codes to a motor driver IC (like the ULN2003, because the 8051 cannot supply enough current to drive a motor directly).

Sequence (Full Step): `1000`, `0100`, `0010`, `0001`. Sending this sequence via a port rotates the motor forward. Reversing the sequence rotates it backward. The speed of rotation is controlled by the software delay inserted between sending each code.

14 of 14

Continue in this subject