0% found this document useful (0 votes)
5 views

UNIT I

The document compares microprocessors and microcontrollers, highlighting that microprocessors are general-purpose devices requiring external components, while microcontrollers are complete systems on a chip designed for embedded applications. It details the features and applications of 8-bit microcontrollers, particularly the 8051 architecture, including its components, memory organization, and instruction set. The document also covers programming concepts, parallel port programming, and specific characteristics of the 8051 microcontroller's ports.

Uploaded by

learner22032000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

UNIT I

The document compares microprocessors and microcontrollers, highlighting that microprocessors are general-purpose devices requiring external components, while microcontrollers are complete systems on a chip designed for embedded applications. It details the features and applications of 8-bit microcontrollers, particularly the 8051 architecture, including its components, memory organization, and instruction set. The document also covers programming concepts, parallel port programming, and specific characteristics of the 8051 microcontroller's ports.

Uploaded by

learner22032000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

UNIT-I 8 BIT EMBEDDED PROCESSOR

Microcontroller vs Microprocessor

Microprocessor
• A CPU (Central Processing Unit) on a single chip
• General-purpose device
• Needs external components for:
o RAM
o ROM
o I/O ports
o Timers, etc.
• Used in computing applications like:
o PCs
o Laptops
o Servers

Characteristics

• No on-chip memory for program/data


• High processing power
• Suitable for complex calculations
• Expensive and high power consumption
• Example: Intel 8085, 8086, Pentium, i3/i5/i7

Microcontroller
• A complete computer on a chip
• Contains:
o CPU
o RAM
o ROM (Flash)
o I/O ports
o Timers/Counters
o ADC/DAC
• Used in embedded applications like:
o Washing machines
o Microwave ovens
o IoT devices
o Robotics

Characteristics

• All components on one chip


• Low cost, low power consumption
• Real-time control capability
• Ideal for specific tasks
• Example: 8051, ATmega328 (Arduino), PIC, ARM Cortex-M

Comparison Table
Feature Microprocessor Microcontroller
Application General purpose Embedded systems
On-chip Memory No Yes (RAM, ROM)
I/O Ports External Built-in
Cost High Low
Power Consumption High Low
Speed High (GHz) Medium (MHz)
Development Complex (more parts) Simple (single chip)
Example Devices Intel i7, AMD Ryzen 8051, Arduino, STM32

Summary
• Use Microprocessors for computing-heavy tasks (PCs, servers).
• Use Microcontrollers for device control in embedded systems.

8-bit Microcontroller

Definition
An 8-bit microcontroller is a microcontroller whose data bus and ALU are 8-bits wide,
meaning it processes 8 bits of data at a time.

Key Features
• 8-bit ALU → processes 8-bit data
• 8-bit Data Bus
• 16-bit Address Bus (can access 64KB memory)
• On-chip ROM, RAM, I/O ports, Timers, Counters
• Typically includes:
o UART/USART (for serial communication)
o ADC (Analog to Digital Converter)
o Interrupt controller
• Operates in the MHz range
• Low power consumption

Examples of 8-bit Microcontrollers


Microcontroller Manufacturer Notes
8051 Intel Most popular legacy MCU
ATmega328 Microchip (Atmel) Used in Arduino UNO
PIC16F877A Microchip Used in various projects

8051 Microcontroller Overview


• Released by Intel in 1980
• 4K ROM, 128 bytes RAM
• 2 Timers, Serial port, 4 I/O ports
• 5 interrupt sources

Applications of 8-bit Microcontrollers


• Home automation systems
• Consumer electronics (TVs, washing machines)
• Automotive (dashboard display, indicators)
• Industrial control systems
• IoT devices
• Robotics

Advantages
• Low cost
• Simple instruction set (easy to program)
• Compact and reliable
• Suitable for small embedded applications

Limitations
• Slower than 16/32-bit MCUs
• Limited memory and peripheral support
• Not suitable for complex computations (like image/video processing)

Summary
• 8-bit microcontrollers are ideal for simple, low-power embedded systems.
• Still widely used due to low cost, ease of use, and availability.

Sure! Here’s a detailed point-wise explanation of the 8051 Microcontroller Architecture


based on the info from the GeeksforGeeks article you referenced — clear and exam-friendly
without diagrams.

8051 Microcontroller Architecture (Detailed


Explanation)

1. Overview
• The 8051 microcontroller is an 8-bit microcontroller developed by Intel.
• It is a Harvard architecture MCU with separate memory spaces for program and
data.
• Uses 8-bit ALU and registers.
• Has a 16-bit address bus for program memory (up to 64KB) and data memory.

2. Main Components of 8051 Architecture


2.1 CPU (Central Processing Unit)

• Executes instructions and controls operations.


• Contains an 8-bit ALU for arithmetic and logic operations.
• Contains Accumulator (A) and B registers (special purpose).
• Program Counter (PC) holds address of next instruction.
• Stack Pointer (SP) points to stack location.
• Data Pointer (DPTR) used for external memory access.

2.2 Memory Organization

• On-chip Program Memory (ROM/Flash): 4KB internal code memory.


• On-chip Data Memory (RAM): 128 bytes internal RAM.
• Separate memory buses for code and data (Harvard architecture).
• Supports external program memory (up to 64KB).
• Supports external data memory (up to 64KB).

2.3 Register Banks

• Four banks of registers (Bank 0 to Bank 3).


• Each bank has 8 registers: R0 to R7.
• Only one register bank active at a time.
• Selectable via PSW (Program Status Word) register bits (RS1, RS0).

2.4 Special Function Registers (SFRs)

• Memory-mapped registers controlling hardware peripherals and CPU functions.


• Examples: ACC (Accumulator), B, PSW, SP, DPTR, TCON, TMOD, IE, IP, SCON,
P0-P3 (I/O ports).
• Located in the upper 128 bytes of internal RAM.

2.5 Input/Output Ports

• Four 8-bit bidirectional I/O ports: P0, P1, P2, P3.


• Used to interface with external devices.
• Each port can be used individually as input or output.
• Ports have internal pull-up resistors (except P0).

2.6 Timers/Counters
• Two 16-bit timers/counters: Timer 0 and Timer 1.
• Can be configured as timer (count internal clock pulses) or counter (count external
events).
• Used for measuring time intervals, generating baud rates, etc.

2.7 Serial Communication

• Full-duplex serial communication via UART.


• Controlled by SCON (Serial Control) register.
• Supports asynchronous and synchronous modes.

2.8 Interrupt System

• 5 sources of interrupts:
1. External Interrupt 0 (INT0)
2. Timer 0 Overflow
3. External Interrupt 1 (INT1)
4. Timer 1 Overflow
5. Serial Communication Interrupt
• Interrupts can be enabled/disabled via IE (Interrupt Enable) register.
• Priorities assigned via IP (Interrupt Priority) register.

2.9 Oscillator and Clock Circuit

• On-chip oscillator driven by external crystal (commonly 11.0592 MHz).


• Provides clock pulses for MCU operations.
• Divides clock frequency internally for machine cycles.

3. Block Diagram
4. Key Architectural Features
• Harvard Architecture: Separate code and data memories improve speed.
• Bit Addressable Memory: Allows individual bit manipulation in certain RAM areas
and SFRs.
• Power Saving Modes: Idle and Power-down modes for low power consumption.
• Stack: Uses internal RAM; stack grows upward from address 08H.

5. Working Flow
• Fetch instruction from program memory.
• Decode and execute instruction using CPU.
• Use ALU for arithmetic and logic.
• Access data from internal/external RAM via data bus.
• Use peripherals as per instruction or interrupts.

Instruction Set and Programming


1. Instruction Set
Definition:

• A collection of machine-level commands that a processor can execute.


• Defines operations CPU can perform (data transfer, arithmetic, logic, control).

Types of Instructions:

Type Description Example


Data Transfer Move data between registers, memory MOV, LOAD, STORE
Arithmetic Perform math operations ADD, SUB, MUL, DIV
Logical Perform bitwise operations AND, OR, XOR, NOT
Control Change flow of execution JMP, CALL, RET, JZ (jump if zero)

Instruction Format:

• Usually contains opcode (operation code) and operand(s) (data or address).


• Example: MOV R1, #05 (Move immediate value 5 to register R1).

2. Types of Instruction Sets


Type Description
CISC (Complex Instruction Set
Many complex instructions, variable length.
Computer)
RISC (Reduced Instruction Set Few simple instructions, fixed length, faster
Computer) execution.

3. Programming Embedded Systems


Languages Used:

• Assembly Language: Low-level, direct hardware control, faster, hardware-specific.


• Embedded C: Higher-level, portable, easier to maintain, widely used.
• C++ / Python: Used in advanced embedded applications.

Programming Concepts:

• Direct register manipulation: Using instructions to access hardware registers.


• Bitwise operations: For setting, clearing, toggling bits.
• Interrupt handling: Programming ISRs (Interrupt Service Routines).
• Memory management: Managing stack, heap, and data segments.
• Timing control: Using timers, delays, real-time constraints.

4. Sample Embedded C Instructions


Instruction Function
PORTA = 0xFF; Set all pins of PORTA as HIGH
if (PINA & 0x01) Check if the first pin of PORTA is HIGH
TIMER0_OVF_vect() ISR for Timer0 overflow

5. Important Notes
• Efficiency matters: Code size and speed are crucial in embedded.
• Use hardware-specific headers to access registers.
• Debugging often done via simulators or hardware debuggers.
• Interrupts and concurrency require careful programming.

Types of Instructions in Embedded


Systems

1. Arithmetic Instructions
Purpose:

• Perform mathematical operations on data.

Common Instructions:
Instruction Function Example
ADD Adds two operands ADD R1, R2 (R1 = R1 + R2)
SUB Subtracts one operand from another SUB R3, #5 (R3 = R3 - 5)
MUL Multiplies operands MUL R1, R2
DIV Divides operands DIV R4, R5
INC Increment operand by 1 INC R1
DEC Decrement operand by 1 DEC R2
NEG Negates (two’s complement) NEG R1

2. Logical Instructions
Purpose:

• Perform bitwise logical operations.

Common Instructions:

Instruction Function Example


AND Bitwise AND AND R1, R2
OR Bitwise OR OR R3, R4
XOR Bitwise Exclusive OR XOR R5, R6
NOT Bitwise NOT (complement) NOT R1
SHL Shift left bits SHL R1, #2 (shift left by 2 bits)
SHR Shift right bits SHR R1, #1
ROL Rotate bits left ROL R2
ROR Rotate bits right ROR R3

3. Data Transfer Instructions


Purpose:

• Move data between registers, memory, and I/O ports.

Common Instructions:

Instruction Function Example


MOV Move data between registers/memory MOV R1, R2
LOAD Load data from memory to register LOAD R1, [0x1000]
STORE Store data from register to memory STORE R2, [0x2000]
PUSH Push register/data onto stack PUSH R1
POP Pop data from stack to register POP R2
Instruction Function Example
IN Input from I/O port to register IN R1, PORTA
OUT Output from register to I/O port OUT PORTB, R2

4. Branch (Control Transfer) Instructions


Purpose:

• Change the sequence of instruction execution (branching, loops, function calls).

Common Instructions:

Instruction Function Example


JMP Unconditional jump to address JMP 0x3000
CALL Call subroutine/function CALL subroutine_label
RET Return from subroutine RET
JZ / JE Jump if zero / equal (based on flag) JZ label
JNZ / JNE Jump if not zero / not equal JNZ label
JC Jump if carry JC label
JNC Jump if no carry JNC label

5. Bit-Oriented Instructions
Purpose:

• Operate on individual bits in registers or memory locations.

Common Instructions:

Instruction Function Example


SETB Set bit (make it 1) SETB P1.0 (set bit 0 of Port 1)
CLR Clear bit (make it 0) CLR P1.1
CPL Complement bit (toggle) CPL P2.3
JB Jump if bit is set (1) JB P1.0, label
JNB Jump if bit is not set (0) JNB P3.2, label
ANL AND with bit mask ANL P1, #0x0F
ORL OR with bit mask ORL P2, #0xF0
Programming Parallel Ports

What is Parallel Port?

• Parallel port is a communication interface that transfers multiple bits simultaneously


(usually 8 bits).
• Used to connect microcontrollers to external devices like LEDs, switches, LCDs.

Characteristics:

• Consists of multiple data lines (usually 8).


• Faster data transfer compared to serial ports.
• Can be configured as input or output ports.

Basic Parallel Port Programming:

• Configure port direction (input/output).


• Write data to port to send signals.
• Read data from port to receive signals.

Example pseudo-steps:

1. Set port direction registers (e.g., DDRx in AVR).


2. Write data (e.g., PORTx = 0xFF to turn all pins HIGH).
3. Read data (e.g., PINx to read input pins).

8051 Microcontroller Port


Programming

About 8051 Ports:

• 8051 has 4 parallel I/O ports: P0, P1, P2, P3.


• Each port is 8-bit wide (8 pins).
• Ports can be used as input or output.
• Ports P0 and P2 also serve as multiplexed address/data buses.

Port Characteristics:

Port Pins Special Function Notes


P0 8 AD0-AD7 (Address/Data multiplexed) Requires external pull-ups
Port Pins Special Function Notes
P1 8 General purpose I/O Internal pull-ups
P2 8 Higher order address lines (A8-A15) Also used for external memory
P3 8 I/O + Special functions UART, interrupts, timers, etc.

Port Programming Basics:

• Ports are bidirectional.


• To output data: Write value to the port register (e.g., MOV P1, #0xFF sets all pins
HIGH).
• To input data: Read from the port register (e.g., MOV A, P1 reads input from port 1).
• Ports P1, P2, P3 have internal pull-ups; P0 does not, so external pull-ups are needed.

Simple Example: Toggle all pins of Port 1 in Assembly


MOV P1, #0FFH ; Set all pins of Port 1 to HIGH
HERE: CPL P1 ; Complement (toggle) all bits of Port 1
SJMP HERE ; Infinite loop

Pin Configuration of 8051 / 8031


Microcontroller

Pin Count: 40 Pins in DIP Package


Important Pins and Their Functions:

Pin
Pin Name Function Description
Number
1-8 P1.0–P1.7 Port 1 I/O pins — general purpose I/O with internal pull-ups
9 RST Reset pin — active high, resets the MCU on logic 1
Port 3 I/O pins — with alternate functions (UART, interrupts,
10-17 P3.0–P3.7
timers)
XTAL2,
18-19 Crystal oscillator pins — connect crystal/resonator
XTAL1
20 GND Ground pin
Port 2 I/O pins — high byte address bus in external memory
21-28 P2.0–P2.7
mode
Program Store Enable — read signal for external program
29 PSEN
memory
Address Latch Enable — latch demultiplexes address/data on
30 ALE
Port 0
External Access Enable — enable external program memory
31 EA
(active low)
Port 0 I/O pins — low byte address/data bus in external memory
32-39 P0.0–P0.7
mode (no internal pull-ups)
40 VCC Power supply +5V

Special Functions of Port 3 Pins

Pin Port Special Function


10 P3.0 RXD (UART Receive)
11 P3.1 TXD (UART Transmit)
12 P3.2 INT0 (External Interrupt 0)
13 P3.3 INT1 (External Interrupt 1)
14 P3.4 T0 (Timer 0 external input)
15 P3.5 T1 (Timer 1 external input)
16 P3.6 WR (External memory write)
17 P3.7 RD (External memory read)

Notes:

• Port 0 pins require external pull-up resistors when used as I/O.


• Ports 1, 2, and 3 have internal pull-ups.
• The 8031 is a variant without on-chip ROM; 8051 has on-chip ROM.
• External memory interface is used when program or data memory exceeds internal
limits.

Summary:
Topic Key Points
Parallel Port Multiple bits transferred simultaneously, configure direction,
Programming read/write data.
4 ports (P0-P3), each 8 bits, some with special functions, P0 needs
8051 Ports
external pull-ups.
Write to port for output, read from port for input; internal/external
Port Programming
pull-ups important.
40-pin IC; pins assigned to ports, reset, oscillator, memory control,
Pin Configuration
and special functions.

8051 Timers

Introduction
• 8051 Microcontroller has two 16-bit timers:
o Timer 0
o Timer 1
• Can operate as:
o Timers – count internal clock pulses.
o Counters – count external events (via T0 and T1 pins).
• Used for generating delays, baud rates, event counting, etc.

Timer Registers
Each timer uses two 8-bit registers:

• TL0 & TH0 → Timer 0 Low & High byte


• TL1 & TH1 → Timer 1 Low & High byte
Important Registers
1. TMOD (Timer Mode Register) – 8-bit

Used to configure Timer 0 and Timer 1.

Bits Use
GATE 1: External interrupt start
C/T 0 = Timer, 1 = Counter
M1,M0 Select mode (0 to 3)
| GATE | C/T | M1 | M0 | GATE | C/T | M1 | M0 |
T1 T0

2. TCON (Timer Control Register) – 8-bit

Used to control the start/stop and overflow of timers.

Bit Name Function


TF1 Timer 1 overflow flag
TR1 Timer 1 run control
TF0 Timer 0 overflow flag
TR0 Timer 0 run control

Timer Modes (via TMOD)


Mode M1 M0 Description
0 00 13-bit timer mode (used rarely)
1 01 16-bit timer mode (full TH and TL used)
2 10 8-bit auto-reload mode (used in baud rate generation)
3 11 Split mode – Timer 0 splits into two 8-bit timers

How Timers Work


• When enabled (TR0/TR1 = 1), the timer register increments on each machine cycle.
• When the timer overflows:
o TF0 or TF1 is set.
o Can trigger an interrupt (if enabled).

Timer Clock
• 8051 uses a 12 MHz crystal.
• 1 machine cycle = 12 clock cycles → Timer increments every 1 µs.
• Max count in 16-bit mode = 65536 → Delay = 65536 µs = 65.5 ms

Applications of Timers
• Generating time delays
• Creating waveforms (square wave, etc.)
• Counting external pulses
• Baud rate generation for serial communication
• Measuring pulse width

Example: Delay Generation using Timer 0


• Mode 1 (16-bit), Timer 0
• Load TH0 & TL0 for desired delay
• Start Timer (TR0 = 1)
• Wait for TF0 = 1
• Stop timer, clear TF0

8051 Serial Ports

Introduction
• The 8051 microcontroller has one full-duplex serial port.
• Used for asynchronous (UART) and synchronous communication.
• Data transmission and reception is serial (bit-by-bit).
• Controlled by SBUF, SCON, PCON, and Timer 1.

Key Registers Used


1. SBUF (Serial Buffer Register)
Purpose Operation
Transmit Write data to SBUF → sends via TXD pin
Receive Read data from SBUF ← received via RXD pin

2. SCON (Serial Control Register – 8-bit)

Bit Name Function


7 SM0 Serial mode bit 0
6 SM1 Serial mode bit 1
5 SM2 Used in multiprocessor communication
4 REN Receiver Enable (1 = enable reception)
3 TB8 9th bit for transmission in Modes 2 & 3
2 RB8 9th bit received in Modes 2 & 3
1 TI Transmit Interrupt Flag (1 = transmit done)
0 RI Receive Interrupt Flag (1 = receive done)

3. PCON (Power Control Register)

• Bit 7 = SMOD
o If SMOD = 1, doubles baud rate in Modes 1, 2, and 3.

Serial Communication Pins


Pin Function
TXD (P3.1) Transmit serial data
RXD (P3.0) Receive serial data

Serial Communication Modes in 8051


Mode SM0 SM1 Description Baud Rate Type
0 00 8-bit Shift Register (sync) Fixed (Osc/12)
1 01 8-bit UART (async) Variable (Timer 1)
2 10 9-bit UART with fixed baud Fixed (Osc/64 or /32)
3 11 9-bit UART with variable baud Variable (Timer 1)

Baud Rate (Mode 1 Example)


• Formula:

Baud Rate=2SMOD32×(Timer 1 Overflow Rate12)\text{Baud Rate} =


\frac{2^{\text{SMOD}}}{32} \times \left(\frac{\text{Timer 1 Overflow
Rate}}{12}\right)

• Timer 1 must be in Mode 2 (auto-reload) for baud rate generation.

Serial Communication Process


Transmission

1. Load data into SBUF


2. Hardware sends bit-by-bit via TXD
3. TI flag is set when transmission completes

Reception

1. Data is received via RXD


2. Hardware loads it into SBUF
3. RI flag is set

Applications of Serial Port in 8051


• Communication with:
o PC via RS232
o GSM, GPS modules
o Bluetooth, Wi-Fi modules
• Data logging and monitoring
• Remote device control

Interrupt Handling in 8051

1. Introduction to Interrupts
• Interrupt: A signal to the CPU to pause current execution and jump to a special
routine (Interrupt Service Routine - ISR).
• Allows the microcontroller to respond immediately to important events.
• Improves efficiency by avoiding continuous polling.

2. Types of Interrupts in 8051


8051 supports 5 interrupt sources:

Interrupt Source Vector Address Priority Level Type


External Interrupt 0 (INT0) 0003H High/Low Edge/Level triggered
Timer 0 Overflow 000BH High/Low Level triggered
External Interrupt 1 (INT1) 0013H High/Low Edge/Level triggered
Timer 1 Overflow 001BH High/Low Level triggered
Serial Communication 0023H High/Low Level triggered

3. Interrupt Vector Table


• Each interrupt has a fixed vector address where the CPU jumps to execute the ISR.
• Vector addresses start from 0003H and increment by 8 (except for serial interrupt
which is at 23H).

4. Enabling and Disabling Interrupts


• Controlled by IE (Interrupt Enable) register.
• IE bits:

Bit Bit
Bit 7 (EA) 6 Bit 5 (ES) Bit 4 (ET1) Bit 3 (EX1) Bit 2 (ET0) Bit 1 (EX0) 0
(—) (—)
Global Serial Timer 1 External Timer 0 External
enable/disable — Interrupt Interrupt Interrupt 1 Interrupt Interrupt 0 —
interrupt Enable Enable Enable Enable Enable

• EA = 1 enables all interrupts.


• Individual interrupts enabled by setting corresponding bits (EX0, ET0, etc.).

5. Interrupt Priority
• Managed by IP (Interrupt Priority) register.
• Allows assigning high or low priority to each interrupt.
• Higher priority interrupt can interrupt a lower priority ISR.
• Bits in IP register correspond to interrupts similar to IE.

6. Types of Interrupt Triggers


• External Interrupts (INT0 & INT1):
o Can be level triggered (active low) or edge triggered (falling edge).
o Controlled by IT0 and IT1 bits in the TCON register.
• Timer and Serial Interrupts:
o Triggered when timer overflows or serial transmission/reception completes.

7. Interrupt Control Registers


Register Purpose
IE Interrupt Enable register
IP Interrupt Priority register
TCON Timer Control register (for external interrupt triggers and timer flags)

8. Interrupt Handling Process


1. Interrupt Request: Interrupt signal received.
2. Interrupt Enable Check: CPU checks IE register for global and individual interrupt
enables.
3. Priority Check: CPU compares priority if multiple interrupts.
4. Save Context: CPU saves program counter and flags.
5. Execute ISR: CPU jumps to the interrupt vector address.
6. Return from Interrupt: ISR ends with RETI (Return from Interrupt) instruction.
7. Restore Context: CPU resumes main program execution.

9. Interrupt Flags and Registers


• TCON Register (Timer Control and Interrupt Flags):

Bit Name Description


7 TF1 Timer 1 Overflow Flag
6 TR1 Timer 1 Run Control
5 TF0 Timer 0 Overflow Flag
Bit Name Description
4 TR0 Timer 0 Run Control
3 IE1 External Interrupt 1 Edge Flag
2 IT1 External Interrupt 1 Type
1 IE0 External Interrupt 0 Edge Flag
0 IT0 External Interrupt 0 Type

• Flags are set when interrupt occurs, cleared by hardware or software.

10. Programming Interrupts in 8051


• Steps to use interrupts:
1. Set interrupt enable (IE) bits.
2. Configure interrupt priority (IP) if needed.
3. Configure external interrupt triggers (IT0, IT1 bits).
4. Write the Interrupt Service Routine (ISR) at the vector address.
5. Use RETI at the end of ISR.
6. Enable global interrupts by setting EA=1.

11. Advantages of Interrupts


• Immediate response to events.
• Efficient CPU usage (no polling).
• Supports multitasking and real-time processing.
• Facilitates communication with peripherals.

12. Summary
• 8051 has 5 interrupt sources with vector addresses.
• Controlled by IE and IP registers.
• Supports priority and nested interrupts.
• Interrupts improve real-time capabilities.

You might also like