24
Lecture 02 1 Microprocessor and Microcontroller Architectures Z80 Architecture ในการที่จะเขียนโปรแกรม ให้มีประสิทธิภาพมากๆ นั ้นเราจาเป็นที่จะต้อง เข้าใจถึงส่วนประกอบภายใน และการทางานต่างๆ ของ Microprocessor และ Microcomputer รูปแสดง Block diagram ของ Z80 รูปแสดงโปรแกรมมิ ่งโมเดลของ Z80 แสดงส่วนต่างๆที ่โปรแกรมเมอร์สามารถใช้หรือเปลี ่ยนแปลงได้

Lecture 02 Microprocessor and Microcontroller Architectures

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

1

Microprocessor and Microcontroller Architectures Z80 Architecture

ในการท่ีจะเขยีนโปรแกรม ให้มีประสทิธิภาพมากๆ นัน้เราจ าเป็นที่จะต้อง เข้าใจถึงสว่นประกอบภายใน และการท างานตา่งๆ ของ Microprocessor และ Microcomputer

รูปแสดง Block diagram ของ Z80

รูปแสดงโปรแกรมม่ิงโมเดลของ Z80 แสดงส่วนต่างๆที่โปรแกรมเมอร์สามารถใช้หรือเปลี่ยนแปลงได้

Page 2: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

2

ALU เป็นสว่นท่ีกระท าการทางคณิตศาสตร์ กบัข้อมลู เนื่องจากทีต้่องมี Input เข้าไปสองตวั ดงันัน้จะต้องมีตวัพกัข้อมลู Accumulator (A) ซึง่จะใช้เป็นได้ทัง้ที่เก็บข้อมลูเข้า และเก็บผลลพัธ์ที่ได้ ส าหรับคา่สถานะตา่งๆ ที่เกิดจากการประมวลผลข้อมลู มนัจะถกูบนัทกึไว้ใน Flag Register (F) มีข้อมลูบาง Bit ที่อยูใ่น F ที่เป็นผลมาจากการท างานของสว่นอื่นใน Z80 โดยการใช้ค าสัง่พเิศษเราจะสามารถตรวจสอบคา่สถานะเหลา่นีไ้ด้ เพือ่ใช้เป็นเง่ือนไขในการท างานท่ีเหมาะสมตอ่ไป

Register A และ F จะแสดงเป็น Register คู ่คือ A, A’ กบั F, F’ แตส่ามารถใช้งานได้เพียงชดุเดยีวเทา่นัน้ ถ้าต้องการใช้งานอีกชดุหนึง่ จะท าได้โดยใช้ค าสัง่ในการสลบัคา่ระหวา่ง A กบั A’ และ F กบั F’

General Purpose Registers ใช้ในการเก็บข้อมลูเพื่อการประมวลผลที่รวดเร็ว เพราะมนัจะเช่ือมตรงเข้ากบั Internal Data Bus และสามารถอ้างถึงได้โดยตรงใน

ค าสัง่ทีใ่ช้ จากข้อจ ากดัของจ านวน Bit ในรหสัค าสัง่ (Opcode) ท าให้ Register แบบนีม้ีจ านวนจ ากดั

General-purpose Register นีเ้ป็นแบบ 8 Bit จ านวนทัง้หมด 6 ตวัคือ B, C, D, E, H, L ซึง่จะมีอยูส่องชดุ (B’, C’, D’, E’, H’, L’) และใช้งานมนัได้เพียงทีละชดุเทา่นัน้ การใช้งานอกีชดุหนึง่ต้องใช้ค าสัง่ในการสลบัคา่ จะมี Register เพียงตวัเดยีวที่จะสามารถ รับ/สง่ ข้อมลูจาก Internal Data Bus ได้ที่เวลาใดๆเทา่นัน้ และ Register เหลา่นีม้นัจะตอ่อยูก่บั Address Bus ด้วย โดยการจบัเป็นคูข่อง Register ให้ได้เป็น 16 Bit (BC, DE, HL) มนัก็จะสามารถที่จะใช้เป็นท่ีเก็บข้อมลูแบบ 16 Bit ได้ หรือใช้ในการเก็บคา่ Address ของหนว่ยความจ าทีเ่ก็บข้อมลู (Pointer)

Address Registers ใช้ในการเก็บคา่ต าแหนง่ของข้อมลู (Pointer) ในการใสข้่อมลูเข้าใน Address register ที่มีความกว้างมากกวา่ Internal data bus จาก

รูป Address Register จะแบง่เป็นสองสว่นคือ Low byte (L) และ High byte (H) การ Load ข้อมลูจะท าสองครัง้

Program Counter (PC) ต้องมใีน Microprocessor ทกุๆ ตวั โดยเก็บคา่ต าแหนง่ Memory ของรหสัค าสัง่ตอ่ไปที่ Microprocessor จะอา่น เมื่อ Microprocessor เร่ิมท างาน มนัจะสง่คา่ที่อยูใ่น PC ลงไปใน Address bus และไปถึง Program Memory จากนัน้ Program Memory จะสง่ค าสัง่ในต าแหนง่นัน้ๆ กลบัมา Microprocessor จะน าค าสัง่ที่ได้มาใช้เป็น Opcode แล้วท างานตาม ในขณะเดียวกนั คา่ของ PC จะเพิ่มขึน้ 1

Stack Pointer (SP) จะใช้ในการสร้าง Software stack โดยมนัจะชีอ้ยูท่ี่ (เก็บคา่ Address ของ) ต าแหนง่บนสดุของ Stack ใน Memory

Index Register X (IX), Index Register Y (IY) จะใช้ในการเก็บคา่ Address ของข้อมลู (เป็น Pointer ที่ชีไ้ปยงัข้อมลู) ที่ต้องการ

Interrupt-Page Address Register (I)

มีประโยชน์ใช้งานในขบวนการ Interrupt

Memory-Refresh Register (R)

ใช้ในการท า Refresh ของ Dynamic RAM (DRAM)

Page 3: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

3

Instruction Register (IR)

ท าหน้าที่ในการเก็บรหสัค าสัง่ที่ Z80 จะท า โดยมนัจะมี Instruction Decoder ในการตีความรหสัค าสัง่ และมี Controller-Sequencer ในการควบคมุจงัหวะการท างานของสว่นตา่งๆ ตามขัน้ตอนของค าสัง่นัน้ๆ สว่นของ Control Section นีย้งัจะท าหน้าที่ในการสร้างสญัญาณ ออกไปยงั Control Bus เพื่อควบคมุอปุกรณ์ภายนอกของ Z80 อีกด้วย

Stack เป็นท่ีเก็บข้อมลูแบบ LIFO ข้อมลูที่ถกูเก็บเข้าไปก่อนจะออกมาทีห่ลงั ซึง่จะมีประโยชน์ในการใช้งานของ Sub routine, Interrupt

และเป็นท่ีพกัข้อมลู การเก็บข้อมลูลงไปใน Stack จะเรียก PUSH และการเอาข้อมลูออกมาจะเรียก POP

Stack จะแบง่เป็นสองแบบคือ

1. Hardware Stack โดยมีชดุของ Register ใน Microprocessor ที่ท าหน้าทีเ่ป็น Stack เลย ข้อดี ท างานได้เร็ว ข้อเสยี จ านวนมีจ ากดั

2. Software Stack Microprocessor ที่ใช้งานทัว่ๆ ไปจะใช้ Stack แบบนี ้ โดยอาศยัคา่ใน SP ในการสร้างการท างานในแบบของ Stack ขึน้ใน memory โดยทัว่ไป SP จะเก็บคา่ของ Address ที่เป็นต าแหนง่บนสดุของ Stack ใน memory

Microprocessor

Register

DATA

07

SP

ADDRESS+1

015

STACK

BASE

Data Memory 07

Data Bus

PUSH

POP

Address Bus

การใช้งาน Stack ด้วยค าสั่ง PUSH และ POP

Page 4: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

4

Microprocessor

PC

000DH

015

SP

0007H

015

Program Memory 07

000AH000BH

000DH000EH

Sub

routine

000FH

ACALL 0500H

RET

Address Bus

0500H

0501H0502H0503H

1

STACK

BASE

Data Memory 07

0007H

0010H0011H

000CH ACALL 0500H

Main

Program

000CH

Data Bus

STACK

BASE

Data Memory 07

Microprocessor

PC

0500H

015

SP

0008H

015

Program Memory 07

000AH

000BH000CH000DH

Sub

routine

000EH

ACALL 0500H

RET

Address Bus

0500H

0501H0502H0503H

2

0007H0008H

(000DH)

000DH

Address Bus

Main

Program

0010H0011H

000FH

Data Bus

Page 5: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

5

รูปแสดงการใช้งาน Stack เมื่อเกดิการเรียกโปรแกรมย่อย

1) ขณะอ่านค าสั่งเรียกโปรแกรมย่อย

2) ขณะปฏิบัตติามค าสั่งเรียกโปรแกรมย่อย

3) ขณะอ่านและปฏิบตัิตามค าสั่งกลับจากโปรแกรมย่อย

The Instruction Execution Cycle ขัน้ตอนการท างานของ Microprocessor ทกุตวัจะมีอยู ่3 ขัน้คือ

1. fetch the next instruction

2. decode the instruction

3. execute the instruction

Fetch คือการอา่นรหสัค าสัง่ที่ Microprocessor จะท าตอ่ไป สิง่ที่เกิดขึน้ในขบวนการนีก็้จะเร่ิมต้นจาก คา่ที่อยูใ่น PC จะถกูสง่ลงใน

Address bus แล้วไปถึงยงัหนว่ยความจ า ในเวลาเดยีวกนันัน้ Microprocessor จะสง่สญัญาณ Read data ไปใน Control bus

STACK

BASE

Data Memory 07

Microprocessor

PC

0504H

015

SP

0007H

015

Program Memory 07

000AH

000BH000CH000DH

Sub

routine

000EH

ACALL 0500H

RET

Address Bus

0500H

0501H0502H0503H

3

0007H0008H

Data Bus

000DH

Main

Program

0010H0011H

000FH

RET

000DH

000DH

0503H

Page 6: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

6

หนว่ยความจ าจะน ารหสัค าสัง่ใน Address ที่ต้องการนี ้สง่กลบัมาให้ Microprocessor ทาง Data bus จากนัน้ Microprocessor จะอา่นค าสัง่ขึน้มาจาก Program Memory แล้วน าไปเก็บใน IR

Decode and Execution เมื่อรหสัค าสัง่ (Opcode) ที่ต้องการมาอยูใ่น IR แล้ว สว่นของ Control unit ใน Microprocessor จะท าการแปลความ (Decode)

แล้วสร้างชดุของสญัญาณ เพื่อควบคมุสว่นตา่งๆ ทัง้ใน และนอก Microprocessor ให้ท างานตามนัน้ ส าหรับการท างาน (Execute) ของแต่ละค าสัง่จะแตกตา่งกนั บางค าสัง่อาจเป็นการท างานกบัข้อมลูที่อยูภ่ายใน Microprocessor หรือบางค าสัง่ Microprocessor จะต้อง fetch ข้อมลูเพิ่มเติมจาก Data Memory ก็จะท าให้เวลาทีใ่ช้ในการประมวลผลของแตล่ะค าสัง่ไมเ่ทา่กนัด้วย

Fetching the Next Instruction ในการท างานของ Microprocessor ซึง่รหสัค าสัง่จะถกูอา่นจาก Program Memory เป็นล าดบัอยา่งตอ่กนัไป ใน

Microprocessor จะมกีลไกที่จะท าให้การเพิม่คา่ Program counter ซึง่เป็นต าแหนง่ของค าสัง่ โดยอตัโนมตัิ เพื่อให้พร้อมส าหรับการ fetch ครัง้ตอ่ไป

Microprocessor

PC000BH

015

Program Memory 07

000AH

000BH000CH000DH000EH

Instruction 1

Main

Program

0010H0011H

000FH

Address Bus

Instruction 2

Microprocessor

PC

000CH

015

Program Memory 07

000AH

000BH000CH000DH000EH

Instruction 2

Main

Program0010H0011H

000FH

Address Bus

Instruction 1

000BH

รูปที่ 1 รูปแสดงการเพิม่คา่ของProgram Counter หลงัจาก Fetch ค าสัง่จากหนว่ยความจ าโปรแกรม

ตวัอยา่ง ขบวนการท่ีเกิดขึน้ในการท างาน

Page 7: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

7

R0 = R0 + R1

Page 8: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

8

The Critical Race Problem การท่ี ALU ซึง่ก็เป็นวงจร Digital นัน้มีคา่ Output ออกมาได้ ข้อมลูที่เป็น Input ก็จะต้องคงอยูต่ลอด แตเ่นื่องจากมนัมี Internal

data bus เดียวดงันัน้ ข้อมลูก็จะมาชนกนั ท าให้ผลการท างานผิดพลาด

ทางแก้ก็คือการเพิม่ Buffer ที่ Input ของ ALU ขึน้อีกชัน้หนึง่ ดงัรูป

Page 9: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

9

จากทางด้านขวามือที่เป็น Arithmetic-logic unit จะมีอินพทุด้านหนึง่ที่เป็น Register A และมี Buffer อยูด้่วย (ACT: temporary accumulator) และอกีด้านหนึง่ก็จะมี temporary register (TMP)

Instruction Formats ส าหรับรหสัค าสัง่ของ Z80 จะมีทีเ่ป็นเลขฐานสอง 1, 2, 3 และ 4 Bytes รหสัค าสัง่นีจ้ะเป็นตวัก าหนดการท างานของ

Microprocessor ซึง่มนัจะมีสองสว่นคือ สว่นของ Opcode แล้วตามด้วย Operand ซึง่เป็นคา่ข้อมลู หรือคา่ Address ของข้อมลู

ส าหรับแตล่ะ Byte ของรหสัค าสัง่ ท่ีสว่นของ Control Unit จะต้องท าการ FETCH มาจาก Memory มนัจะใช้สญัญาณนาฬิกา ถงึ 4 ลกูในการท างาน

Assembly Language

ในภาษา Assembly จะใช้ Symbolic หรือ Mnemonic แทนรหสัค าสัง่ที่เป็นเลขฐานสอง

ตวัอยา่งตอ่ไปนีเ้ป็นภาษา Assembly ของไมโครโปรเซสเซอร์ Z80

One-Word Instruction

LD r, r’ จะแทน 0 1 D D D S S S

D D D จะเป็น Bit ที่ก าหนด Register ปลายทาง (Destination register) และ S S S จะก าหนด Register ที่จะเป็นต้นทาง (Source register)

หมายถึง ให้น าข้อมลูจาก Register r’ ไปใสใ่น r จะเรียกได้เป็น “Register-to-Register” Operation

ADD A, r หมายถึง ให้บวกคา่ของ Register ( r ) เข้ากบั Accumulator ( A ) หรือจะแสดงการท างานได้เป็น A = A + r ส าหรับรหสัเลขฐานสอง จะเป็น 1 0 0 0 0 S S S

Two-Word Instruction

CODE REGISTER

0 0 0 B

0 0 1 C

0 1 0 D

0 1 1 E

1 0 0 H

1 0 1 L

1 1 0 - (MEMORY)

1 1 1 A

Page 10: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

10

ADD A,n

เป็นตวัอยา่งของ Two-word instruction ที่จะท าการบวกคา่ของ Byte ที่สอง เข้ากบั Accumulator มนัจะมีรหสัค าสัง่เป็น 1 1 0 0 0 1 1 0

ตามด้วยข้อมลู 8 Bit ของ n

Three-Word Instruction LD A, (nn)

เป็นค าสัง่ให้ท าการ Load คา่ของ Accumulator ด้วยข้อมลูที่มาจากหนว่ยความจ าต าแหนง่ที่ nn (Memory Address nn ) การท่ีคา่ Address ของข้อมลูเป็นแบบ 16 Bit ค าสัง่นีจ้ึงเป็น Tree-word instruction จะมีรหสัค าสัง่ใน Program Memory เป็น

LD A,(1002H)

LD A

(02) (10)

โดยจะมีโครงสร้างรหสัค าสัง่ดงัแสดงและการท างานท่ีเกิดขึน้ จะเป็นดงัตอ่ไปนี ้

CPU Instruction Timing

เนื่องทกุโปรแกรมประกอบด้วยการอา่นและเขยีน ดงันัน้ แตล่ะครัง้ของการอา่นหรือเขียนจึงถกูนิยามวา่ Machine Cycle หนึง่ Machine cycle ใช้สญัญาณ CPU Clock (T states) 3-6 ลกู ระยะเวลาการท างานของ Microprocessor ในแตล่ะค าสัง่ขึน้อยูก่บัจ านวนครัง้ของการอา่นหรือเขยีน (Machine cycle) ของค าสัง่นัน้ๆ

0 0 1 1 1 0 1 0

Low address

High address

Page 11: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

11

Z-80 Pin

Page 12: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

12

Pin I / O / Z หน้าที่ / การท างาน

A0-A15 O / Z Address Bus เป็นขาสญัญาณที่จะระบตุ าแหนง่ของ Memory หรือ Input /Output Port ที่ Z80 ต้องการจะตดิตอ่

D0-D7 I / O / Z Data Bus เป็นเส้นทางการ รับ/สง่ ของข้อมลู ระหวา่ง Z80 กบัต าแหนง่ที่ก าหนด

Clock I Clock Input ส าหรับปอ้นสญัญาณนาฬิกาให้ระบบ ซึง่ก าหนดจงัหวะการท างานให้กบัสว่นตา่งๆ สามารถใช้ได้สงูสดุ 4 MHz

BUS CONTROLL

BUSRQ I Bus Request เป็นสญัญาณที่จะบอก Z80 วา่ต้องการขอใช้ System Bus (ใช้ท า DMA)

BUSACK O Bus Acknowledge เมื่อ Z80 ได้รับสญัญาณขอใช้ Bus และเมือ่มนัท างานจบ Machine Cycle หลงัจากที่ท าให้ ขาสญัญาณตา่งๆ เป็น High Impedance แล้ว Z80 จะสง่สญัญาณนีอ้อกมา

CPU CONTROLL

NMI I Non-Maskable Interrupt เป็นสญัญาณที่จะ Interrupt การท างานของ โปรแกรม แล้วกระโดดไปท างานท่ี Address 0066H

INT I Maskable Interrupt เป็นสญัญาณขอท าการ Interrupt การท างาน ซึง่ถ้า IFF มีสถานะเป็น “1”

(Interrupt Enable) แล้วจบการท างานของค าสัง่ Z80 ตอบรับโดยใช้สญัญาณ ของ IORQ และ

M1

WAIT I Wait เป็นสญัญาณที่จะบอกให้ Z80 คอย การท างานของ Memory หรือ Input /Output Device ทีม่ีการท างานช้า

HALT O Halt เป็นสญัญาณ Output ที่แสดงวา่ Z80 ได้ท าค าสัง่ HALT

RESET I Reset เป็นสญัญาณปอ้นให้กบั Z80 เพื่อเป็นการก าหนดคา่เร่ิมต้นตา่งๆ ( Register PC, I, R = 0 และ ท าให้ IFF = 0 และให้ท างาน Interrupt ใน Mode 0) การท า Reset นี ้จะต้องท าทกุครัง้ที่จ่ายไฟให้กบัวงจร

MEMORY and I/O CONTROL

MREQ O / Z Memory Request เป็นสญัญาณที่บอกวา่ Z80 ต้องการจะติดตอ่กบั Memory เมื่อมีสญัญาณนี ้แสดงวา่ คา่ที่อยูใ่น Address Bus เป็นคา่ต าแหนง่ของข้อมลูที่ต้องการ

M1 O Machine Cycle 1 เป็นสญัญาณที่สง่ออกมาเพื่อบอกวา่ขณะนี ้Z80 ท างานอยูใ่นขัน้ตอนของการ Fetch ค าสัง่

IORQ O / Z I/O Request เป็นสญัญาณที่บอกวา่ Z80 ต้องการจะติดตอ่กบั Input / Output Port เมื่อมีสญัญาณนี ้แสดงวา่ คา่ที่อยูใ่น Address Bus เป็นคา่ต าแหนง่ของ I/O Port ที่ต้องการ

ในการท่ีเกิด IORQ และ M1 ขึน้จะเป็นการแสดงวา่ Z80 ตอบรับการ Interrupt อปุกรณ์ หรือวงจรภายนอกสามารถทีจ่ะใช้เง่ือนไขนีใ้นการท่ีจะใสค่า่ของ Interrupt response vector ลงใน Data Bus

RD O / Z Read เป็นสญัญาณที่จะบอกอปุกรณ์ภายนอกวา่ Z80 พร้อมทีจ่ะอา่นข้อมลูจาก Data Bus เข้าไป

WR O / Z Write เป็นสญัญาณทีจ่ะบอกวา่ ขณะนี ้มีข้อมลูอยูใ่น Data Bus แล้ว และพร้อมที่จะสง่ให้อปุกรณ์ภายนอก

Page 13: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

13

RFSH O / Z Refresh เมื่อสญัญาณนี ้Active จะหมายความวา่ Z80 จะท าการ Refresh Dynamic RAM ใน Address ที่ก าหนดโดย A0-A6

Timing Diagram จงัหวะเวลาการท างานของสญัญาณตา่งๆ ท่ีเกิดขึน้นัน้สามารถจะแบง่ได้ดงันี ้

1. Fetch Op-code

2. Z80 อา่นข้อมลูจาก Memory

3. Z80 เขียนข้อมลูเข้า Memory

4. Z80 อา่นข้อมลูจาก Input Port

5. Z80 เขียนข้อมลูออกที่ Output Port

6. เกิด Interrupt แบบ NMI

7. เกิด Interrupt แบบ INT

8. เกิด Bus Request

9. ท าค าสัง่ HALT

10. มีสญัญาณ Reset

เช่น ถ้า Z80 ต้องท างานตามค าสัง่

LD A, (nn) จะมีล าดบัของสญัญาณที่เกิดขึน้คือ 1 2 2 2

LD (nn), A จะมีล าดบัของสญัญาณที่เกิดขึน้คือ 1 2 2 3

IN A, (n) จะมีล าดบัของสญัญาณที่เกิดขึน้คือ 1 2 4

Page 14: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

14

1. Fetch Op-code

เมื่อสร้างสญัญาณ Wait เพื่อให้ Z80 รอการท างานของหนว่ยความจ า

ในจงัหวะเวลาที่ T2 ถ้ามีสญัญาณ WAIT ขบวนการท างานของ Z80 จะเลือ่นไปอีก 1 Clock (Tw) แล้วจะท าการตรวจสอบสญัญาณ WAIT นีอ้ีกครัง้

ขบวนการ Refresh ข้อมลูใน Dynamic RAM จะเกิดขึน้หลงัจากการ Fetch รหสัค าสัง่

Page 15: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

15

2. เมื่อ CPU อา่นข้อมลูจาก Memory

สิง่ที่เกิดขัน้เมื่อ Z80 ได้รับสญัญาณ WAIT

Page 16: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

16

3. เมื่อ CPU เขียนข้อมลูเข้า Memory

การเขยีนข้อมลูเมื่อมีสญัญาณ WAIT

4. เมื่อ CPU อา่นหรือ เขียนข้อมลูจาก Input/Output Port จากทีก่ารท างานของอปุกรณ์ภายนอก มีการท างานช้า ดงันัน้แล้ว จึงได้มีการออกแบบให้ Z80 เลือ่นจงัหวะการท างานของ T3 ออกไป

อีก 1 Clock ดงันัน้แล้วการตดิตอ่กบั Port จะใช้เวลา 4 Clock

Page 17: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

17

การติดตอ่กบั Input/Output Port เมื่อมีสญัญาณ WAIT

Page 18: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

18

เมื่อเกิด Interrupt แบบ INT

Page 19: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

19

Page 20: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

20

เมื่อเกิด Bus Request

เมื่อมีสญัญาณ Reset

Page 21: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

21

Clock & Reset Signal

Clock Circuit ในการท างานของ Microprocessor นัน้มนัจะต้องใช้ สญัญาณนาฬิกา เพ่ือไปก าหนดจงัหวะการท างาน สญัญาณ Clock นีจ้ะได้

จากวงจร Oscillator ดงัรูป

โดยมากแล้ว Oscillator จะใช้เป็น Crystal Oscillator เพราะต้องการคาบเวลาที่แนน่อน

Reset Circuit การ Reset เป็นสิง่จ าเป็นในระบบ Microcomputer เพราะเป็นขบวนการท่ีก าหนดจดุเร่ิมต้นในการท างาน (Register PC, I, R = 0

และ ท าให้ IFF = 0 และให้ท างาน Interrupt ใน Mode 0) การ Reset ที่เกิดขึน้ทกุครัง้ทีจ่่ายไฟให้กบัวงจรเรียกวา่ Power-on Reset และเราจะท าการ Reset เมื่อต้องการเร่ิมการท างานของระบบใหม ่ ดงันัน้วงจรที่จะใช้ ต้องสามารถท า Power-on Reset ได้ และจะต้องมี Switch ที่จะใช้กดเพื่อท าการ Reset ระบบ ได้ตามต้องการ

การท า Power-on Reset จะอาศยัการเก็บประจเุข้าทีต่วัเก็บประจ ุซึง่แรงดนัท่ีตกคร่อมตวัมนัจะมีคา่เพิ่มขึน้เร่ือยๆ เร่ิมจาก 0 สญัญาณ

RESET นีจ้ะต้องเกิดขึน้โดยมีคาบเวลาทีน่านกวา่ 4 Clock Cycle

Page 22: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

22

รูปแสดง Block diagram ของ 6802 โดยจะแสดงส่วนที่เป็นไบต์ล่าง (8 บติ) ของรีจิสเตอร์ 16 บติ แต่เมื่อโปรแกรมเมอร์ใช้รีจิสเตอร์เหล่านีจ้ะต้องใช้แบบ 16 บติ โปรแกรมม่ิงโมเดลของ 6802

โปรแกรมมิ่งโมเดลของ 6802 จะง่ายกวา่ Z – 80 เพราะวา่ไมม่ีรีจิสเตอร์ใช้กนัทัว่ไป แตจ่ะใช้ Memory เป็นสว่นช่วยในพกัข้อมลูแทนและมีอินเด็กซ์รีจิสเตอร์เพียงตวัเดียวแตจ่ะมีแอกควิมเูลเตอร์สองตวั มีรีจิสเตอร์สถานะแบบ 6 บิต และการใช้การอ้างอิง I/O แบบ Memory-mapped I/O คือใช้ Memory เป็นสว่นช่วยในพกัข้อมลูที่จะน าเข้าหรือสง่ออกด้วยเช่นกนั

Page 23: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

23

โปรแกรมม่ิงโมเดลของ 6802

โปรแกรมมิ่งโมเดลของ 6802 จะต้องให้หนว่ยความจ ามาก แทนการใช้รีจิสเตอร์ที่มใีน 8080 หรือ Z – 80 ในการท างานลกัษณะเดียวกนั เพราะวา่ 6802 มีโครงสร้างแบบเน้นให้ใช้หนว่ยความจ า (memory-intensive) ในขณะท่ี 8080 และ Z – 80 มีโครงสร้างแบบเน้นให้ใช้รีจิสเตอร์ (register-intensive) Glossary Accumulator: The parallel register in a microprocessor that is the focal point for all arithmetic and logic operations. Address Bus: A group of conductors that are routed throughout a computer system and are used to select a unique location based on its binary value. Architecture: The layout and design of a system. Arithmetic Logic Unit (ALU): The part of a microprocessor that performs all of the arithmetic and digital logic functions. Assembly Language: A low-level programming language unique to each microprocessor. It is converted, or assembled, into machine code before it can be executed. Central Processing Unit: The brain of a computer system. The term is used interchangeably with microprocessor. Control Bus: A group of conductors that are routed throughout a computer system and are used to signify special control functions, such as Read, Write, I/O, Memory, and Ready. Data Bus: A group of conductors that are routed throughout a computer system and contains the binary data used for all arithmetic and I/O operations. Hardware: The integrated circuits and electronic devices that make up a computer system. Instruction Decoder: The circuitry inside a microprocessor that interprets the machine code and produces the internal control signals required to execute the instruction.

Page 24: Lecture 02 Microprocessor and Microcontroller Architectures

Lecture 02

24

Interrupt: A digital control signal that is input to a microprocessor IC pin that suspends current software execution and performs another predefined task. Interrupt Service Routine: The subroutine that is executed when the microprocessor receives an interrupt. Machine Code: The binary codes that make up a microprocessor’s program instruction. Microprocessor: An integrated circuit that is the fundamental building block of a digital computer. It is controlled by software programs that allow it to do all digital arithmetic, logic, I/O operations. Mnemonic: The abbreviated spellings of instructions used in assembly language. Program Counter: A 16-bit internal register that contains the address of the next program instruction to be executed. Software: Computer program statements that give step-by-step instructions to a computer to solve a problem. Stack: An area set aside in RAM and used by certain instructions for the temporary storage of data and address. Stack Pointer: A 16-bit internal register that contains the address of the last entry on the RAM stack. Address Latch Enabled (ALE): A signal output by the microprocessor to demultiplex the data bus and low-order address bus. A HIGH ALE signifies that the multiplexed bus currently contains address information. Machine Cycle: The execution of each microprocessor instruction consists of several Read or Write operations to external devices. Each Read or Write operation is a machine cycle. Memory Map: A table developed for each microprocessor system design that lists the range of address that access each device or IC in the system.

Read Cycle: The microprocessor machine cycle that issues a LOW RD pulse and reads 8 bits from the addressed memory or I/O port.

Write Cycle: The microprocessor machine cycle that issues a LOW WR pulse and writes 8 bits from the addressed memory or I/O port.