Microcontroller
Dr. Hemant Singh Pokhariya
Associate Professor
CSE Dept.
GEU Dehradun
Microprocessor Based System
• CPU
• External RAM, ROM, I/O etc..
2
Microcontroller
• A smaller computer on a CHIP
• On-chip RAM, ROM, I/O Ports, Timer, Serial Controller
• Example: 8051,Arduino Uno, and Raspberry.
3
Microprocessor VS. Microcontroller
Microcontroller (µC) Microprocessor (µP)
Feature
Designed for Designed for general-purpose
Purpose
specific applications computing applications
CPU, RAM, ROM, I/O and CPU is stand-alone, RAM,
Architecture
timer are all on a single chip ROM, I/O, timer are separate
Power Consumption Lower power Higher power
Instruction set Fixed instruction set More flexible
It uses Von Neumann
Architecture Type It uses Harvard Architecture.
Architecture.
Cost Lower cost Higher cost
Applications Embedded systems General-purpose
Example Television Personal Computers
Lower clock speed, typically Higher clock speed, typically
Clock speed
less than 100 MHz greater than 1 GHz 4
Features of 8051
• 8 bit Processor
• 4KB Internal ROM
• 128 Bytes Internal RAM
• Four 8 bit I/O PORTS (32 I/O LINES)
• Two 16 Bit Timers/Counters
• On Chip Full Duplex UART for Serial Communication
• 5 Vector Interrupts ( 2 External, 3 Internal -
Timer0,Timer1,Serial)
• On Chip Clock Oscillator
• 16 bit Address bus
64k External Code Memory
64k External Data Memory
5
Block Diagram of 8051
8051 Microcontroller 6
Pin Diagram
8051 Microcontroller 7
RST
• RESET pin is an input and is active high (normally low)
• Upon applying a high pulse to this pin, the microcontroller will
reset and terminate all activities
• This is often referred to as a power-on reset
• Activating a power-on reset will cause all values in the registers to
be lost
8
EA’
• EA’, “external access’’, is an input pin and must be
connected to Vcc or GND
• The 8051 family members all come with on-chip ROM
to store programs and also have an external code and
data memory.
• Normally EA pin is connected to Vcc (Internal Access)
• EA pin must be connected to GND to indicate that the
code or data is stored externally.
9
PSEN’ and ALE
• PSEN, “program store enable’’, is an output pin
• This pin is connected to the OE pin of the external
memory.
• For External Code Memory, PSEN’ = 0
• For External Data Memory, PSEN’ = 1
• ALE pin is used for demultiplexing the address and
data.
10
I/O Port Pins
• The four 8-bit I/O ports P0, P1, P2
and P3 each uses 8 pins.
• All the ports upon RESET are
configured as output, ready to be
used as input ports by the external
device.
11
Port 0
• Port 0 is also designated as AD0-AD7.
• The 8051 multiplexes address and data
through port 0 to save pins.
• ALE indicates if P0 has address or data.
– When ALE=0, it provides data D0-D7
– When ALE=1, it has address A0-A7
12
Port 1 and Port 2
• Both P1 and P2 are used as simple I/O.
• Port 2 must be used along with P0 to provide
the 16-bit address for the external memory.
13
Port 3
• Port 3 can be used as input or output.
• Port 3 has the additional function of
providing some extremely important
signals
14
8051 Memory Structure
External
External
60K
64K 64K
SFR
EXT INT 4K
128
EA = 0 EA = 1 Internal
Code Memory Data Memory
15
128 Byte RAM
• There are 128 bytes of RAM in the 8051.
– Assigned addresses 00 to 7FH General Purpose
Area
• The 128 bytes are divided into 3 different
groups as follows:
BIT Addressable
1. A total of 32 bytes from locations 00 to 1F Area
hex are set aside for register banks and the 128 BYTE
stack. INTERNAL RAM
Reg Bank 3
2. A total of 16 bytes from locations 20H to 2FH
Reg Bank 2
are set aside for bit-addressable read/write Register Banks
memory. Reg Bank 1
3. A total of 80 bytes from locations 30H to 7FH Reg Bank 0
are used for read and write storage, called
scratch pad.
16
8051 RAM with addresses
17
8051 Register Bank Structure
Bank 3 R0 R1 R2 R3 R4 R5 R6 R7
Bank 2 R0 R1 R2 R3 R4 R5 R6 R7
Bank 1 R0 R1 R2 R3 R4 R5 R6 R7
Bank 0 R0 R1 R2 R3 R4 R5 R6 R7
8051 Microcontroller 18
8051 Register Banks with address
8051 Microcontroller 19
Interrupts in 8051
Six interrupts are allocated as follows:
1. Reset – power-up reset.
2. Two interrupts are set aside for the timers.
– one for timer 0 and one for timer 1
3. Two interrupts are set aside for hardware external
interrupts.
– P3.2 and P3.3 are for the external hardware interrupts INT0
(or EX1), and INT1 (or EX2)
4. Serial communication has a single interrupt that
belongs to both receive and transfer.
20
8051 Interrupt Vectors
21
Registers of 8051
22
Thank You
8051 Microcontroller 23