8051 Chap1 Introduction PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

ĐH Bách Khoa TP.

HCM Lê Chí Thông

Microprocessing Systems

Lê Chí Thông
Ref. I. Scott Mackenzie, The 8051 Microcontroller

Objectives

• Introduction fundamentals and applications of


microprocessors and microcomputers.
• Architecture, the instruction set, and applications of
8051 microcontroller family
• Basic applications of microprocessors, such as
input/output, analog-digital conversion (ADC), and
digital-analog conversion (DAC), and data acquisition.

Ref. I. Scott Mackenzie Lê Chí Thông 2

sites.google.com/site/chithong 1
ĐH Bách Khoa TP.HCM Lê Chí Thông

Textbooks

• I. Scott MacKenzie, ”The 8051 Microcontroller”, 2nd


Edition, Prentice-Hall, 1995
• Kenneth J. Ayala, “The 8051 Microcontroller:
Architecture, Programming, and Applications”, West
Publishing Company

Ref. I. Scott Mackenzie Lê Chí Thông 3

Chapter 1
Introduction to Microcontrollers

Ref. I. Scott Mackenzie Lê Chí Thông 4

sites.google.com/site/chithong 2
ĐH Bách Khoa TP.HCM Lê Chí Thông

These are …

embedded systems

An embedded system is a system in which a


processor/microcontroller/computer is embedded to
perform a specific task or
Ref. I. Scott Mackenzie
tasks
Lê Chí Thông 5

Microprocessors
Control Unit
• Integrated ALU and CU (CU)

• No RAM, ROM, I/O on CPU chip itself


Arithmetic
• Example: Intel’s x86, Motorola’s 680x0 Logical Unit (ALU)

Central Processing Unit (CPU)

Data Bus
Many chips on mother’s board
CPU
General- Serial
Purpose RAM ROM I/O Timer Port
Micro- Port
processor
Address Bus

General-Purpose Microprocessor
Ref. I. Scott Mackenzie Lê Chí Thông System 6

sites.google.com/site/chithong 3
ĐH Bách Khoa TP.HCM Lê Chí Thông

FIGURE 1–2 Block diagram of a microcomputer system

Architecture of computers

Ref. I. Scott Mackenzie Lê Chí Thông 7

FIGURE 1–3 The central processing unit (CPU)

Architecture of CPU

PC-
Program counter

Ref. I. Scott Mackenzie Lê Chí Thông 8

sites.google.com/site/chithong 4
ĐH Bách Khoa TP.HCM Lê Chí Thông

FIGURE 1–4 Bus activity for an opcode fetch cycle

Opcode fetch, decode, execution

Ref. I. Scott Mackenzie Lê Chí Thông 9

FIGURE 1–5 Levels of software

Shell, GUI – user


- hardware

Utilities

Booster loader,
BIOS

Keyboard, monitor
Other hardwires

Ref. I. Scott Mackenzie Lê Chí Thông 10

sites.google.com/site/chithong 5
ĐH Bách Khoa TP.HCM Lê Chí Thông

FIGURE 1–6 Detailed block diagram of a microcomputer system

Ref. I. Scott Mackenzie Lê Chí Thông 11

Microcontrollers
• Integrates CPU, RAM, ROM, I/O ports, … on a
single chip
• Sometimes called a "computer on a chip"
• Typically used in embedded applications
• Example: Motorola’s 6811, Intel’s 8051, Zilog’s Z8
and PIC 16X

CPU RAM ROM


A single chip
Serial
I/O Timer COM
Port
Port

Microcontroller
Ref. I. Scott Mackenzie Lê Chí Thông 12

sites.google.com/site/chithong 6
ĐH Bách Khoa TP.HCM Lê Chí Thông

Microcontroller Architectures
Memory
0
Address Bus
Program
CPU Data Bus + Data Von Neumann
2n
Architecture
Memory
0
Address Bus
Program
CPU Fetch Bus Harvard
Address Bus 0
Architecture
Data Bus Data

Ref. I. Scott Mackenzie Lê Chí Thông 13

Embedded System
• Embedded system: the processor is embedded into
that application.
• An embedded product usually uses a microcontroller
to do one task only.
• In an embedded system, there is only one application
software that is typically burned into ROM

Ref. I. Scott Mackenzie Lê Chí Thông 14

sites.google.com/site/chithong 7
ĐH Bách Khoa TP.HCM Lê Chí Thông

Embedded System

Sensor conditioning

Output interfaces
sensor
actuator

sensor Microcontroller
(uC)
indicator

sensor

Ref. I. Scott Mackenzie Lê Chí Thông 15

Representation of Number Systems

• Positive radix, positional number systems


• A number with radix r is represented by a string of
digits:
An - 1An - 2 … A1A0 . A- 1 A- 2 … A- m + 1 A- m
in which 0 < Ai < r and . is the radix point.
• The string of digits represents the power series:

(Number)r = ( i=n-1
Ai r + i ) ( j=-1

Aj r j )
i=0 j=-m
(Integer Portion) + (Fraction Portion)
Ref. I. Scott Mackenzie Lê Chí Thông 16

sites.google.com/site/chithong 8
ĐH Bách Khoa TP.HCM Lê Chí Thông

Representation of Number Systems

General Decimal Binary


Radix (Base) r 10 2
Digits 0 => r - 1 0 => 9 0 => 1
0 r0 1 1
1 r1 10 2
2 r2 100 4
3 r3 1000 8
Powers of 4 r4 10,000 16
Radix 5 r5 100,000 32
-1 r -1 0.1 0.5
-2 r -2 0.01 0.25
-3 r -3 0.001 0.125
-4 r -4 0.0001 0.0625
-5 r -5 0.00001 0.03125
Ref. I. Scott Mackenzie Lê Chí Thông 17

Decimal (Radix r = 10)

4 0 7 . 6 2 5
102 101 100 . 10-1 10-2 10-3
4x102 0x101 7x100 . 6x10-1 2x10-2 5x10-3
400 0 7 . 0.6 0.02 0.005

400 + 0 + 7 + 0.6 + 0.02 + 0.005 = 407.625


Binary (Radix r = 2)
1 0 1 . 0 1 1
22 21 20 . 2-1 2-2 2-3
1x22 0x21 1x20 . 0x2-1 1x2-2 1x2-3
4 0 1 . 0 0.25 0.125

101.011 B = 4 + 0 + 1 + 0 + 0.25 + 0.125 = 5.375


Ref. I. Scott Mackenzie Lê Chí Thông 18

sites.google.com/site/chithong 9
ĐH Bách Khoa TP.HCM Lê Chí Thông

Hexadecimal or Hex (Radix r = 16)


Hexadecimal Decimal Binary Hexadecimal Decimal Binary
0 0 0000 8 8 1000
1 1 0001 9 9 1001
2 2 0010 A 10 1010
3 3 0011 B 11 1011
4 4 0100 C 12 1100
5 5 0101 D 13 1101
6 6 0110 E 14 1110
7 7 0111 F 15 1111

5 A 0 . 4 D 1
162 161 160 . 16-1 16-2 16-3
5x162 10x161 0x160 . 4x16-1 13x16-2 1x16-3
1280 160 0 . 0.25 0.0508 0.0002

5A0.4D1 H = 1280 + 160 + 0 +Lê0.25


Ref. I. Scott Mackenzie
+ 0.0508 + 0.0002 = 1440.301
Chí Thông 19

Converting decimal to binary


8 . 625 D = ? B

8 :2 = 4 remainder 0
4 :2 = 2 remainder 0
2 :2 = 1 remainder 0
1 :2= 0 remainder 1

1 0 0 0 . 1 0 1 B

0.625 x 2 = 1.25 save the integer digit 1


0.25 x 2 = 0.5 save the integer digit 0
0.5 x 2 = 1.0 save the integer digit 1

Ref. I. Scott Mackenzie Lê Chí Thông 20

sites.google.com/site/chithong 10
ĐH Bách Khoa TP.HCM Lê Chí Thông

Converting decimal to hex


1480.4296875D=?H

1480 : 16 = 92 remainder 8
92 : 16 = 5 remainder 12
5 : 16 = 0 remainder 5

5 C 8 . 6 E H

0.4296875 x 16 = 6.875 save the integer digit 6


0.875 x 16 = 14.0 save the integer digit 14

Ref. I. Scott Mackenzie Lê Chí Thông 21

Converting binary to hex


0 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 . 0 1 1 0 1 0 10 B
3 B 5 D . 6 A H

Converting binary to octal

2 C 9 . E 8 H

0 01011001001.11101000 B

Ref. I. Scott Mackenzie Lê Chí Thông 22

sites.google.com/site/chithong 11
ĐH Bách Khoa TP.HCM Lê Chí Thông

BCD (Binary Coded Decimal)


Decimal BCD
(8 4 2 1)
0 0000
1 0001 Ex: 12 = 0001 0010 (BCD)
2 0010 39 = 0011 1001 (BCD)
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

Ref. I. Scott Mackenzie Lê Chí Thông 23

ASCII Code
b6 b5 b 4
000 001 010 011 100 101 110 111
b3b2b1b0 Hex 0 1 2 3 4 5 6 7

0000 0 NUL DLE SP 0 @ P ` p


0001 1 SOH DC1 ! 1 A Q a q
0010 2 STX DC2 ” 2 B R b r
0011 3 ETX DC3 # 3 C S c s
0100 4 EOT DC4 $ 4 D T d t
0101 5 ENQ NAK % 5 E U e u
0110 6 ACK SYN & 6 F V f v
0111 7 BEL ETB ’ 7 G W g w
1000 8 BS CAN ( 8 H X h x
1001 9 HT EM ) 9 I Y i y
1010 A LF SUB * : J Z j z
1011 B VT ESC + ; K [ k {
1100 C FF FS , < L \ l |
1101 D CR GS - = M ] m }
1 1 Mackenzie
Ref. I. Scott 10 E SO RS Lê. Chí Thông > N ^ n ~ 24
1111 F SI US / ? O _ o DEL

sites.google.com/site/chithong 12
ĐH Bách Khoa TP.HCM Lê Chí Thông

Boolean (Logical) Operations


a NOT a a b a AND b
0 1 0 0 0
1 0 0 1 0
1 0 0
1 1 1

a b a OR b a b a XOR b
0 0 0 0 0 0
0 1 1 0 1 1
1 0 1 1 0 1
1 1 1 1 1 0

Ref. I. Scott Mackenzie Lê Chí Thông 25

Applying Boolean Operations

• Force a bit or bits to zero


– Sometimes called "masking out bits"
• Use a "mask" byte with
– 0's in positions to be cleared (forced to 0)
– 1's in positions to be unchanged
• Perform an AND with the mask
– x AND 0 = 0 (domination)
– x AND 1 = x (identity)

Ref. I. Scott Mackenzie Lê Chí Thông 26

sites.google.com/site/chithong 13
ĐH Bách Khoa TP.HCM Lê Chí Thông

Applying Boolean Operations

• Force a bit or bits to one


– Sometimes called "setting bits"
• Use a "mask" byte with
– 1's in positions to be set (forced to 1)
– 0's in positions to be unchanged
• Perform an OR with the mask
– x OR 0 = x (identity)
– x OR 1 = 1 (domination)

Ref. I. Scott Mackenzie Lê Chí Thông 27

Applying Boolean Operations

• Toggle a bit or bits


– Sometimes called "flipping or complementing
bits"
• Use a "mask" byte with
– 1's in positions to be toggled (complemented)
– 0's in positions to be unchanged
• Perform an XOR with the mask
– x XOR 0 = x (identity)
– x XOR 1 = NOT x
Ref. I. Scott Mackenzie Lê Chí Thông 28

sites.google.com/site/chithong 14
ĐH Bách Khoa TP.HCM Lê Chí Thông

Combining Bits in Separate Bytes

• Bit patterns from two bytes are to be combined


– The important bits of each byte must be aligned with 0 (and
unimportant) bits in the other byte
• The OR of the two bytes, combines them into one
– The bold bits are the important ones:
00110000
OR 00001010
00111010

Ref. I. Scott Mackenzie Lê Chí Thông 29

Shifting

• Move bits in a byte to the left or right


– 11011100 shifted left is 10111000
– 11011100 shifted right is 01101110
• In these examples, a zero (0) was brought in to
fill the vacated position
– Variations on the basic shift fill this position
differently

Ref. I. Scott Mackenzie Lê Chí Thông 30

sites.google.com/site/chithong 15
ĐH Bách Khoa TP.HCM Lê Chí Thông

Rotating

• Move bits in a byte to the left or right in a


circular pattern
– 11011100 rotated left is 10111001
– 11011100 rotated right is 01101110
• In these examples, the bit shifted out is used to
fill the vacated position
– There are some variations of this behavior as well

Ref. I. Scott Mackenzie Lê Chí Thông 31

Application of Shifts

• When a byte (or word) is interpreted


numerically (as a binary representation of a
number)…
– Left shift is equivalent to multiplication by 2
– Right shift is equivalent to division by 2
– 5CH shifted left becomes B8H
• 92 * 2 = 184
– 5CH shifted right is 2EH
• 92 / 2 = 46 (remainder if any is thrown away)

Ref. I. Scott Mackenzie Lê Chí Thông 32

sites.google.com/site/chithong 16
ĐH Bách Khoa TP.HCM Lê Chí Thông

Multiplication Tricks

• Every multiplication can be accomplished by


shifting and adding
– Just regroup using only multiplications by powers
of 2 and additions
• 10 * n = (8 + 2) * n
• =8*n+2*n
– or
• 10 * n = (2 * (4 + 1)) n
• = 2 * (4 * n + n)

Ref. I. Scott Mackenzie Lê Chí Thông 33

Memory

• A computer system
0000 3F
component that allows
the storage and retrieval 0001 2C
of data 0002 41
• Main memory is usually 0003 FF
called RAM 0004 00
• Memory is usually 0005 1E
organized as a table of
bytes or words Addresses Data values
are usually are usually
shown in bytes
hexadecimal
Ref. I. Scott Mackenzie Lê Chí Thông 34

sites.google.com/site/chithong 17
ĐH Bách Khoa TP.HCM Lê Chí Thông

RAM and ROM

• RAM: Random Access Memory


– Access time does not vary by address
– Read & write memory
– Typically volatile
• ROM: Read Only Memory
– Also a random access memory
– Retains data even when power is removed

Ref. I. Scott Mackenzie Lê Chí Thông 35

RAM and ROM


RAM ROM

Ref. I. Scott Mackenzie Lê Chí Thông 36

sites.google.com/site/chithong 18
ĐH Bách Khoa TP.HCM Lê Chí Thông

References

• I. Scott Mackenzie, The 8051 Microcontroller


• Nguyễn Trọng Luật, Bài giảng Kỹ Thuật Số
• Các tài liệu trên Internet không trích dẫn hoặc không ghi tác
giả

Ref. I. Scott Mackenzie Lê Chí Thông 37

sites.google.com/site/chithong 19

You might also like