Programming the 8259 PIC: A Tech-Tip Example and Boilerplate

Similar documents
Week 11 Programmable Interrupt Controller

8086 Interrupts and Interrupt Responses:

PC Interrupt Structure and 8259 DMA Controllers

Northern India Engineering College, Delhi (GGSIP University) PAPER I

Interrupts. by Rahul Patel, Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

Lecture-51 INTEL 8259A Programmable Interrupt Controller

Design with Microprocessors

Topics. Interfacing chips

4) In response to the the 8259A sets the highest priority ISR, bit and reset the corresponding IRR bit. The 8259A also places

7/19/2013. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to: Chapter Objectives 12 1 BASIC INTERRUPT PROCESSING

Chapter 12: Interrupts

These three counters can be programmed for either binary or BCD count.

27 December 2016 Pramod Ghimire. Slide 1 of 16

Understanding the Interrupt Control Unit of the 80C186EC/80C188EC Processor

Chapter 12: INTERRUPTS

The Purpose of Interrupt

For more notes of DAE

sequence is not needed. (ROM space). Another application is to use the poll mode to expand the number of priority levels to more than 64.

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

MP Assignment III. 1. An 8255A installed in a system has system base address E0D0H.

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

The K Project. Interrupt and Exception Handling. LSE Team. May 14, 2018 EPITA. The K Project. LSE Team. Introduction. Interrupt Descriptor Table

ECE 485/585 Microprocessor System Design

Lecture-61 Initialization Control Word 2 (ICW2):

Chapter 8 PC Peripheral Chips - Pt 3 Interrupts

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

UNIT - II PERIPHERAL INTERFACING WITH 8085

UNIT-IV. The semiconductor memories are organized as two-dimensional arrays of memory locations.

Introduction to Microprocessor

INPUT/OUTPUT ORGANIZATION

b. List different system buses of 8085 microprocessor and give function of each bus. (8) Answer:

8259A - STUDY CARD 1. INTRODUCTION

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

Types of Interrupts:

Interrupts. Chapter 20 S. Dandamudi. Outline. Exceptions

4 Categories Of 8085 Instructions That Manipulate Data


Course Syllabus of Microprocessor I (Fall 2006)

BHARATHIDASAN ENGINEERING COLLEGE. III Year / V Semester / EEE MICROPROCESSORS AND MICROCONTROLLERS (R-2013)

Description of the Simulator

S.R.M. INSTITUTE OF SCIENCE & TECHNOLOGY SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING

Adding PC Connectivity to the MTS-88 Microcomputer Teaching. Omar Walid Abdul-Wahab, Wameedh Nazar Flayyih. System

Features: 3 8-bit IO ports PA, PB, PC. PA can be set for Modes 0, 1, 2. PB for 0,1 and PC for mode 0 and for BSR. Modes 1 and 2 are interrupt driven.

Pin Description, Status & Control Signals of 8085 Microprocessor

UNIT V MICRO CONTROLLER PROGRAMMING & APPLICATIONS TWO MARKS. 3.Give any two differences between microprocessor and micro controller.

8085 Microprocessor Architecture and Memory Interfacing. Microprocessor and Microcontroller Interfacing

Homework. Reading. Machine Projects. Labs. Intel 8254 Programmable Interval Timer (PIT) Data Sheet. Continue on MP3

INSTITUTE OF ENGINEERING AND MANAGEMENT, KOLKATA Microprocessor

Microprocessors and Microcontrollers. Assignment 1:

9. PERIPHERAL CHIPS 9a

Program controlled semiconductor device (IC) which fetches (from memory), decodes and executes instructions.

QUESTION BANK CS2252 MICROPROCESSOR AND MICROCONTROLLERS

CS609 Final Term Solved MCQs with References Without Repetitions 14/02/2013

Question Bank Microprocessor and Microcontroller

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

INPUT/OUTPUT ORGANIZATION

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

CC411: Introduction To Microprocessors

BASIC INTERFACING CONCEPTS

Interrupt is a process where an external device can get the attention of the microprocessor. Interrupts can be classified into two types:

8051 Microcontroller


Microprocessors & Interfacing

EEM336 Microprocessors I. I/O Interface

Lecture Note On Microprocessor and Microcontroller Theory and Applications

Advanced Microprocessors

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

Syllabus for Bachelor of Technology. Computer Engineering. Subject Code: 01CE0501. Subject Name: Microprocessor Fundamentals & Programming

1. What is Microprocessor? Give the power supply & clock frequency of 8085?

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

2. List the five interrupt pins available in INTR, TRAP, RST 7.5, RST 6.5, RST 5.5.

INTRODUCTION OF MICROPROCESSOR& INTERFACING DEVICES Introduction to Microprocessor Evolutions of Microprocessor

eaymanelshenawy.wordpress.com

MICROPROCESSOR TECHNOLOGY

8051 Microcontrollers

Unit I Introduction. Department of Electronics and Communication Engineering VARDHAMAN COLLEGE OF ENGINEERING Shamshabad, Hyderabad , India.

8085 Interrupts. Lecturer, CSE, AUST

Lab 2: 80x86 Interrupts

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

4 Multiplexer. Y Fig Keyboard Scan Matrix

FIFTH SEMESTER B.TECH DEGREE EXAMINATION MODEL TEST QUESTION PAPER, NOVEMBER CS 305: Microprocessor and Microcontrollers PART A

Internal architecture of 8086

CS401 - Computer Architecture and Assembly Language Programming Glossary By

CS 3803 Lab 6 Interrupts Assigned 2/25/10 Point Value: 30

MICROPROCESSOR Architecture, Programming and Interfacing SUNIL MATHUR. Assistant Professor Maharaja Agrasen Institute of Technology Delhi

EE 390 Lab Manual, EE Department, KFUPM. Experiment #7. Introduction to Flight86 Microprocessor Trainer and Application Board

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

Basics of Microprocessor

Chapters 2, 3: bits and pieces. Chapters 2 & 3. Chapters 2, 3: bits and pieces. Chapters 2, 3: bits and pieces. Using C. A last word about hardware

Intel 8086 MICROPROCESSOR. By Y V S Murthy


1. INTRODUCTION TO MICROPROCESSOR AND MICROCOMPUTER ARCHITECTURE:

ECE 341. Lecture # 19

INT 21H and INT 10H Programming and Macros

EC6504 MICROPROCESSOR AND MICROCONTROLLER

INPUT/OUTPUT ORGANIZATION

Department of Computer Science and Engineering

Control Unit: The control unit provides the necessary timing and control Microprocessor resembles a CPU exactly.

Microcomputer Architecture and Programming

Transcription:

Programming the 8259 PIC: A Tech-Tip Example and Boilerplate Thomas W. Associate Professor, New Mexico State University, Department of Engineering Technology PO Box 3001, MSC 3566, Las Cruces, NM 88003-8001, tjenkins@nmsu.edu Abstract - The Intel 8259 Programmable Interrupt Controller (PIC) is a common electronic device whose many and varied applications include integrating it into simple Intel based microcomputer systems. This device is also frequently used in Engineering Technology classes when discussing computer hardware or microcomputer system architectures and interfacing. Regularly these devices are utilized in the application portion of these classes or in student projects. The author presents an example of the programming of this device in MASM an assembly language. This can be used as a boilerplate for describing the device s actions or in the use of this device in electronic or computer hardware laboratories or other applications. Introduction: Most microcomputer systems designed today require that many I/O devices such as keyboards, communication ports, sensors, displays, and other components interface to the central processing unit (CPU) via a method call interrupts. In this method, the interfacing device (or sensor, etc.) requests service from the processor by generating an asynchronous signal to the CPU called an interrupt. The CPU will respond to the interrupt signal by completing its current instruction execution, saving the CPU state, and then respond to this request by executing a small program called an Interrupt Service Routine (ISR) that is specific to the requesting device. After completing the ISR, the CPU returns to the program it was executing before servicing the interrupting device via the ISR. 1

Most microprocessor CPUs typically have one input pin (INT) which when asserted causes the CPU to execute microcode to respond to this signal. Specifically, the CPU will automatically execute the following sequence of events via this microcode when a TRUE is detected on the INT input pin of the CPU. 1. The CPU completes its current instruction, which is in the instruction register. 2. The Code Segment (CS) and Instruction Pointer (IP) and the flags register values are placed on the stack thusly saving the machine state. 3. The CPU sends a handshake signal out via a pin called the interrupt acknowledge (INTA) 4. After acknowledging the interrupt signal, the CPU looks on it s data bus for a numeric value N. This number N (0-255 decimal) is used to read an entry from the Interrupt Vector Table (IVT) which is located at the lowest memory locations 0-400H. At the Nth entry in the table, there is a four-byte value that is a pointer/address to a memory location where a short program resides the ISR. The ISR is a machine code subroutine that is specifically designed to service the external hardware interrupt. The CPU places this four-byte value into its CS and IP registers. Thus the CPU responds to this request for service by executing this small program that is specific to the requesting device. The particular ISR to be executed is determined by the value N which is read from the data bus. 5. The ISR is ended with a Return from Interrupt (IRET) instruction which permits the CPU to return to the code it was executing before the interrupt occurred. This is accomplished by popping the saved CS, IP, and flags from the stack before the CPU returns to the program it was executing before servicing the interrupting device. Consequently, the technique of real-time programming using interrupts permits the CPU to be doing another task (executing another program) and only stop temporarily to execute an ISR when an external device (event, sensor, etc.) requests CPU action before returning to the original task. With the CPU having only one INT pin, this would seem to limit the number of devices that could request an interrupt, to only one device. The Intel 8259 Programmable Interrupt Controller (PIC), which is designed to be used in common real-time interrupt driven microcomputer systems, is specifically designed to handle this situation. The PIC, can multiplex up to eight prioritized hardware external interrupts, thusly allowing eight devices to request service asynchronously from the CPU. It can be cascaded for up to 64 vectored priority interrupts without additional circuitry. The PIC is designed to minimize overhead and additional software and hardware in handling multiple external interrupts. The CPU and the PIC are easily hardware interfaced with many texts discussing the technique. Simply stated the CPU and PIC have a handshake interface with two lines: the PIC has an INTR line (output) which connects directly to the CPU INT line(input) while 2

the INTA line (output) from the CPU attaches to the INTA line (input) on the PIC. The PIC and CPU also have common connections via the shared data bus. As the name programmable implies, the PIC can be programmed allowing a variety of implementations and applications. Typically, the primary usage is to permit multiplexing multiple devices that utilize interrupts (hard drive, printer, communication ports, floppy drive, external sensors, and user-defined devices) to use the interrupt techniques with a single microprocessor CPU. The programming of the PIC is usually done automatically as part of a microcomputer systems bootstrap or initialization routine that is contained in an operating system program. However, it is often useful to modify the standard PIC initialization to a non-typical application or it may be necessary to initialize the PIC to a specific task in small user-defined applications where large operating system programs are not needed nor even wanted. For example, small microprocessor based systems are often used to collect data from a variety of sensors on a pipeline, irrigation system, photovoltaic array, or other instrumented applications. In this user-defined specialized application, a very limited microprocessor based system with minimal hardware is desired to minimize cost, weight, energy usage, and space. A large memory intensive operating system such as WINDOWS is definitely a burden here. In these types of applications, user defined programming of the PIC is required. Many microprocessor system architecture or interfacing classes in Engineering Technology programs have students design (and build) simple microprocessor based systems to demonstrate basic microcomputer architecture concepts or concepts relating to interfacing of the microprocessor to various devices such as memory, IO devices, sensors, or other similar applications. The PIC is often a main component of these systems and thus requires the instructor and students to understand the initialization of this device to function within this system. Intel technical manuals are often difficult for students to understand at their level of experience and many textbooks give only superficial treatment of this device. Therefore, the use of an example boilerplate and accompanying in-line documentation is offered as a supplement to these resources and as an aid in these activities. The author has used this boiler plate in a senior Hardware Design and Microcomputer Architecture class that has students design, build, integrate, test, and document a single board microprocessor based computer system. Small assembly language routines are constructed to permit the hardware to do specified tasks such as display a real-time clock and function as a four-function calculator. The boiler-plate provided below is given to the students as a supplement to technical manuals, lectures, and text material over these devices. The boiler-plate approach gives good documentation on the function of the device and relieves the student of much of the burden of the coding, which permits more investment in learning interfacing and functionality. 3

Programming the 8259 PIC The following provides an example of assembly language code, which initializes the PIC into an example typical configuration and provides an easily modifiable boilerplate for users to change the code to meet their specific requirements. The following is written in MASM code format and the author assumes a degree of assembly language, general programming, and PIC familiarity by the readers. ************************************************************************ semicolon on any line begins a comment nonexecutable documentation ************************************************************************ 8259 Programmable Interrupt Controller (PIC) The PIC has two internal registers which we will program they are generally accessed in Intel architecture via I/O ports 20 and 21 hex. NOTE: the use of equates (equ) is a common and useful form of assigning mnemonic names to constants and thus increasing the program s useful documentation. PIC_P1 equ 20h 8259 control port: A0=0 (address line 0) PIC_P2 equ 21h 8259 control port: A0=1 In this example, we will Initialize the 8259 PIC to handle three out of a possilbe eight hardware interrupts these will be on the input lines labeled on the PIC as IR0, IR1, and IR7. These interrupts could be the timer, keyboard, hard- drive or some sensor input. The 8259 should be edge-triggered on these pins, single-mode, auto generate an End-of-Interrupt (EOI), 8088 CPU, with interrupt offset mask value of 8 more on this below. This example requires three initialization control words: ICW1,ICW2 and ICW4, and one operational control word (OCW1) be sent to the device ports (equated to mnemonic names of PIC_P1 and PIC_P2 above.) These control words port destination internal register destination is determined by the address bus line A0 value 0/1 which will directly correspond to decoding to the assigned ports 20 or 21Hex The PIC is programmed via operational command words (ICW or OCW). If we need to initialize the 8259 PIC controller into a single unit, edge triggered interupt controller, then the first control word (ICW1) performs the following initialization: (x indicates a don t care bit) X/0 X/0 X/0 1 0 1 1 1 = 17h {Not Used} Must Edge {IVT Single Needs be Trigger interval 8259 ICW4 a 1 of 4 bytes per vector} IVT = interrupt vector table 4

The PIC has eight interrupt input pins IR0-IR7. The internal register at standard IO port 20H (PIC_P1 see above) holds a value which is added to the interrupt line which is activated to produce an Interrupt Number. This number is the true interrupt value used by the CPU. This modification of the interrupt line-to-interrupt number, allows for generating any eight consecutively numbered interrupts with a PIC as well as permitting the cascading of PIC s. Most commonly, the 8259 uses the value 8 as its interrupt number offset therefore interrupt numbers 8-0Fh. These are most commonly used with a single PIC implementation and standard INTEL architecture. The second control word (ICW2) performs the following initialization: 0 0 0 0 1 X/0 X/0 X/0 (x=don t care) = 08h This is the number of the interrupt generated by the IR0 pin (0+8=8), i.e. the interrupt offset number. Therefore, an interrupt on the first pin IR0 (0) causes this interrupt number 8 to be sent to the CPU via the data bus. This number is multiplied by 4 by the CPU and that value is used to find the corresponding ISR s address in the Interrupt Vector Table (IVT). An interrupt on IR7 would thusly generater an interrupt number of 7+8=15 decimal or 0FH(HEX) The third control word is not required because the 8259A PIC is being initialized as a single unit ONLY! (They can be cascaded) The fourth control word (ICW4) performs the following initialization: 0 0 0 0 1 1 1 1 = 0Fh Non {Non-buffered Auto 8088 SFNM mode} EOI CPU Thusly, ICW1 equ 17h command word 1 (ICW1) ICW2 equ 08h " word 2 (ICW2) ICW4 equ 0Fh " word 4 (ICW4) The first/only operation command word (OCW1) is the enable/disable mask for the eight interrupt lines: o=enable, 1=disable in the relative bit position for that interrupt. For example, int0=> bit 0 of the byte mask OCW1 equ 01111100B 8259 int. enable mask values to enable interrupts 0,1,7 equ 7CH enables IR0, IR1, and IR7 on the 8259 ************************************************************************* ************************************************************************* INIT_8259 ************************************************************************* Initialize the 8259 PIC to handle three(3) hardware interrupts on lines IR0, IR1, and IR7. These interrupts could be the timer, keyboard, and some sensor input. The 8259 should be edge-triggered on these pins, single-mode, auto EOI, 8088 CPU, with interrupt offset mask value of 8. This example requires three initialization control words: ICW1, 2, and 4, and one(1)operational control word (OCW1) be sent to the device ports. These control words port destination is determined by the address 5

line A0 value 0/1 which will directly correspond to ports 20 or 21Hex It is recommended that the interrupt processing be disabled here then re-enabled at the end-of-this-code using the set/clear interrupt flag instructions: STI CLI cli turn off interrrupt processing while we manipulate the PIC registers. Start to initialize the 8259A PIC by sending it the first control "word" (really 8 bits - 1 byte) as defined in the equates (equ) above. mov al,icw1 load the 8259 PIC with the first out PIC_P1,al initialization word. A0=0 therefore port 20H Continue to initialize the 8259A PIC with its second control word. mov al,icw2 load the 8259 PIC with the second out PIC_P2,al initialization word. A0=1 therefore port 21H Finish initializing the 8259A PIC with the last control word. mov al,icw4 load the 8259 PIC with the fourth out PIC_P2,al initialization word. A0=1 The 8259A PIC is now initialized as a single unit, edge triggered interrupt controller. Now send the 8259 then operational command word (OCW1) which will set the enable/disable bits for the three valid interrupts (0,1,7) mov al,ocw1 load the 8259 enable/disable IRQ mask out PIC_P2,al A0=1 It is recommended that the interrupt processing be re-enabled here using the set/clear interrupt flag instructions: STI and CLI sti turn ON interrrupt processing after we have manipulated the PIC registers allowing the PIC to operate. done the PIC is now initialized and ready to accept interrupts!! ************************************************************************* ************************************************************************* INIT_8259 ************************************************************************* 6

Conclusion: The 8259 PIC is a versatile device that has many applications in electronics and microcomputer systems. Understanding their potential applications means understanding how to program the device to function in its different modes. An example boilerplate makes their programming an easier endeavor and permits their full potential in applications and as teaching tools. References: 1. INTEL Hardware Design Homepage including specifications for the 8259 Programmable Interrupt Controller http://developer.intel.com/ 2. The Intel Microprocessors: 8086/8088, 80186, 80286, 80386, 80486, Pentium, Pentium Pro, and Pentium II, Pentium III, Pentium 4, Seventh Edition, Barry B. Brey, Prentice-Hall 2005 3. Embedded Controllers: 80186/80188 and 80386EX, Barry B. Brey, Prentice-Hall, 1998 4. The 8088 and 8086 Microprocessors, WA Triebel and A. Singh, Prentice Hall, 2000. 5. The 80386, 80486, and Pentium Processors: Hardware, Software, and Interfacing, Walter Tribel, Prentice Hall, 1998 7