Académique Documents
Professionnel Documents
Culture Documents
Microcontrollers
Architecture
Learning Objectives
Study Architecture of 8051 Microcontroller
Understand 8051 Registers
Learn Pin Diagram and function of each pin
Study Reset Circuit
Understand On-Chip ROM Address Range,
RAM Allocation, Memory Bank and SFRs
Learn concept of Program and Data Memory
Study I/O Ports and their functions
Study Stack
2
The 8051 Microcontroller
The 8051 is the first microcontroller of the MCS-51 family
introduced by Intel Corporation at the end of the 1970’s.
3
Inside 8051 Microcontroller
External interrupts
On-chip Timer/Counter
CPU
Bus Serial
4 I/O Ports
OSC Control Port
P0 P1 P2 P3 TxD RxD
Address/D
ata
4
8051 Registers
5
PSW(Flag) Register
CY AC F0 RS1 RS0 OV -- P
8
Pin Description
Vcc pin 40 Vcc = +5V provides supply voltage to the chip.
GND pin 20 = ground
XTAL1 and XTAL2 pins 19,18 Provides external clock.
Way 1:using a quartz crystal oscillator
Way 2:using a TTL oscillator
RST pin 9 Power on reset (input pin, active high)
Upon applying a high pulse to RST, the microcontroller will reset
and all values in registers will be lost. By applying logical zero to
this pin, the program starts execution from the beginning.
Way 1 Power-on reset circuit
Way 2 Power-on reset with key de-bounce
9
Pin Description (cont …)
/PSEN pin 29 Program Store Enable (output pin, active low)
Connected to the OE pin of the ROM.
If external ROM is used for storing program then it has a logic-0 value every time the
microcontroller reads a byte from memory.
ALE pin 30 Address latch Enable (output pin, active high)
8051 port 0 provides both address and data.
The ALE signal is used for de-multiplexing the address and data bus.
/EA pin 31 External Access (Active low)
The /EA pin is connected to GND to indicate the code is stored in external memory.
By applying logic zero to this pin, port P0 and port P2 are used for data and address
transmission to external memory.
It means if program is written into internal ROM of the microcontroller, will not be executed,
the program written to external ROM will be used instead.
10
Crystal Connection
Using a quartz crystal Using a TTL oscillator
oscillator typically of
XTAL2 is unconnected
11.0592MHz
We can observe the frequency
on the XTAL2 pin.
C2
XTAL2 N XTAL2
30pF C
C1 EXTERNAL
XTAL1 OSCILLATOR XTAL1
30pF SIGNAL
GND GND
11
RESET Value of Registers & Ckt
13
8051 RAM Allocation
1F
Bank 3
18
17
Bank 2
10
0F
Stack/
08
Bank 1
07 R7
06 R6
05 R5
04 R4
03 R3 Bank 0
02 R2
01 R1
00 R0
14
15
Bit Addressable Memory
2F 7F 78
20h – 2Fh (16 locations X
2E
8-bits = 128 bits)
2D
2C
2B
Bit addressing:
2A mov C, 1Ah
29 or
28 mov C, 23h.2
27
26
25
24
23
1A
22
21 10
20 0F 08
07 06 05 04 03 02 01 00
17
SFR (Special function register)
Four I/O (Input/Output) ports
P0, P1, P2, P3
Timer Registers
TH0 TL0 16-bit timer register for timer 0 to hold count
TH1 TL1 16-bit timer register for timer 1 to hold count
TMOD – Timer mode control register
TCON – Timer control register
Serial Communication Registers
SCON Serial Control register -controls the baud rate of the serial port
SBUF Serial Buffer register
PCON – Power Control register
Interrupt Register
IE – Interrupt enable control
IP - Interrupt Priority control
7
SFRs
16
Program Memory (ROM)
18
External ROM Connection
PSEN OE
ALE G 74LS373 OC
P0.0 D A0
P0.7 A7
D0
D7
EA
P2.0 A8
P2.7 A15
8051 ROM
19
Data Memory
20
4 I/O Ports
Ports P0,P1,P2,P3 Each has 8 pins and are Bidirectional
21
Port 3: I/O, No Pull-up Resistors
23
Port Bit latches & I/O buffers
24
Port 0 Configuration
Port 0: I/O, Open Drain
Vcc
10 K
P0.0
Port
8051 P0.1
P0.2
89C5 P0.3
1 P0.4 0
P0.5
P0.6
P0.7
22
Hardware Structureof I/O Pin
TB1
Read pin
25
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
26
Writing“1” to Output Pin P1.X
Clk 0 output 1
Write to latch Q M1
TB1
Read pin
27
Writing“0” to Output Pin P1.X
Clk 1 output 0
Write to latch Q M1
TB1
Read pin
28
Reading “High” at Input Pin
Read latch Vcc 2. MOVA,P1
TB2 external
ext pin=High
1. write a 1 to the pin MOV Load(L1)
P1,#0FFH
1 1
Internal CPU bus D Q P1.X pin
P1.X
0 M1
Write to latch Clk Q
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
29
Reading “Low” at Input Pin
0 M1
Write to latch Clk Q
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
30
Block Diagram
8051 Block Diagram
A (Accumulator)
B
PSW (Program Status Word)
SP (Stack Pointer)
PC (Program Counter)
DPTR (Data Pointer)
Used in assembler
instructions
33
34
35
Pin Diagram with Alternate Function
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)
P1.2 3 38 P0.1(AD1)
P1.3 4 8051 37 P0.2(AD2)
P0.3(AD3)
P1.4 5 36
P1.5 6 (8031) 35 P0.4(AD4)
P1.6 7 34 P0.5(AD5)
P1.7 8 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RX 10 31 EA/VPP
D)P 11 30 ALE/PROG
3.0 12 29 PSEN
(INT1)P3.3
(TX 13 28 P2.7(A15)
(T0)P3.4
D)P 14 27 P2.6(A14)
(T1)P3.5
3.1 15 26 P2.5(A13)
(WR)P3.6
(I 16 25 P2.4(A12)
NT0)
(RD)P3.7 17 24 P2.3(A11)
P3.2
XTAL2 18 23 P2.2(A10)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
36