Beruflich Dokumente
Kultur Dokumente
DEPARTMENT OF ECE
MVGR COLLEGE OF ENGINEERING
July 4,CHINTALAVALASA,VIZIANAGARAM
2015
Contents
Introduction to embedded systems
The 8051 architecture
Micro controller hardware
Ports
External memory
Timers & Counters
Serial port communication
Interrupts
July 4, 2015
Contents:
Microcontrollers Microcontrollers
Why should we study them?
Where they are being used?
vs. Microprocessor
Need for them
What is it?
July 4, 2015
July 4, 2015
July 4, 2015
Digital cameras
Electronic card readers
Portable video games
Printers
Satellite phones
Scanners
Smart ovens/dishwashers
Speech recognizers
Stereo systems
Teleconferencing systems
Televisions
Temperature controllers
Theft tracking systems
TV set-top boxes
VCRs, DVD players
Video game consoles
Video phones
Electronic instruments
Electronic toys/games
Factory control
Fax machines
Fingerprint identifiers
Home security systems
Life-support systems
Medical testing systems
Modems
MPEG decoders
Network cards
Network
switches/routers
On-board navigation
Pagers
Photocopiers
Washers and dryers
6 on
And the list goes on and
July 4, 2015
General-purpose microprocessor
CPU
GeneralPurpose
Microprocessor
Data Bus
RAM
ROM
I/O
Port
Timer
Serial
COM
Port
Address Bus
General-Purpose Microprocessor System
July 4, 2015
Microcontroller :
A smaller computer
On-chip RAM, ROM, I/O ports...
Example Motorolas 6811, Intels 8051, Zilogs Z8 and PIC 16X
CPU
I/O
Port
RAM ROM
Serial
Timer COM
Port
July 4, 2015
A single chip
Microcontroller
9
July 4, 2015
Microcontroller
CPU, RAM, ROM, I/O and
timer are all on a single chip
fix amount of on-chip ROM,
RAM, I/O ports
for applications in which cost,
power and space are critical
single-purpose
10
July 4, 2015
11
What is a Microcontroller?
A microcontroller is an entire computer
manufactured on a single chip
They have a high concentration of on-chip
facilities such as
serial ports,
parallel input/output ports,
Timers & counters,
interrupt control,
analog-to-digital converters,
random access memory, read only memory, etc.
July 4, 2015
12
Low space
Needs no extra circuitry
Possible to build handy systems
July 4, 2015
13
Common Microcontrollers
Atmel
ARM
Intel
8-bit
8XC42
MCS48
MCS51
8xC251
16-bit
MCS96
MXS296
National Semiconductor
COP8
Microchip
12-bit instruction PIC
14-bit instruction PIC
PIC16F84
16-bit instruction PIC
NEC
July 4, 2015
Motorola
8-bit
68HC05
68HC08
68HC11
16-bit
68HC12
68HC16
32-bit
683xx
Texas Instruments
TMS370
MSP430
Zilog
Z8
Z86E02
14
July 4, 2015
15
16
July 4, 2015
17
July 4, 2015
18
Microcontroller Architectures
Address Bus
CPU
Memory
Program
or Data
Data Bus
2n
Address Bus
CPU
Fetch Bus
Memory
Program
Address Bus 0
Data Bus
July 4, 2015
Von Neumann
Architecture
Harvard
Architecture
Data
19
About 8051
It was the first microcontroller developed
by Intel in early 80s
It is an 8 bit microcontroller & a 40 pin IC
Now produced by many companies in
many variations
The most popular microcontroller about
50% of market share
July 4, 2015
20
Typically contains
8 bit Processor (CPU).
4K Bytes ROM
128 Bytes RAM
two timer/counters (16 bit)
A serial port
4 general purpose parallel input/output port
Interrupt controller
The 8051 can address 64K of external data memory and 64K of
External program memory.
July 4, 2015
21
Block Diagram
External interrupts
Interrupt
Control
On-chip
ROM for
program
code
Timer/Counter
On-chip
RAM
Timer 1
Timer 0
Counter
Inputs
CPU
OSC
Bus
Control
4 I/O Ports
P0 P1 P2 P3
Serial
Port
TxD RxD
Address/Data
July 4, 2015
22
Feature
8051
ROM (program space in bytes) 4K
RAM (bytes)
128
Timers
2
I/O pins
32
Serial port
1
Interrupt sources
6
July 4, 2015
8052
8K
256
3
32
1
8
8031
0K
128
2
32
1
6
23
July 4, 2015
24
July 4, 2015
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
8051
(8031)
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
Vcc
P0.0(AD0
P
) 0.1(AD1)
P0.2(AD2
P
) 0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14
)P2.5(A13
P
) 2.4(A12
)P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)
25
July 4, 2015
26
July 4, 2015
27
28
July 4, 2015
29
Oscillator
XTAL Connection to 8051
July 4, 2015
30
N
C
EXTERNAL
OSCILLATOR
SIGNAL
XTAL2
XTAL1
GND
July 4, 2015
31
Example :
Find the machine cycle for
(a) XTAL = 11.0592 MHz
(b) XTAL = 16 MHz.
Solution:
(a) 11.0592 MHz / 12 = 921.6 kHz;
machine cycle = 1 / 921.6 kHz = 1.085 s
(b) 16 MHz / 12 = 1.333 MHz;
machine cycle = 1 / 1.333 MHz = 0.75 s
July 4, 2015
32
Registers
A
B
R0
DPTR
DPH
DPL
R1
R2
PC
PC
R3
R4
R5
R6
R7
Some 8-bitt Registers of
the 8051
July 4, 2015
33
Register
PC
ACC
B
PSW
SP
DPTR
RAM are all zero.
July 4, 2015
Reset Value
0000
0000
0000
0000
0007
0000
34
RESET Pin
Power-On RESET Circuit
Vcc
+
10 uF
31
30 pF
8.2 K
30 pF
11.0592 MHz
19
18
EA/VPP
X1
X2
9 RST
July 4, 2015
35
31
10 uF
30 pF
EA/VPP
X1
X2
RST
8.2 K
July 4, 2015
36
37
8k
32k
0000H
0000H
0FFFH
DS5000-32
8751
AT89C51
1FFFH
July 4, 2015
8752
AT89C52
7FFFH
38
30H
2FH
Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H
July 4, 2015
Register Bank 3
Register Bank 2
Register Bank 1( Stack)
Register Bank 0
39
7F
78
2E
2D
2C
2B
2A
29
28
27
26
25
24
23
1A
22
21
20
10
0F
07
08
06
05
04
July 4, 2015
03
02
01
00
40
AC
F0
RS1
RS0
OV
Carry flag
Auxiliary carry flag
Available to the user for general purpose
Register Bank selector bit 1
Register Bank selector bit 0
Overflow flag
User define bit
Parity flag Set/Reset odd/even parity
RS1
RS0
Register Bank
--
PSW.7
PSW.6
PSW.5
PSW.4
PSW.3
PSW.2
PSW.1
PSW.0
CY
AC
-RS1
RS0
OV
-P
Address
00H-07H
08H-0FH
10H-17H
18H-1FH
July 4, 2015
41
Note: X can be 0 or 1
July 4, 2015
42
7FH
Scratch pad RAM
30H
July 4, 2015
2FH
Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H
Register Bank 3
Register Bank 2
Register Bank 1( Stack)
Register Bank 0
43
Example:
MOV
MOV
MOV
PUSH
PUSH
PUSH
R6,#25H
R1,#12H
R4,#0F3H
6
1
4
0BH
0BH
0BH
0BH
0AH
0AH
0AH
0AH
F3
09H
09H
09H
12
09H
12
08H
08H
08H
25
08H
25
Start SP=07H
July 4, 2015
25
SP=08H
SP=09H
SP=08H
44
Function
Internal Ram
address
ACCUMULATOR
0E0
ARTHIMETIC
0F0
DPH
83
DPL
82
IE
0A8
IP
INTERRUPT PROIRITY
0B8
P0
80
P1
90
P2
0A0
P3
0B0
PCON
POWER CONTROL
87
PSW
0D0
July 4, 2015
45
Function
Internal Ram
address
SCON
98
SBUF
99
SP
TACK POINTER
81
TMOD
89
TCON
TIMER/COUNTER CONTROL
88
TL0
8A
TH0
8C
TL1
8B
TH1
8D
July 4, 2015
46
I/O PROGRAMMING
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
RST
(RXD)P3.0
(TXD)P3.1
(INT0)P3.2
(INT1)P3.3
(T0)P3.4
(T1)P3.5
(WR)P3.6
(RD)P3.7
XTAL2
XTAL1
GND
July 4, 2015
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
8051
(8031)
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
Vcc
P0.0(AD0)
P0.1(AD1)
P0.2(AD2)
P0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14)
P2.5(A13)
P2.4(A12)
P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)
47
July 4, 2015
48
Other Pins
P1, P2, and P3 have internal pull-up resisters.
P1, P2, and P3 are not open drain.
P0 has no internal pull-up resistors and does not connects to
Vcc inside the 8051.
P0 is open drain.
Compare the figures of P1.X and P0.X.
However, for a programmer, it is the same to program P0, P1,
P2 and P3.
All the ports upon RESET are configured as output.
July 4, 2015
49
50
Tri-state Buffer
Output
Input
Tri-state control
(active high)
July 4, 2015
Low
Highimpedance
(open-circuit)
51
A Pin of Port 1
Read latch
TB2
Vcc
Load(L1)
Internal CPU
bus
Write to latch
Clk
P1.X
pin
P1.X
Q
M1
TB1
P0.x
Read pin
July 4, 2015
8051 IC
52
Vcc
TB2
Vcc
Write to latch
Clk
P1.X
pin
P1.X
Q
M1
output 1
TB1
Read pin
July 4, 2015
8051 IC
53
Vcc
TB2
ground
Write to latch
Clk
P1.X
pin
P1.X
Q
M1
output 0
TB1
Read pin
July 4, 2015
8051 IC
54
BACK:
MOV
A,#55H
MOV
P1,A
ACALL
DELAY
CPL A
SJMP BACK
Let P1 toggle.
You can write to P1 directly.
July 4, 2015
55
TB2
2. MOV A,P1
Vcc
external pin=High
Load(L1)
P1.X pin
P1.X
Write to latch
Clk
M1
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
July 4, 2015
8051 IC
56
Vcc
2. MOV A,P1
TB2
Load(L1)
external pin=Low
MOV P1,#0FFH
Internal CPU bus
P1.X pin
P1.X
Write to latch
Clk
M1
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
July 4, 2015
8051 IC
57
BACK:
MOV
MOV
MOV
MOV
SJMP
A,#0FFH
P1,A
A,P1
P2,A
BACK
;A=11111111B
;make P1 an input port
;get data from P0
;send data to P2
July 4, 2015
58
July 4, 2015
59
July 4, 2015
60
Function
Pin
P3.0
RxD
10
P3.1
TxD
11
P3.2
INT0
12
P3.3
INT1
13
P3.4
T0
14
P3.5
T1
15
P3.6
WR
16
P3.7
RD
17
July 4, 2015
61
A Pin of Port 0
Read latch
TB2
Internal CPU
bus
Write to latch
Clk
P1.X
Q
TB1
Read pin
July 4, 2015
P0.X
pin
8051 IC
M1
P1.x
62
July 4, 2015
63
July 4, 2015
Port 0
P0.0
DS5000 P0.1
P0.2
8751
P0.3
P0.4
8951
P0.5
P0.6
P0.7
10 K
64
July 4, 2015
65
74LS373
PSEN
ALE
P0.0
P0.7
74LS373
G
D
OE
OC
A0
A7
D0
D7
EA
P2.0
A8
P2.7
A15
8051
July
4, 2015
ROM
66
P0.0
P0.7
A7
PSEN
ALE
1. Send address to
ROM
Address
D0
D7
EA
P2.0
A8
P2.7
A12
8051
July 4, 2015
ROM
67
74LS373
G
D
Address
OE
OC
A0
A7
D0
D7
EA
A8
P2.7
A12
8051
July
4, 2015
ROM
68
ALE Pin
The ALE pin is used for de-multiplexing the
address and data by connecting to the G pin of
the 74LS373 latch.
When ALE=0, P0 provides data D0-D7.
When ALE=1, P0 provides address A0-A7.
The reason is to allow P0 to multiplex address and
data.
July 4, 2015
69
Timer/Counter Logic
July 4, 2015
70
July 4, 2015
71
Timer 1 registers
TL1 ( timer 1 low byte )
TH1 ( timer 1 high byte )
July 4, 2015
72
July 4, 2015
73
July 4, 2015
74
July 4, 2015
75
Operation of Timer on
Mode-0
July 4, 2015
76
Operation of Timer in
Mode 1
July 4, 2015
77
Operation of Timer in
Mode 2
July 4, 2015
78
Operation of Timer in
Mode 3
July 4, 2015
79
8051 SERIAL
COMMUNICATION
July 4, 2015
80
Basics of serial
communication
July 4, 2015
81
July 4, 2015
82
July 4, 2015
83
July 4, 2015
84
SM0,SM1
SM0 and SM1 are D7 and D6 of the SCON
SM0
0
0
1
1
SM1
0
Serial Mode 0
1
Serial Mode 1,8 bit data,
1 stop bit, 1 start bit
0
Serial Mode 2
1
Serial Mode 3
July 4, 2015
85
D0
SMO
D
--
--
MOV A,PCON
SETB ACC.7
MOV PCON,A
July 4, 2015
--
GF1
GF0
PD
IDL
July 4, 2015
87
July 4, 2015
88
INTERRUPTS PROGRAMMING
July 4, 2015
89
INTERRUPTS PROGRAMMING
July 4, 2015
90
July 4, 2015
91
Step in enabling an
interrupt
July 4, 2015
92
Example:
Writing the ISR for Timer0 interrupt
ORG 0000H
;reset
LJMP MAIN
ORG 000BH
;Timer0 entry point
T0ISR: .
;Timer0 ISR begins
.
RETI
;return to main program
MAIN: .
;main program
.
.
END
July 4, 2015
93
July 4, 2015
94
July 4, 2015
95
July 4, 2015
96
Assembler Directives
ORG (origin)
Is to indicate beginning of the address
ORG 0000H or ORG 8000H
END
This indicates the assembler the end of the source file
It is last line of program
EQU (equate)
This is used to define a constant without occupying
memory location
COUNTEQU 25h
. .
MOV R3,#COUNT
July 4, 2015
97
ORG
MOV
MOV
MOV
ADD
ADD
HERE: SJMP
END
0H
R5,#25H
R7,#34H
Myfile.lst
A,#0
A,R5
A,#12H
HERE
Myfile.asm
ASSEMBLER
PROGRAM
Other obj file
Myfile.obj
LINKER
PROGRAM
Myfile.abs
OH
PROGRAM
Myfile.hex
July 4, 2015
98
NOP: No Operation
ORL: Bitwise OR
July 4, 2015
99
THANK YOU
ANY QUERIES
July 4, 2015
100