Professional Documents
Culture Documents
Lecture 2
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 1
MICROCONTROLLERS: AN
CCE 514 Computer Architecture – 3 Units
INTRODUCTION
A microcontroller (or MCU) is a special-purpose computer-on-a-
chip . As a computer it has a CPU.
Features of MCU
dedicated to one task and run one specific program.
MCU are often low-power devices. A desktop computer is almost always
plugged into a wall socket and might consume 50 watts of electricity. A battery-
operated MCU might consume 50 milliwatts.
has a dedicated input device and May or may contain a small LED or LCD
display for output.
Takes input from the device it is controlling and controls the device by sending signals to
different components in the device.
For example, the microcontroller inside a TV takes input from the remote control and
displays output on the TV screen. The controller controls the channel selector, the speaker
system and certain adjustments on the picture tube electronics such as tint and
brightness.
integrates memory (ROM and RAM) and input-output interfaces
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 2
MICROCONTROLLERS: AN
CCE 514 Computer Architecture – 3 Units
INTRODUCTION...
Processors used in MCU. The actual processor used to implement
a microcontroller can vary widely
The Z-80 is an 8-bit microprocessor
Some designs include general-purpose microprocessor cores, with one or
more ROM, RAM, or I/O functions integrated onto the package.
Types of MCU
The Motorola 6811
Intel 8051
PIC microcontrollers" created by a company called Microchip.
e.t.c.
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 3
CCE 514 Computer Architecture – 3 Units
MCU Chips
Broad Classification of different microcontroller chips could be as
follows
Embedded (Self -Contained) 8 - bit Microcontroller
16- to 32-bit Microcontrollers
Digital Signal Processors
Power
Control Store
Power Distribution
ROM
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 5
Princeton Architecture
CCE 514 Computer Architecture – 3 Units
Instruction Decoder
Example : An instruction "Read a data
byte from memory and store it in the
Program
accumulator" is executed as follows: -
ROM
Data
Cycle 1 - Read Instruction
Address Memory
Interface Processor Cycle 2 - Read Data out of RAM
Unit and and put into Accumulator
Built-in
Registers
RAM Control
CPU
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 6
CCE 514 Computer Architecture – 3 Units
Harvard Architecture
Separate Program and Data Memory interfaces
Data
Instruction Decoder
Address
Control
Register
Program Space/Data
ROM PC Stack Memory
RAM
Data
Processor
and Address
Register Interface
Control
CPU
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 7
CCE 514 Computer Architecture – 3 Units
Harvard Architecture...
The same instruction (as shown under Princeton
Architecture) would be executed as follows:
Cycle1
Complete previous instruction
Read the "Move Data to Accumulator" instruction
Cycle 2
Execute "Move Data to Accumulator" instruction
Read next instruction
Microprocessor vs Microcontroller
Microprocessor :
requires an external memory for program/data storage.
Instruction execution requires movement of data from the external memory to
the microprocessor or vice versa.
Usually, microprocessors have good computing power and they have higher
clock speed to facilitate faster computation.
Microcontroller :
has required on-chip memory with associated peripherals. A microcontroller can
be thought of a microprocessor with inbuilt peripherals.
does not require much additional interfacing ICs for operation and it functions
as a standalone system. The operation of a microcontroller is multipurpose.
are also called embedded controllers. A microcontroller clock speed is limited
only to a few tens of MHz. Microcontrollers are numerous and many of them are
application specific.
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 9
CCE 514 Computer Architecture – 3 Units
CPU
Bus Serial
Oscillator 4 I/O Ports
Control Port
P0 P2 P1 P3 TXD RXD
Address/Data
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 11
CCE 514 Computer Architecture – 3 Units
8051 MCU...
The 8051 MCU family are 8-bit units which can address 64 Kbytes of
memory
All of the family members have some RAM on the chip and different
members of the family have some ROM or EPROM also included on
the chip
If an application does not require any memory other the on-chip, then
all 4 ports are available for use as input or output ports.
If additional memory is needed, then port 0 and port 2 can be programmed to
function as a multiplexed address/data bus.
When used with external memory, 2 lines on port 3 are used to generate the
and signals
RD WR
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 12
CCE 514 Computer Architecture – 3 Units
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 13
CCE 514 Computer Architecture – 3 Units
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
S1 S2 S3 S4 S5 S6
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 14
CCE 514 Computer Architecture – 3 Units
8051 Memory
The 8051 has three very general types of memory.
On-Chip Memory,
External Code Memory, and
External RAM.
On-Chip Memory refers to any memory (Code, RAM, or other) that
physically exists on the microcontroller itself. On-chip memory can
be of several types.
External Code Memory is code (or program) memory that resides
off-chip. This is often in the form of an external EPROM.
External RAM is RAM memory that resides off-chip. This is often in
the form of standard static RAM or flash RAM.
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 15
CCE 514 Computer Architecture – 3 Units
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 16
CCE 514 Computer Architecture – 3 Units
iRAM Description
Addr R – Register
00 R0 – Register 0
R0 R1 R2 R3 R4 R5 R6 R7 Reg- Bank 0
08
R0 R1 R2 R3 R4 R5 R6 R7 Reg- Bank 1 Internal RAM (iRAM)
10
R0 R1 R2 R3 R4 R5 R6 R7 Reg- Bank 2 • fastest RAM available,
18
R0 R1 R2 R3 R4 R5 R6 R7 Reg- Bank 3 • most flexible in terms of reading,
20
Bits- 00 – 3F
writing, and modifying its contents.
00 08 10 18 20 28 30 38
28 • iRAM is volatile, so when the 8051 is
40 48 50 58 60 68 70 78 Bits- 40 – 7F
30 reset this memory is cleared.
General User RAM & Stack Space
(80 bytes, 30h – 7Fh) General iRAM
7F
80
: Special Function Registers (SFRs) SFRs
(80 bytes, 30h – 7Fh)
:
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 18
CCE 514 Computer Architecture – 3 Units
address space)
7Fh
General
Purpose 80 bytes
30h Area
2Fh
Bit Address 16 bytes
30h Area
1Fh
Register
Bank-3 No. of Bits = 16 x 8 = 128 bytes
18h Bit address 00h – 7Fh
17h
Register
10h Bank-2
0Fh
Register
Bank-1
08h 32 bytes= 8 x 4 bytes
07h R7
Register
Bank-0
R1
00h R0
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 21
128 bytes of Internal RAM Structure...
CCE 514 Computer Architecture – 3 Units
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 22
Internal Data Memory and Special Function
CCE 514 Computer Architecture – 3 Units
The SFRs are mapped in the upper 128 bytes of internal data memory address.
Hence there is an address overlap between the upper 128 bytes of data RAM and SFRs.
Please note that the upper 128 bytes of data RAM are present only in the 8052 family.
The lower128 bytes of RAM (00H - 7FH) can be accessed both by direct or indirect
addressing while the upper 128 bytes of RAM (80H - FFH) are accessed by indirect
addressing.
The SFRs (80H - FFH) are accessed by direct addressing only. This feature
distinguishes the upper 128 bytes of memory from the SFRs, as shown above
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 23
CCE 514 Computer Architecture – 3 Units
SFR Map
The set of Special Function Registers (SFRs) contains important registers such
as:
Accumulator (A),
Register B,
I/O Port latch registers,
Stack pointer,
Data Pointer,
Processor Status Word (PSW) and various control registers
Some of these registers are bit addressable
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 24
CCE 514 Computer Architecture – 3 Units
PSW
CY PSW.7 Carry flag.
PSW: Example
The flag bits affected by the ADD instruction are CY, P, AC, and OV
Example
Show the status of the CY, AC and P flag after the addition of 38H and 2FH in the following
instructions.
MOV A, #38H
ADD A, #2FH ; after the addition A=67H, CY=0
Solution:
D7..............D0
38 00111000
+ 2F 00101111
67 01100111
P = 1 since the accumulator has an odd number of 1s (it has five 1s)
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 26
CCE 514 Computer Architecture – 3 Units
PSW: Example...
Example 2
Show the status of the CY, AC and P flag after the addition of 9CH and
64H in the following instructions.
MOV A, #9CH
ADD A, #64H ; after the addition A=00H, CY=1
Solution:
9C 10011100
+ 64 01100100
100 00000000
Example
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 28
CCE 514 Computer Architecture – 3 Units
SFR Map...
Some of these registers are bit addressable (they are marked with a * in the diagram below)
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 29
CCE 514 Computer Architecture – 3 Units
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 30
CCE 514 Computer Architecture – 3 Units
Immediate Addressing
Data is immediately available in the instruction.
For example:
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 31
Bank Addressing or Register
CCE 514 Computer Architecture – 3 Units
Addressing
This way of addressing accesses the bytes in the current register
bank.
Data is available in the register specified in the instruction.
The register bank is decided by 2 bits of Processor Status Word
(PSW).
For example:
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 32
CCE 514 Computer Architecture – 3 Units
Direct Addressing
The address of the data is available in the instruction.
For example -
This instruction will read the data out of Internal RAM address
MOV A,30h
30 (hexidecimal) and store it in the Accumulator.
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 33
CCE 514 Computer Architecture – 3 Units
For example:
Indirect addressing is also the only way to access the extra 128
bytes of Internal RAM found on an 8052.
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 34
CCE 514 Computer Architecture – 3 Units
There are only two commands that use External Direct addressing
mode:
MOVX A, @DPTR Moves content of 8-bit address pointed by R0 to A
MOVX @DPTR, A Moves content of 16-bit address pointed by DPTR to A
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 35
CCE 514 Computer Architecture – 3 Units
Such data may require reading the code memory. This may be done
as follows -
MOVC A, @A+DPTR; Moves content of address pointed by A+DPTR to A
MOVC A, @A+PC; Moves content of address pointed by A+PC to A
Engr. Dr. Christopher U. Ngene, Dept. of Communication and Computer Engineering, ATBU , email:ngene@unimaid.edu.ng 36