CHAPTER 1
Introduction to Microcontroller
razkiah@[Link] 1
Major Functions of a Computer
• Computer
Data Processing
Data Storage
razkiah@[Link] 2
Major Components of a Computer
• A computer consists of
– CPU
– Memory
– I/O
– System Bus
razkiah@[Link] 3
CPU: Central Processing Unit
• CPU
– Is the “brain” of a computer
– It consists of
• Control unit and instruction decoder
• Arithmetic and logic unit
• Registers
razkiah@[Link] 4
Memory
Memory Address-1 Memory Location-1
Memory Address-2 Memory Location-2
1 2 3 4 5 6 7 8
1 word = 8-bit data
(for 8051)
Memory Address-n Memory Location-n
razkiah@[Link] 5
I/O Module
• Human-readable I/Os:
Suitable for communicating with the user
Examples: monitor, keyboard, mouse, joystick, video display terminals,
printers, scanner, microphone, and speaker.
• Machine-readable I/Os:
Suitable for communicating with equipment: magnetic disk, optical disk,
sensors (temperature, light, motion, and so on), and actuators (motor, relay,
and pneumatic).
Communication I/Os: suitable for communicating with remote devices: infra-
red (IR) interface, radio frequency (RF) interface, bluetooth device, and
Wireless LAN.
razkiah@[Link] 6
System Bus
• The collection of paths connecting the various modules of the computer
• Different types of connection for different types of unit
CPU Memory Memory I/O I/O
Control bus
Address bus
Data bus
razkiah@[Link] 7
Types of Exchanges Between Modules
Read Read
Memory Write Internal
Write Data
Address I/O Module
N words
Address Data External
0 Internal Data
Data MPorts
Data Interrupt
N1 External Signals
Data
Instructions
Control
Data CPU Signals
Data
Interrupt
Signals
razkiah@[Link] 8
Basic Instruction Cycle
PC = 0000H Start
Fetch Instruction
Fetch Cycle
PC = PC + n
Execute
Instruction Execute Cycle
End
razkiah@[Link] 9
Fetch Cycle
• Program Counter (PC) holds the address of the next instruction to
fetch
• The processor fetches the instruction from the memory location
pointed to by PC
• Increment PC
– unless told otherwise
• The instruction is loaded into the Instruction Register (IR)
• The processor interprets the instruction and performs the required
actions
razkiah@[Link] 10
Execute Cycle
• Processor-memory
– Data transfer between the CPU and main memory
• Processor-I/O
– Data transfer between the CPU and I/O module
• Data processing
– Some arithmetic or logical operation on data
• Control
– Alteration of sequence of operations
– Example: jump
• Combination of the above
razkiah@[Link] 11
Instruction Cycle: State Diagram
Instructi Operand Operand
on Fetch Fetch Store
Multiple Multiple
operands results
Instructi Instructi Operand Data Operand
on on Address Operatio Address
Address Operatio Calculati n Calculati
Calculati n on on
on Decoding Return for string
Instruction or vector date
completes, fetch
next instruction
razkiah@[Link] 12
Memory Read Operation: Step 1
The CPU sends out control signals Memory
Request and Read to indicate that it wants to
read from memory
CPU Read
Memory
Memory request
Data bus
Address bus
CPU places address (XXXX) of the
memory location on the address bus
razkiah@[Link] 13
Memory Read Operation: Step 2
Accessed location at XXXX
CPU Read Memory
Memory request
Data bus
Address bus
Memory places data from the accessed
location onto the data bus
razkiah@[Link] 14
Memory Read Operation: Step 3
The CPU removes the Memory Request
and Read signals
CPU Read Memory
Memory request
Register
Data bus
Address bus
The CPU latches the data into a register
razkiah@[Link] 15
Memory Write Operation: Step 1
The CPU sends out a Memory Request control
signal to indicate that it wants to perform a
memory operation
CPU Memory
Memory request
Data bus
Address bus
The CPU places address (YYYY) of the
memory location on the address bus
razkiah@[Link] 16
Memory Write Operation: Step 2
The CPU sends out a Write control signal to
indicate that valid data is available on the data
bus
CPU Write Memory
Memory request
Register
Data bus
Address bus
The CPU places the data from a register
onto the data bus
razkiah@[Link] 17
Memory Write Operation: Step 3
The CPU removes the Write signal to complete
the memory write operation
CPU Write Memory
Memory request
Register Accessed location
Data bus at YYYY
Address bus
Memory copies the data bus into the
accessed location
razkiah@[Link] 18
What Is Microprocessor?
CPU
A microprocessor is a single-chip CPU used in the computer system. It contains all the
necessary computer components except memory and I/O ports. Microprocessors are most
commonly used as the CPU in computer systems (in the world of personal computers, the
terms “microprocessor” and “CPU” are used interchangeably).
razkiah@[Link] 19
What Is Microcontroller?
A microcontroller is a true
single-chip computer
system. It contains a CPU,
memory (RAM and ROM),
I/O modules (serial and
parallel interfaces), timers,
counters, and interrupt
MEMORY
scheduling circuitry – all
I/O SYSTEM within a single IC.
BUS
CPU
razkiah@[Link] 20
General Structure of a MCU
I/O
Interrupt
Control Serial Parallel
Interface Interface
CPU
Internal address, data, & control buses
Timers/ RAM ROM
Counters
Memory
razkiah@[Link] 21
Microprocessors vs. Microcontrollers
Perspective Microprocessor Microcontroller
Hardware Single-chip CPU Single-chip computer
Architecture High RAM-ROM ratio High ROM-RAM ratio
External components are Built-in interrupt, timer,
required and I/O
Applications to implement interrupt, devices
Used in control-oriented
Used as CPU in computer
timer, and systems
systems
I/O operations requiring minimum
for general processing
Instruction Powerful and process components
Simple and compact
Set intensive instructions
Features instructions
More suitable for large More suitable for single-
volume data bit I/O
handlings operations
AND, OR, XOR operations AND, OR, XOR operations
at bit razkiah@[Link] at bit 22
List of Popular Microcontrollers
68HC11
8051
ARM
Atmel AVR 8-bit architecture
Atmel AVR32 32-bit architecture
Freescale CF (32-bit)
Freescale S08
Hitachi H8, Hitachi SuperH
MIPS (32-bit PIC32)
NEC V850
PIC (8-bit PIC16, PIC18, 16-bit dsPIC33 / PIC24)
PowerPC ISE
PSoC (Programmable System-on-Chip)
Rabbit 2000
TI MSP430 (16-bit)
Toshiba TLCS-870
Zilog eZ8, eZ80….
razkiah@[Link] 23
Major 8-bit Microcontrollers
CPU Sold in 2003 (US$44 billion)
Intel 8051
Motorola 68HC11 Others
35%
Zilog Z86 8-bit
55%
32-bit
Microchip PIC16XX 10%
razkiah@[Link] 24
8051 Microcontroller / MCS-51 TM
• The 8-bit microcontroller was originally developed by Intel in 1980.
• The 8051 instruction set is optimized for bit operation, which is best
suited for real-world, real-time control applications.
• The world’s most popular microcontroller core.
• The 8051 family is still one of the most popular microcontrollers used
in embedded products.
razkiah@[Link] 25
Original 8051 Specifications
Feature Quantity
ROM 4K bytes
RAM 128 bytes
Timer 2
I/O pins 48
Serial port 1
Interrupt sources 6
razkiah@[Link] 26
ROM Technology
• Mask ROM programmed by the IC manufacturer
• OTP ROM / PROM programmed once by the user
• EPROM / UV-EPROM Erasable Programmable ROM (~1000x)
• EEPROM / FLASH Electrically Erasable ROM (100k to 1millionx)
• Flash memory is a version of EEPROM that allows multiple memory locations
to be erased or programmed in one programming operation.
• NV RAM allows program codes to be loaded into the on-chip ROM while it
is in the system (in-system programming).
• It has the ability to change the ROM contents one byte at a time, as opposed
to EPROM and flash memory in which the entire ROM must be erased before
it can be reprogrammed.
razkiah@[Link] 27
Popular 8051 Variants
Part Number Pin Mfr RAM (bytes) ROM (bytes) Descriptions
8031 40 All 128 0K ROM-less 8051
8051 40 All 128 4K ROM 8051 core
8052 40 All 256 8K ROM 8051 + Timer 2
87C51 40 Intel 128 4K EPROM 8051 compatible
87C52 40 Intel 256 8K EPROM 8052 compatible
87C51GB 68 Intel 256 8K EPROM 8bA/D, PWM, WDT, 48 I/Os
87C251 40 Intel 1024 16K EPROM High-speed 8051
AT89C2051 20 Atmel 128 2K Flash 15 I/Os, Analog comparator, LED drive outputs
AT89C51 40 Atmel 128 4K Flash 8051 compatible
AT89C51RD2 40 Atmel 256 64K Flash 80C52 compatible, ISP, WDT, PWM
AT89C52 40 Atmel 256 8K Flash 8052 compatible
AT89S51 40 Atmel 128 4K Flash 8051 + ISP, WDT
AT89S8252 40 Atmel 256 10K Flash 2K EEPROM, WDT, SPI
DS5000FP 80 Dallas/ Maxim 128 32K NVR 8051 + WDT, ISP
87C520 40 Dallas/ Maxim 256 16K EPROM 2 UART, 3 Timers, WDT
P87C528 40 Philips 256 32K 8052 + WDT, I2C
P87C654 40 Philips 256 16K 8051 + I2C
P87C751 24 Philips 64 2K EPROM 19 I/Os, I2C
P87C752 28 Philips 64 2K EPROM 87C751 + 8bA/D + PWM
P89C51RD2 40 Philips 256 64K Flash 80C52 compatible, ISP, WDT, PWM
SAB80C517A 84 Siemens / Infineon 256 0K 21PWM, 2UART, 10bA/D, 4 Timers, 68 I/Os
SAB80C515 68 Siemens / Infineon 256 8K 4PWM, WDT, 3 Timers, 8bA/D, 56 I/Os
razkiah@[Link] 28
Recommended References
Recommended References:
1) Koo Voon Chet, et. al., “The 8051 Cookbook”, 2nd Edition, Prentice Hall, 2006.
2) James W. Stewart and Kai X. Miao, “The 8051 Microcontroller: Hardware, Software and
Interfacing,” 2nd Edition, Prentice Hall, 1999.
3) Muhammad Ali Mazidi, “The 8051 Microcontroller and Embedded Systems,” Prentice
Hall, 2000.
4) Richard H. Barnett, “The 8051 Family of Microcontrollers,” Prentice Hall, 1995.
5) Scott Mackenzie, “The 8051 Microcontroller,” 3rd Edition, Prentice Hall, 1999.
6) [Link] – Resources, tutorials, code libraries, hardware and software product
information, and links for the 8052 microcontroller family.
razkiah@[Link] 29