hỌ vi ĐiỀu khiỂn 8051 - hcmut.edu.vnbmthanh/vixuly/vxl-ch03-8051-3.1_3.2_v03.pdfother pins...

48
HỌ VI ĐIỀU KHIỂN 8051 1 Hiệu đính từ slide của thầy Hồ Trung Mỹ Bộ môn Điện tử - DH BK TPHCM

Upload: dangdieu

Post on 07-Mar-2018

221 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

HỌ VI ĐIỀU KHIỂN 8051

1

Hiệu đính từ slide của thầy Hồ Trung Mỹ

Bộ môn Điện tử - DH BK TPHCM

Page 2: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Nội dung3.1 Giới thiệu họ vi điều khiển 8051

3.2 Kiến trúc phần cứng 8051

2

Page 3: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

3.1 Giới thiệu

họ vi điều khiển 8051

3

Page 4: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Các kiến trúc vi điều khiển

4

CPU

Program

+ Data

Address Bus

Data Bus

Memory

Von Neumann

Architecture

CPU

ProgramAddress Bus

Data Bus

Harvard

Architecture

Memory

Data

Address Bus

Fetch Bus

0

0

0

2n

Page 5: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Họ VĐK 8051 8051 là vi điều khiển đầu tiên của họ vi điều khiển MCS51

được Intel sản xuất vào năm 1980. Họ MCS51 là họ 8-bit cókhả năng định địa chỉ 64KB bộ nhớ chương trình và 64KBbộ nhớ dữ liệu.

5

Page 6: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

So So sánhsánh cáccác dòngdòng MCSMCS--5151

6

3256 bytes8K EPROM8752

3256 bytes0K8032

3256 bytes8K ROM8052

2128 bytes4K EPROM8751

2128 bytes0K8031

2128 bytes4K ROM8051

TimersOn-Chip Data

Memory

On-Chip Code

Memory

Part

Number

Page 7: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

3.2 Kiến trúc phần cứng 8051

7

Page 8: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

3.2.1 Sơ đồ khối 8051/8031

8

Page 9: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

9

Page 10: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Ý nghĩa các chân trên MCU 8051

Port 0 (Cổng 0)

Port 0 là một port hai chức năng trên các chân 32–39. Trong các thiết kế cỡ nhỏ (không dùng bộ nhớ mở rộng) nó có chức năng như các đường I/O. Đối với các thiết kế lớn với bộ nhớ mở rộng, nó được dồn kênh giữa bus địa chỉ và bus dữ liệu.

Port 1 (Cổng 1)

Port 1 là cổng dành riêng cho nhập/xuất trên các chân 1–8. Các chân được ký hiệu P1.0, P1.1, P1.2, ... có thể dùng cho giao tiếp với các thiết bị ngoài nếu cần. Port 1 không có chức năng khác, vì vậy chúng chỉ được dùng cho giao tiếp với các thiết bị ngoài.

Port 2 (Cổng 2)

Port 2 là một cổng công dụng kép trên các chân 21–28 được dùng như các đường xuất nhập hoặc là byte cao của bus địa chỉ đối với các thiết kế dùng bộ nhớ mở rộng.

Port 3 (Cổng 3)

Port 3 cũng là một cổng công dụng kép trên các chân 10–17. Các chân của port này có nhiều chức năng, các công dụng chuyển đổi có liên hệ với các đặc tính đặc biệt của 8051/8031

10

Page 11: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Các chức năng chuyển đổi ở Port 3

11

Page 12: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

12

Page 13: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

3.2.2 Cấu trúc cổng I/O

Khả năng lái là 4 tải TTL loại LS (Low Power Schottky)

với các cổng P1, P2, và P3; và 8 tải TTL loại LS với cổng

P0.

Chú ý là điện trở kéo lên bên trong không có trong Port 0

(ngoại trừ lúc làm việc như bus dữ liệu / địa chỉ bên

ngoài). Điện trở kéo lên có thể được sử dụng với P0 tùy

theo đặc tính vào của thiết bị mà nó lái.

13

Page 14: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

14

Page 15: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

15

Page 16: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

A Pin of Port 1

16

8051 IC

D Q

Clk Q

Vcc

Load(L1)

Read latch

Read pin

Write to latch

Internal CPU

bus

M1

P1.X

pinP1.X

TB1

TB2

P0.x

Page 17: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Writing “1” to Output Pin P1.X

17

D Q

Clk Q

Vcc

Load(L1)

Read latch

Read pin

Write to latch

Internal CPU

bus

M1

P1.X

pinP1.X

8051 IC

2. output pin is

Vcc1. write a 1 to the pin1

0 output 1

TB1

TB2

Page 18: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Writing “0” to Output Pin P1.X

18

D Q

Clk Q

Vcc

Load(L1)

Read latch

Read pin

Write to latch

Internal CPU

bus

M1

P1.X

pinP1.X

8051 IC

2. output pin is

ground1. write a 0 to the pin0

1 output 0

TB1

TB2

Page 19: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Reading “High” at Input Pin

19

D Q

Clk Q

Vcc

Load(L1)

Read latch

Read pin

Write to latch

Internal CPU bus

M1

P1.X pin

P1.X

8051 IC

2. MOV A,P1

external pin=High1. write a 1 to the pin MOV

P1,#0FFH

1

0

3. Read pin=1 Read latch=0

Write to latch=1

1

TB1

TB2

Page 20: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Reading “Low” at Input Pin

20

D Q

Clk Q

Vcc

Load(L1)

Read latch

Read pin

Write to latch

Internal CPU bus

M1

P1.X pin

P1.X

8051 IC

2. MOV A,P1

external pin=Low1. write a 1 to the pin

MOV P1,#0FFH

1

0

3. Read pin=1 Read latch=0

Write to latch=1

0

TB1

TB2

Page 21: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

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.

21

Page 22: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

A Pin of Port 0

22

8051 IC

D Q

Clk Q

Read latch

Read pin

Write to latch

Internal CPU

bus

M1

P0.X

pinP1.X

TB1

TB2

P1.x

Page 23: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Port 0 with Pull-Up Resistors

23

P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7

DS5000

8751

8951

Vcc10 K

Po

rt

0

Page 24: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Port 3 Alternate Functions

24

17RDP3.7

16WRP3.6

15T1P3.5

14T0P3.4

13INT1P3.3

12INT0P3.2

11TxDP3.1

10RxDP3.0

PinFunctionP3 Bit

Page 25: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

3.2.3 Định thì CPUChu kỳ lệnh, chu kỳ máy và trạng thái

25

Page 26: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

12MHz internal clock

6 state cycles

26

Page 27: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Dồn kênh bus địa chỉ (byte thấp) và bus dữ liệu

27

Page 28: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Truy cập bộ nhớ chương trình bên ngoài

28

Page 29: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

29

Page 30: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

30

Page 31: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

31

Page 32: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

3.2.4 Cấu trúc bộ nhớ 8051

32

Page 33: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Tóm tắt bộ nhớ dữ liệu trên chip

33

Page 34: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Bộ nhớ dữ liệu 8051

34

Page 35: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Lower 128 Bytes of Internal RAM

35

20H-2FH: 128 Bit-addressable bits occupying bit address 00H-7FH.

30H-7FH: General purpose RAM (can be accessed through direct or

indirect addressing)

Page 36: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Upper 128 Bytes of Internal RAM

36

Page 37: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Vùng nhớ 8032/8052

37

MOV A, 5FHMOV A, FFH

MOV Ri, #5FH ( I = 0 or 1)MOV A, @Ri

Page 38: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Tóm tắt thanh ghi PSW

38

Page 39: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Tóm tắt thanh ghi PCON

39

Page 40: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Truy cập bộ nhớ chương trình bên ngoài

40

Page 41: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Định thì đọc bộ nhớ chương trình bên ngoài (PCH byte của PC và PCL là byte thấp của PC)

41/PSEN ở mức thấp trong thời gian lấy lệnh

Page 42: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Truy cập bộ nhớ dữ liệu bên ngoài

42

Page 43: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Giản đồ định thì cho lệnh MOVX

43

Page 44: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Mạch giải mã địa chỉ các EPROM 8KB và RAM 8KB với hệ 8051

44

Page 45: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Phủ lấp vùng nhớ dữ liệu và chương trình bên ngoài

45

Page 46: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

3.2.8 Hoạt động reset

46

Page 47: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Mạch reset hệ thống

47

Vc(0+) = Vc(0-)

Page 48: HỌ VI ĐIỀU KHIỂN 8051 - hcmut.edu.vnbmthanh/ViXuLy/VXL-Ch03-8051-3.1_3.2_v03.pdfOther Pins P1, P2, and P3 have internal pull-up resisters. P1, P2, and P3 are not open drain

Các giá trị thanh ghi sau khi reset hệ thống

48