basic input/output

34
1 Basic Input/Output Basic Input/Output Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB.

Upload: magnar

Post on 28-Jan-2016

51 views

Category:

Documents


0 download

DESCRIPTION

Basic Input/Output. Wannachai Wannasawade Department of Computer Education Faculty of Technical Education, KMITNB. Basic Input/Output. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Basic Input/Output

1

Basic Input/OutputBasic Input/Output

Wannachai Wannasawade

Department of Computer Education

Faculty of Technical Education, KMITNB.

Page 2: Basic Input/Output

2

การทำ�างานของไมโครโพรเซสเซอร�ไม�ได้�ม�เฉพาะก�บหน�วยความจำ�า เทำ�าน��น แต่�ย�งม�การทำ�างานทำ�"เก�"ยวก�บอ#นพ$ทำ- เอาทำ�พ$ทำ หร&อทำ�"เร�ยกว�า “I/O

port” ซ("งเป็*นทำางทำ�"ใช้�ในการเช้&"อมต่�อแลกเป็ล�"ยนข�อม.ลระหว�างไมโครโพรเซสเซอร�ก�บอ$ป็กรณ์�ภายนอก

โด้ยม�ป็ระเภทำของอ#นพ$ทำ- เอาทำ�พ$ทำทำ�"เป็*นพ&�นฐานหล�ก2 ป็ระเภทำค&อ ขนานข�อมู�ล (Parallel)

อนกรมูข�อมู�ล (Serial)

การเช้&"อมต่�อแบบขนานข�อม.ลเป็*นว#ธี�การเช้&"อมต่�อทำ�"ง�ายทำ�"ส$ด้ โด้ย มองข�อม.ลเป็*นกล$�มก�อน ซ("งม�ขนาด้เทำ�าใด้ จำะข(�นอย.�ก�บขนาด้ของไมโคร

โพรเซสเซอร�แต่�ละต่�ว อาจำม�ขนาด้8 บ#ทำ 16 บ#ทำ 32 บ# ทำ หร&อ 64 บ#ทำ การ ส�ง หร&อร�บข�อม.ลต่ามจำ�านวนความกว�างของข�อม.ลทำ�"ไมโครโพรเซสเซอร�แต่�ละ

ต่�ว

Page 3: Basic Input/Output

3

ส�วนการเช้&"อมต่�อแบบอน$กรมข�อม.ล ม�ล�กษณ์ะการส�ง ข�อม.ลทำ�"

แต่กต่�างก�นออกไป็ค&อ ข�อม.ลจำะส�งไป็ในร.ป็แบบของบ#ทำทำ�"ต่�อเน&"องก�นไป็

ซ("งจำะม�การส�งข�อม.ลทำ�"ช้�ากว�าแบบขนานข�อม.ล แต่�ม�ข�อด้�ต่รงทำ�"ใช้�สาย

ส�ญญาณ์ทำ�"น�อยลง เช้�น การเช้&"อมต่�อแบบสองทำาง (Full-Duplex) จำะ

ใช้�สายส�ญญาณ์เพ�ยง3 เส�น Transmit Data

Receive Data

Common Ground between Computer

and Peripheral

Page 4: Basic Input/Output

4

Type of Input/Output

Parallel I/O Serial I/O Programmed I/O Interrupt-Driven I/O Direct Memory Access

Page 5: Basic Input/Output

5

เป็*นกล$�มค�าส�"งทำ�"ใช้�ในการต่#ด้ต่�อควบค$มอ$ป็กรณ์�อ#นพ$ทำ-เอาทำ� พ$ทำต่�าง ๆ โด้ยแบ�งได้� 2 ค�าส�"งหล�ก ๆ ค&อININ เป็*นค�าส�"งทำ�"ใช้�ในการอ�านข�อม.ลจำากอ$ป็กรณ์�อ#นพ$ทำ-เอา

ทำ�พ$ทำOUTOUT เป็*นค�าส�"งทำ�"ใช้�ในการเข�ยนข�อม.ลไป็ให�ก�บอ$ป็กรณ์�อ#น

พ$ทำ-เอาทำ�พ$ทำ

Page 6: Basic Input/Output

6

Instruction Data WidthInstruction Data Width FunctionFunction

IN AL,p8 8 Read byte from port p8(8 bit) into AL

IN AX,p8 16 Read word from port p8(8 bit) into AX

IN EAX,p8 32 Read doubleword from port p8(8 bit) into EAX

IN AL,DX 8 Read byte from port address by DX into AL

IN AX,DX 16 Read word from port address by DX into AX

IN EAX,DX 32 Read doubleword from port address by DX into

EAX

INSB 8 Read byte from port address by DX into Extra

Segment by DI = DI (+,-) 1

INSW 16 Read word from port address by DX into

Extra Segment by DI = DI (+,-) 2

INSD 32 Read doubleword from port address by DX

into Extra Segment by DI = DI (+,-) 4

Page 7: Basic Input/Output

7

InstructionInstruction Data WidthData Width FunctionFunction

OUT p8,AL 8 Write byte from AL to port p8(8 bit)

8OUT p ,AX 16 Write word from AX to port p8(8 bit)

OUT p8,EAX 32 Write double word from EAX to port p8(8

bit)

OUT DX,AL 8 Write byte from AL to port address by DX

OUT DX,AX 16 Write word from AX to port address by

DX

OUT DX,EAX 32 Write double word from EAX to port

address by DX

OUTSB 8 Write byte from Data Segment to port

address by DX SI= SI(+,-)1

OUTSW 16 Write word from Data Segment to port

address by DX SI= SI(+,-)2

OUTSD 32 Write double word from Data Segment to

port address by DX SI= SI(+,-)4

Page 8: Basic Input/Output

8

โด้ยทำ�"ค�าส�"งทำ��ง2 ป็ระเภทำจำะใช้�การร�บส�งข�อม.ลผ่�านทำางAccumulator ของไมโครโพรเซสเซอร� (AL, AX, EAX) ซ("งค�า I/O Address ทำ�"เก7บอย.�ใน Register DX จำะเป็*นแบบ 16 บ#ทำ หร&อ8 บ#ทำ ทำ�"ต่าม

หล�ง Opcode ทำาง Intel เร�ยก port ขนาด้8 บ#ทำ (p8) เป็*น Fixed Fixed

AddressAddress และ 16 บ#ทำทำ�"เร�ยกผ่�าน DX เป็*น Variable AddressVariable AddressI/O Address น#ยมเร�ยกว�า ““Port Number”Port Number” ซ(" ง Fixed port

number (p8) จำะใช้�สายส�ญญาณ์ Address 8 เส�นค&อ A0-A7 (0-255

หร&อ 0000H-00FFH) ส�วน Variable port number ใช้�สายส�ญญาณ์Address 16 เส�นค&อ A0-A15(0-65535 หร&อ 0000H-FFFFH) โด้ยทำ�" 256

ต่�าแหน�งแรกสามารถใช้�งานได้�ทำ��ง Fixed port number และ Variable port number แต่� หล�งจำากน��นจำะเป็*นของ Variable port number เทำ�าน��น

ส�าหร�บในเคร&"องไมโครคอมพ#วเต่อร�ทำ�"วไป็จำะใช้�งานอ#นพ$ทำ-เอาทำ�พ$ทำทำ�" ต่�าแหน�ง 00XXH-03XXH

Page 9: Basic Input/Output

9

Isolated I/O

1M X 8

64K X 8

Isolate I/O

FFFFFH

00000H

0FFFFH

00000H

เป็*น I/O ทำ�"แยกก�นอย�างอ#สระระหว�าง หน�วยความจำ�าของระบบก�บ I/O Address ทำ�"

ใช้�ก�บ I/O เร�ยกว�า “Ports” ข�อด้�ของว#ธี�การ น��ค&อ สามารถขยายขนาด้ของหน�วยความจำ�าได้�

โด้ยไม�ต่�องค�าน(งถ(งพ&�นทำ�"ของ I/O port ข�อ เส�ยของแบบน��ค&อ จำะต่�องม�การแยกส�ญญาณ์ ควบค$มทำ�"แน�นอน โด้ยใช้�ส�ญญาณ์ M/IO และ

W/R ให� เป็*น IORC ก�บ IOWCIsolate I/O ใช้�ในการควบค$มอ$ป็กรณ์�

โด้ยก�าหนด้ให�ใช้� port ขนาด้ 8 บ#ทำควบค$ม อ$ป็กรณ์�บน System Board ส�วน port

ขนาด้ 16 บ#ทำควบค$มการต่#ด้ต่�อทำ��งแบบอน$กรมและขนาน

Page 10: Basic Input/Output

10

Memory Mapped I/O

I/O

FFFFFH

00000H

Memory Mapped I/O

เป็*นระบบทำ�"น�าต่�าแหน�งของหน�วยความจำ�าของ ระบบมารวมก�บต่�าแหน�งของ I/O ทำ�าให�ม�ข�อเส�ยค&อ ไม�

สามารถใช้�งานหน�วยความจำ�าได้�ทำ��งหมด้ ข�อด้�ค&อ ลด้ ส�ญญาณ์ควบค$มทำ�"ไม�จำ�าเป็*นออก ทำ�าให�ลด้ขนาด้ของ

วงจำรลง และทำ�"ส�าค�ญทำ�"ส$ด้ค&อ ค�าส�"งทำ�"ใช้�งาน ไม�ใช้�ค�าส�"งทำ�" เก�"ยวก�บ I/O (IN, INS, OUT, OUTS) แต่�ใช้�ค�าส�"งทำ�"

ร�บส�งข�อม.ลระหว�างไมโครโพรเซสเซอร�ก�บหน�วยความจำ�า ก�บ I/O ได้�

Page 11: Basic Input/Output

11

Personal Computer I/O Mapped

0000Port H-03 H : จำองไว�ส�าหร�บระบบของเคร&"องPort 0400H-FFFFH : เป็9ด้ใช้�งานทำ�"วไป็

Page 12: Basic Input/Output

12

Basic Input

Page 13: Basic Input/Output

13

Basic Input InterfaceBasic Input Interface

Three-State Buffer

External TTL connect to inputs of buffer

Outputs of buffer connect to Data bus

Data bus size depend on version of the

Microprocessor such as 8086 has data bus 16 bits

80486 has data bus 32bits and Pentium II has data

bus 64 bits

Microprocessor can receive data when execute IN

Instruction

Page 14: Basic Input/Output

14

Basic I/O Interface : Output

Page 15: Basic Input/Output

15

Basic Output InterfaceBasic Output Interface

Receive data from Microprocessor and must hold

data for some external device

Latches or Flip-flop, like the buffers

Used OUT instruction then send data from AL,

AX, EAX

Data must hold until next OUT Instruction

execute

Page 16: Basic Input/Output

16

HandshakingHandshaking

Many I/O device much slower rate than the

microprocessor. Thus, How to control I/O device?

Handshaking or Polling

Synchronizes the I/O with the microprocessor

Example Parallel Printer BUSYBUSY indicates that the

printer busy and STBSTB is clock pulse used to send data

to printer

Page 17: Basic Input/Output

17

Input Device : ส�วนใหญ� จำะเป็*น TTL การเช้&"อมต่�อจำ(งไม�ม�ข�อย$�งยาก

อะไร ซ("งอ#นพ$ทำทำ�"ใช้�ส�วนใหญ� เป็*นอ$ป็กรณ์�จำ�าพวกสว#ต่ซ� แต่�ในบางคร��งอาจำ

ต่�องมาการด้�ด้แป็ลงแก�ไขบ�าง ซ("งส�วนใหญ�จำะใส� Resistor ทำ�"เร�ยกว�า R

Pull-up เพ&"อให�ทำ�างานได้�ถ.กต่�อง ( TTL Logic Level : “0” = 0.0

V - 0.8 V “1” = 2.0 V - 5.0 V ) โด้ยทำ�"ค�า R อย.�ระหว�าง 1K -

10K และนอกจำากป็:ญหาเร&"องของระด้�บส�ญญาณ์ ลอจำ#กแล�วย�งม�ป็:ญหาทำ�"

เก#ด้จำากการกด้สว#ต่ซ�ซ("งจำะพบมาก�บการน�าไป็ใช้�ในวงจำรทำ�"ม�ส�ญญาณ์นาฬิ#กา

เข�ามาเก�"ยวข�องแต่�สามารถแก�ไขได้�โด้ยการเพ#"มวงจำร

Page 18: Basic Input/Output

18

Vcc

2.2K

SPSTTTL O utput

Page 19: Basic Input/Output

19

Vcc

1K

SPST

Vcc

1K

Q

QQ

Q

Page 20: Basic Input/Output

20

Output Device : Output Device : เป็*นอ$ป็กรณ์�ทำ�"ม�ความหลากหลายในการเช้&"อมต่�อ แต่�

ส#"งทำ�"เหม&อนก�นค&อ แรงด้�นและกระแสไฟฟ=าทำ�"ใช้� โด้ยทำ�"แรงด้�นทำ�"ไมโคร

โพรเซสเซอร�ส�งออกมาในร.ป็แบบของส�ญญาณ์ TTL ม�ค�าแต่กต่�างจำากทำาง

ด้�านอ#นพ$ทำค&อ ทำ�"ระด้�บ “0” จำะให�แรงด้�นระหว�าง 0.0 V - 0.4 V และระด้�บ

“1” ทำ�" 2.4 V - 5.0 V ส�วนทำาง “ด้�านกระแสของระด้�บ 0” จำะอย.�ทำ�" 0.0 -

2.0 mA “และทำ�"ระด้�บ 1” จำะอย.�ทำ�" 0.0 - 400 A

Page 21: Basic Input/Output

21

Vcc

330

2N222218K

Input

Vcc

330

Input

Page 22: Basic Input/Output

22

A

+

-

12V

Input6.2K

Page 23: Basic Input/Output

23

I/O Port Address Decode

การ Decode Address ของ I/O จำะง�ายกว�าการ Decode

Address ของหน�วยความจำ�าเพราะ I/O ม�ต่�าแหน�งทำ�"แน�นอน และทำ�" แต่กต่�างก�นช้�ด้เจำนค&อ จำ�านวนของ ส�ญญาณ์ Address ทำ�"ใช้� เช้�น

Decode หน�วยความจำ�าจำะใช้�ส�ญญาณ์ Address A0-A31, A0-A24

หร&อ A0-A19 แต่� I/O ใช้�ส�ญญาณ์ Address ค&อ A0-A15 เทำ�าน��น

และส�ญญาณ์ควบค$มทำ�"ใช้� ค&อ IORC และ IOWC มาร�วมในการDecode ด้�วย

Page 24: Basic Input/Output

24

I/O Port Decoding

Page 25: Basic Input/Output

25

8 Bit Decode

Page 26: Basic Input/Output

26

16 Bit Decode

Page 27: Basic Input/Output

27

16 Bit 2 Bank Decode

Page 28: Basic Input/Output

28

16 Bit Decode

Page 29: Basic Input/Output

29

32 Bit Decode

Page 30: Basic Input/Output

30

Use 8 LED’s

8088MinimumMode

A18

A0

:

D7

D6

IOR

IOW

A19

D5

D4

D3

D2

D1

D0

:

mov al, 55

out dx, al

:

:

:

Page 31: Basic Input/Output

31

Use of 74LS245 and Address Decoder

:

mov al, 55

mov dx, F000

out dx, al

:

8088MinimumMode

A18

A0

:

D7

D6

IOR

IOW

A19

D5

D4

D3

D2

D1

D0

74LS245

B0

B1

B2

B3

B4

B5

B6

B7

A0

A1

A2

A3

A4

A5

A6

A7

E DIR 5V

A15

A14

A13

A12

A11

A10

A9A8A7A6A5A4A3A2A1A0IOW

Page 32: Basic Input/Output

32

Use of 74LS373 and Address Decoder

:

mov al, 55

mov dx, F000

out dx, al

:

A15

8088MinimumMode

A18

A0

:

D7

D6

IOR

IOW

A19

D5

D4

D3

D2

D1

D0

A14

A13

A12

A11

A10

A9A8A7A6A5A4A3A2A1A0IOW

74LS373

Q0

Q1

Q2

Q3

Q4

Q5

Q6

Q7

D0

D1

D2

D3

D4

D5

D6

D7

OELE

Page 33: Basic Input/Output

33

Use of 74LS245 and Address Decoder

:

mov dx, F000

in al, dx

:A15

8088MinimumMode

A18

A0

:

D7

D6

IOR

IOW

A19

D5

D4

D3

D2

D1

D0

A14

A13

A12

A11

A10

A9A8A7A6A5A4A3A2A1A0IOR

5V

74LS245

B0

B1

B2

B3

B4

B5

B6

B7

A0

A1

A2

A3

A4

A5

A6

A7

E DIR

Same address for input and output?

Page 34: Basic Input/Output

34

Polling

mov dx, F000

in al, dx

L1: cmp al, FF

je L1

:

:

A15

8088MinimumMode

A18

A0

:

D7

D6

IOR

IOW

A19

D5

D4

D3

D2

D1

D0

74LS245

B0

B1

B2

B3

B4

B5

B6

B7

A0

A1

A2

A3

A4

A5

A6

A7

E DIR

A14

A13

A12

A11

A10

A9A8A7A6A5A4A3A2A1A0IOR

5V