Unit 2 Microcontroller
Unit 2 Microcontroller
CPU
OSC Bus
4 I/O Ports Serial
Control
P0 P2 P1 P3 TXD RXD
Addr/Data
Other 8051 featurs
• only 1 On chip oscillator (external crystal)
• 6 interrupt sources (2 external , 3 internal, Reset)
• 64K external code (program) memory(only read)PSEN
• 64K external data memory(can be read and write) by RD,WR
• Code memory is selectable by EA (internal or external)
• We may have External memory as data and code
Embedded System
(8051 Application)
• Keyboard
• Printer
• video game player
• MP3 music players
• Embedded memories to keep configuration
information
• Mobile phone units
• Domestic (home) appliances
• Data switches
• Automotive controls
Three criteria in Choosing a
Microcontroller
• meeting the computing needs of the task efficiently and
cost effectively
– speed, the amount of ROM and RAM, the number of I/O ports
and timers, size, packaging, power consumption
– easy to upgrade
– cost per unit
• availability of software development tools
– assemblers, debuggers, C compilers, emulator, simulator,
technical support
• wide availability and reliable sources of the
microcontrollers
Comparison of the 8051 Family Members
• ROM type
– 8031 no ROM
– 80xx mask ROM
– 87xx EPROM
– 89xx Flash EEPROM
• 89xx
– 8951
– 8952
– 8953
– 8955
– 898252
– 891051
– 892051
• Example (AT89C51,AT89LV51,AT89S51)
– AT= ATMEL(Manufacture)
– C = CMOS technology
– LV= Low Power(3.0v)
Comparison of the 8051 Family Members
892051 2k 128 2 6 16 AC
TB1
Read pin
Hardware Structure of I/O Pin
• Each pin of I/O ports
– Internally connected to CPU bus
– A D latch store the value of this pin
• Write to latch = 1 : write data into the D latch
– 2 Tri-state buffer :
• TB1: controlled by “Read pin”
– Read pin = 1 : really read the data present at the pin
• TB2: controlled by “Read latch”
– Read latch = 1 : read value from internal latch
– A transistor M1 gate
• Gate=0: open
• Gate=1: close
Writing “1” to Output Pin P1.X
TB1
Read pin
Writing “0” to Output Pin P1.X
TB1
Read pin
Reading “High” at Input Pin
1 1 P1.X pin
Internal CPU bus D Q
P1.X
0 M1
Write to latch Clk Q
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
Reading “Low” at Input Pin
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
8051 IC
Port 0 with Pull-Up Resistors
Vcc
10 K
P0.0
DS5000 P0.1
Port 0
P0.2
8751 P0.3
8951 P0.4
P0.5
P0.6
P0.7
IMPORTANT PINS
• Vcc ( pin 40 ):
– Vcc provides supply voltage to the chip.
– The voltage source is +5V.
• GND ( pin 20 ): ground
• XTAL1 and XTAL2 ( pins 19,18 ):
– These 2 pins provide external clock.
– Way 1 : using a quartz crystal oscillator
– Way 2 : using a TTL oscillator
– Example 4-1 shows the relationship between XTAL
and the machine cycle.
XTAL Connection to 8051
C1
XTAL1
30pF
GND
XTAL Connection to an External Clock Source
N XTAL2
C
EXTERNAL
OSCILLATOR
SIGNAL XTAL1
GND
Machine cycle
• Find the machine cycle for
• (a) XTAL = 11.0592 MHz
• (b) XTAL = 16 MHz.
• Solution:
Vcc
31
EA/VPP
X1
10 uF 30 pF
X2
RST
9
8.2 K
RESET Value of Some 8051 Registers:
Figure 2-7
Multiplexing
the address
(low-byte)
and data
bus
Address Multiplexing
for External Memory
Figure 2-8
Accessing
external
code
memory
Accessing External
Data Memory
Figure
2-11
Interface
to 1K
RAM
Timing for MOVX instruction
External code memory
WR
RD
PSEN OE
ALE 74LS373 CS
G
P0.0 A0
D
P0.7 A7
D0
D7
EA
P2.0 A8
P2.7 A15
8051 ROM
External data memory
WR WR
RD RD
PSEN
ALE 74LS373 CS
G
P0.0 A0
D
P0.7 A7
D0
D7
EA
P2.0 A8
P2.7 A15
8051 RAM
Overlapping External Code
and Data Spaces
Overlapping External Code
and Data Spaces
WR WR
RD
PSEN RD
ALE 74LS373 CS
G
P0.0 A0
D
P0.7 A7
D0
D7
EA
P2.0 A8
P2.7 A15
8051 RAM
Overlapping External Code
and Data Spaces
Allows the RAM to be
written as data memory, and
read as data memory as well as code memory.
This allows a program to be
downloaded from outside into the RAM as data, and
executed from RAM as code.
On-Chip Memory
Internal RAM
Registers
1F
Bank 1
08
07 R7
06 R6
05 R5
04
03
R4
R3 Bank 0
02 R2
01 R1
00 R0
Bit Addressable Memory
2F 7F 78 20h – 2Fh (16 locations X
2E
2D
8-bits = 128 bits)
2C
2B
Bit addressing:
2A mov C, 1Ah
29 or
28 mov C, 23h.2
27
26
25
24
23
22
21
20
1A
Special Function Registers
DATA registers
CONTROL registers
Timers
Serial ports
Interrupt system Addresses 80h – FFh
Analog to Digital converter
Digital to Analog converter Direct Addressing used
Etc. to access SPRs
Bit Addressable RAM
Figure 2-6
Summary
of the 8051
on-chip
data
memory
(RAM)
Bit Addressable RAM
Figure 2-6
Summary
of the 8051
on-chip
data
memory
(Special
Function
Registers)
Register Banks
Used in assembler
instructions
Registers
Registers
A
R0
DPTR DPH DPL
R1
R2 PC PC
R3
R6
R7