Documente Academic
Documente Profesional
Documente Cultură
Microcontrollers/Microprocessors
for Embedded Systems
1
MCS-51 Family
2
The 8051 8-bit Microprocessor/
Microcontroller Family (MCS-51)
3
8051 (old chip) Block Diagram
External Interrupts
CPU
OSC Bus
4 I/O Ports Serial
Control
P0 P2 P1 P3 TXD RXD
Addr/Data
4
8051 Internal Block Diagram
5
8051 I/O Pins for 40-Pin DIP Package
6
8051 Family (8051, 8052, 802051, etc)
IMPORTANT PINS:
The 8051 is a Single
Chip Computer or Port 0 (acts as a multiplexed low byte address and
microcontroller data bus for large external memory design).
Developed Initially by
Intel. It is one of the Port 1 – 8-bit R/W - General Purpose I/O
most widely used
microcontroller chips in Port 2 (act as the high byte of the address bus for
the world. large external memory design).
11
Port P1
12
Port P2 and P3
13
Port 3 Alternate Functions
14
Read-Modify-Write Feature
17
Register Banks
18
An Accumulator Architecture: the 8051
8051 is an accumulator architecture (not a
“pure” one)
There’s one register, the accumulator (ACCU),
that is both source and destination register of
most operations
ADD A,ADDRESSB ; A = A + Mem[ADDRESSB]
19
8051 Registers and PSW
ACC - accumulator
B - used in multiply and divide
PSW - Program Status Word
SP - Stack Pointer
PC Program Counter - not user accessible
IP, IE (Interrupt Priority and Interrupt Enable)
DPH and DPL (Data Pointer High and Low)
PCON – Power Control Register
SBUFFER and SCON – Serial Buffer and Serial Control Reg
TH0, TL0, TH1, TL1 – (Timer High and Low 0 and 1)
TCON and TMOD – Timer Control Reg and Timer Mode Reg
PSW: CY - Carry
AC – Aux. Carry (cy from b2 to b3 - BCD)
CY AC F0 RS1 RS0 OV - P
F0 – General Use Flag – no specific func
RS0,RS1 - Bank Select (4 banks or sets)
0 0 - 00h to 07h
OV - Overflow
0 1 - 08h to 0Fh
- User defined flag
1 0 - 10h to 17h
P - Parity
1 1 - 18h to 1Fh 20
8051 Special Function Registers
and Bit-Addressable Memory
21
8051 Programmer’s Model
Program Memory(64K)
7 0
FFFF 7 0
FFFF
60 K
1000
External 64 K • All instructions
OR
External • Constant Data
0FFF (Using MOVC)
4K 0000
0000 Internal
if EA = HI if EA = LO
Data Memory(64K)
FF AND FFFF
SFRs (Using MOVX)
80 64 K
7F RAM External @R
00 @DPTR
Internal 0000
Direct
Direct , Register,
Reg. Indirect
22
8051 Internal RAM
Address
00 Register Set 0
08 Register Set 1
10 Register Set 2
18 Register Set 3
20
Bit Addressable
28
30
38
RAM
40
48 +
50 stack
58
60
68
70
78
Which set of 8 registers is being used depends on 2 bits in the
Program Status Word (PSW)
23
8051 Special Function Registers (SFRs)
80 P0 SP DPL DPH PCON
88 TCON TMOD TL0 PL1 TH0 TH1
90 P1
98 SCON SBUF
a0 P2
a8 IE
b0 P3
b8 IP
c0
c8
d0 PSW
d8
e0 ACC
e8
f0 B
f8
Address
24
8051 Programmer’s Model
7F SFRs
SFRs
Scratch Pad Area A8 * IE Interrupt Enable Ctr 1 FF
A0 * P2 Port 2 F0 *B
RAM
99 SBUF Serial Data Buffer
98 * SCON Serial Control E0 * ACC
90 * P1 Port 1 D0 * PSW
30
8D TH1 timer 1 High
Bit #00 7F OR 8C TH0 timer 0 High B8 * IP
Bit Addressable RAM 20.0 2F.7 8B TL1 timer 1 Low
20 8A TL0 timer 0 Low
R7 89 TMOD timer/counter Mode B0 * P3
Bank 3 Select Bank 88 * TCEN timer/counter control
18 R0
R7 with 87 PCON Power Control
Bank 2
10 R0 PSW.4 , .3 =
Bank 1 R7 83 DPH
08 R0 RS1, RS0 Data pointer DPTR
82 DPL
Bank 0 R7 81 SP Stack pointer
00 R0 80 * P0 Port 0
* = Bit Addressable
25
8051 Assembly Code Example
Register - Rn
MOV R1,A ; R1 Acc
MOV B,R3 ;B R3
27
8051 Addressing Modes (2)
28
Subroutines
Special instructions:
• PUSH op
• POP op
• op must be specified using direct addressing!
29
Parameter passing
30
Interrupt Sources in 8051 Family (non vectored)
31
Interrupt Control Bits
PX0 =0 – Low Priority; PX0= 1 – High Priority – Highest priority within group
PT0 =0 – Low Priority; PT0= 1 – High Priority
PX1 =0 – Low Priority; PX1= 1 – High Priority
PT1 =0 – Low Priority; PT1= 1 – High Priority
PS =0 – Low Priority; PS = 1 – High Priority – Lowest priority within group
32
Interrupt Control Bits (cont)
GATE – If GATE = 1, timer x will run only when TRx=1 and INTx = 1. If GATE=0, timer
x will run whenever TRx=1.
C/T – Timer mode select. If C/T=1, timer x runs in counter mode taking its input from
Tx pin. If C/T=0, timer x runs in timer mode taking its input from the system clock.
34
Interrupt Control Bits (cont)
Timer 2 Control Register – T2CON
EXF2 – Timer 2 external flag. EXF2 is set when a falling edge is detected on T2Ex and EXEN2=1.
This causes an interrupt, if the timer 2 is enabled.
RCLK – Receive clock flag. When RCLK=1, the UART (if in mode 1 or 3) will use the timer 2
overflow frequency for the receive clock.
TCLK – Transmit clock flag – When TCLK=1, the UART (if in mode 1 or 3) will use the timer 2
overflow frequency for the receive clock.
EXEN2 – External enable flag – If EXEN2=1, a capture or reload will be caused by a falling edge
on T2EX. If EXEN2=0, external events on T2EX are ignored.
TR2 – Timer run control bit – If TR2=1, the timer will run. If TR2=0, the timer will stop.
C/T2 – Timer mode select – If C/T2=1, timer 2 will act as an external event counter. If C/T2=0, timer
2 will count processor clock cycles.
CP/RL2 – Capture/Reload flag – If CP/RL2=1, detection of a falling edge on T2EX causes a capture
if EXEN2=1. If CP/RL2=0, detection of a falling edge on T2EX or an overflow causes a timer
reload if EXEN=1.
35
Interrupts on MCS-51 Family
S1 S2 S3 S4 S5 S6
38