Microcontroller
Microcontroller
Purpose ?
Microcontroller
• Microcontrollers are important part of
Embedded systems
• To understand Structure & working of
Microcontrollers
• For Designing good Embedded system
complete understanding of
microcontrollers required
Microcontroller
Integrated chip that typically contains integrated CPU,
memory (RAM ROM), I/O ports on a single Chip.
● Microcontrollers
CPU RAM ROM
Serial
Timer I/O
Port
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
● CPU is stand-alone, RAM, ROM, I/O, ● CPU, RAM, ROM, I/O and timer are all
timer are separate on a single chip
● Designer can decide on the amount of ● Fix amount of on-chip ROM, RAM, I/O
ports
ROM, RAM and I/O ports.
● Not Expansive
● Expansive
● For applications in which cost, power
● Versatility and space are critical
● General-purpose ● Single-purpose
Microcontrollers
A microcontroller
interfaces to
external devices
with a minimum of
external
components
Most common microcontrollers
● 8-bit microcontrollers
○ AVR
○ PIC
○ HCS12
○ 8051
● 32-bit microcontrollers
○ ARM
○ PIC32
Intel 51 family (8-bit MC)
● 8051
○ 40 pin DIP
○ 4K ROM
○ 32 I/O lines
○ 5 Interrupt
○ UART
○ Have 40 pins dedicated for various functions such as I/O, RD, WR, address, data, and interrupts.
● Some companies provide a 20-pin version of the 8051 with a reduced number of I/O
ports for less demanding applications
Pin Diagram of the 8051
XTAL1 and XTAL2
● The 8051 has an on-chip oscillator but requires an external clock to run it
○ A quartz crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2 (pin18)
● We can observe the frequency on the XTAL2 pin using the oscilloscope.
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
RST
● In order for the RESET input to be effective, it must have a minimum duration
of 2 machine cycles.
● In other words, the high pulse must be high for a minimum of 2 machine
cycles before it is allowed to go low.
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.
External
External
60
K
64 64
K K
SFR
EXT INT 4K
128
EA = 0 EA = 1
Program Memory Data Memory
PSEN’ and ALE
● PSEN, “program store enable’’, is an output pin
● The 8051 multiplexes address and data through port 0 to save pins.
○ Port 2 must be used along with P0 to provide the 16-bit address for the
external memory.
○ P2 is used for the upper 8 bits of the 16-bit address, designated as A8 – A15,
and it cannot be used for I/O.
Port 3
● Port 3 can be used as input or output.
P2.0 - P2.7 I/O Port 2: Port 2 is an 8-bit bidirectional I/O. Port 2 emits the high order address
byte during fetches from external program memory and during accesses to
external data memory that use 16 bit addresses.
P3.0 - P3.7 I/O Port 3: Port 3 is an 8 bit bidirectional I/O port. Port 3 also serves special
features as explained.
Pin Description Summary
PIN TYPE NAME AND FUNCTION
RST I Reset: A high on this pin for two machine cycles while the oscillator is running,
resets the device.
ALE O Address Latch Enable: Output pulse for latching the low byte of the address
during an access to external memory.
PSEN* O Program Store Enable: The read strobe to external program memory. When
executing code from the external program memory, PSEN* is activated twice
each machine cycle, except that two PSEN* activations are skipped during each
access to external data memory.
EA*/VPP I External Access Enable/Programming Supply Voltage: EA* must be externally
held low to enable the device to fetch code from external program memory
locations. If EA* Is held high, the device executes from internal program
memory. This pin also receives the programming supply voltage Vpp during
Flash programming. (applies for 89c5x MCU's)
General Block Diagram of 8051
Interrupt 4K 128 B Timer 0
Control ROM Timer 1
RAM
CPU
Bus Serial
OSC Control
4 I/O Ports
Port
TXD RXD
P0 P1 P2 P3
SECTION 2.1: INSIDE THE 8051
• Registers
Figure 2–1a
Some 8-bit Registers of the 8051
SECTION 2.1: INSIDE THE 8051
• Registers
C AC F0 RS1 RS0 OV F1 P
Carry Parity
Auxiliary Carry User Flag 1
User Flag 0 Register Bank Select Overflow
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 hex are 128Area
BYTE
set aside for register banks and the stack. INTERNAL
Reg Bank 3
RAM
2. A total of 16 bytes from locations 20H to 2FH are
set aside for bit-addressable read/write memory. Register
Reg Bank 2
3. A total of 80 bytes from locations 30H to 7FH are Banks
Reg Bank 1
used for read and write storage, called scratch Reg Bank 0
pad.
8051 RAM with addresses
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 Register Banks with address
SECTION 2.7: 8051 REGISTER BANKS AND STACK
• How to switch register banks