NOTES ON INTERRUPT PROGRAMMING USING
PARALLEL PORT ON IBM PC
By Dr. Mohammad Jahangir Ikram
Computer System Application: Design and Development: Spring 2002.
Lahore University of Management Sciences.
Laboratory 6
Introduction:
This lecture will help you
explain the interrupt programming on an IBM PC. We will use Interrupt
programming to measure the speed of a motor.
The Stake Holders
There are quite a few stack holders in the whole process. Namely:
1.
The Parallel Port
2.
The Programmable Interrupt Controller
3.
The Operating System: DOS Support
4.
The Screen Output and Screen memory.
The System Block Diagram
The following diagram shows the overall system block diagram.
The Role of Parallel Port
IRQ7 has been reserved for parallel port. The parallel port inter
rupt can be enabled and diabled. Notice the following
two instructions to enable and disable parallel port interrupts. The control word Is sent to 037A port.
MOV al,00H
; Initialize parallel port to disable interrupts
MOV DX,037Ah
out dx,al
Also n
otice that the port value is placed in DX register (mov DX, 037AH).
The following set instructions enables the interrupts on the parallel port.
MOV al,01AH
; Program parallel port for more interrupts
; See [UffenBeck]
MOV DX,37Ah
out dx,al
CPU
Data Bus
Program’
Able
Interrupt
Controller
(PIC)
Inte
rrupt (INT)
Interrupt Ack (INTA)
Parallel
Port
IRQ7 Ty pe No.
0F
16
Bit 6 on port
0379
16
From Motor
The
Role of PIC
Upon receiving an interrupt from the parallel port, the pIC sends an interrupt to the computer with a type
vector
0F
.
Exercise One
1. The intterupt type number oF will interrupt vector placed at what memory location. ___________
2. Goto D
ebug and type
-
d 0000:0000
What will this instruction do??
3. What is the interrupt vector value specified at addresses pointed to by answer in 1.
______, __________, _______, ______ CS; _________, IP ______
5.
On debug type
–
u CSCS:IPIP (value found
in 3.)
6.
What is the first instruction that you find at address.
_________________________
Command words for the PIC
Once the PIC interrupt has been entertained, it is programmer’s job to tell the PIC in the ISR (Interrupt
Service Routine) the Iterrupt
has been Acknowledge.
The following instruction’s do the same.
MOV al, 20h
; Programming PIC: End Of Interrupt (EOI) command word is
; 0010 0000 (20H)
;
MOV DX,20h
; Port addresses 20H and 21H are where PIC is mapped.
out dx,al
Next step:
MOV al,00H
; Command word 0000 0000 (00H) is to Enable all interrupts
MOV DX,21h
;
It is ent to port 21H
out dx,al
The ROLE of DOS
The DOS provides several service to
1.
Launch Interrupt Vector (INT 21H with AH = 25h, AX = SEGMENT, DX = OFFSET)
2.
Make
a program Terminate and Stay Resident (INT 21H with AH = 31H and DX = 16 byte
paragraphs).
The following lines show how these service are used in the installation program.
The myint is a label at the start of the interrupt service routine.
MOV
AX, SE
G myint
;
Move segment value of the myint, Mote that the values to DS
;
moves through AX (as if AX is secretary to DX) and NOT
;
directly
MOV DS,AX
MOV DX, OFFSET myint
;
Move OFFSET value of myint
MOV AL,0FH
MOV AH,25h
;
INT 21H
i
nt 0FH
i
nt 0FH
The total size of the ISR is the memory distance (difference) between MAIN and MYINT. That is loaded
in AX
MOV AX, OFFSET myint
MOV DX, OFFSET main
S
UB DX,AX
; DX has the memory 'distance' between main an myint
ADD
DX,100h
; Add few more for safety
MOV AH,31h
INT 21H
Finally Interrupt service 31H exits to DOS but leaving the program memory reserved by the operating
system. (TERMINATE AND STAY RESIDENT)
The Role of Screen Display
The screen display is a
rranged in 80 columns and 24 rows. A two
-
byte memory is associated with each
character to be printed on the screen. The memory starts at B800:0000.
EXERCISE 2
What is memory location for the first character in second row. ___________
Write your na
me on the screen using E(nter) command.
EXERCISE 3
In DOS goto MASM611 sub
-
directory BIN and type MOTOR0 to run MOTOR0 program.
TYPE MEM/C to see the program staying resident in the memory.
Type DEBUG
1.
What is new vector of the type number 0FH ________
__________
2.
Use unassemble to see new program in the memory. What are the first few instruction of the
program you see in the memory.
________
________
________
Run motor using coarse control so as to send interrupts to the computer and see if it works.
EXERCISE 4
Printing your name on the screen.
This exercise is related to Programmer Workbench.
In DOS goto MASM611
\
bin directory. Type PWB
STEP 1.
Write the following code
.Model Small
.Stack 100H
.Code
.Startup
;Following two lines are common to all
assembly language programs in MODEL method
.
MOV AX, @DATA
;AX working as secretary for DS
MOV DS,AX
;DS initialized to current data segment.
MOV AX, 0B800H
; Set screen segment
MOV ES, AX
; to ES for segment reference
MOV BX, 100H
; Let us go 10
0 H bytes deep in screen memory (probably second line)
MOV BYTE PTR ES:[BX], ‘S’
;Defult segment with all MOV is DS, we override to ES
INC BX
; Jump over the attribute byte.
INC BX
MOV BYTE PTR ES:[BX], ‘A’
INC BX
INC BX
MOV BYTE PTR ES:[
BX], ‘A’
INC BX
INC BX
MOV BYTE PTR ES:[BX], ‘D’
INC BX
INC BX
.EXIT
END
Use
save as
to save this file as new name, for example myfirst.asm
STEP 2
1.
In PROJECT menu, select new project. Type new name (for example
C:
\
MASM611
\
BIN
\
LAB6 and press
ENTER
2.
Select Assembler and DOS EXE
3.
press OK, Now system will ask to add files to the project.
4.
Add the new file created in step 1 to the project.
STEP 3
Make changes to your program in the file created in step 1 (TA will give you help) and the in the pr
oject
menu REBUILD ALL until you get 0 errors.
STEP 4
Come out of PWB and type project name (for example LAB6) to run your program.
STEP 5
If you have to go back to the program, do NOT forget to open the project LAB6 in PWB again.
EXERCISE 5
Printing yo
ur name on the screen in a hardware Interrupt Program.
In this excersie you are required to change the MOTOR0 Program so that it prints your name on
the screen.
Excersie 6.
Home Assignment
Using timer interrupt 8 which occurs exactly 18.2 time a second, a
nd IRQ7 (interrupt 0F) write a
program to measure and set the speed of the motor.
Program Listing
;Copyright Mohammad Jahangir Ikram, Lahore University of Management Sciences
; Motor 0 is the First program in three part series which demonstrates
; mea
surement of motor speed control
;
;
;Motor 0 is simple demonstration of Interrupts
;Motor 1 is demonstration of interrupt count
;Motor 2 uses clock tick to calculate the speed
;
;
; Dr Mohammad Jahangir Ikram Dated: 27
-
October
-
2000,
Friday
; A Terminate
and Stay Resident Program to write Interrupt for Parallel Port
;Notes:
;
1. Do NOT use INT 21H (DOS Calls) in Interrupt Service Routine
; Becasue it will hang your computer
;
;
2. Do NOT attempt to change Prorammable Interrupt Contr
oller
;
setting connected at port 20H
;
;
3. Do NOT forget to output 00H to printer port.
;
; REFERENCES:
; 1. Uffenbeck IInd Ed. Page 394(Figure), 402 (Table) general PIC programming in the same chapter
; 2. Berry Bray for BIOS and D
OS Fuction calls etc
; 3. Parallel Port Complete by Jan Axelson
.MODEL small
.STACK 100h
.CODE
;The interrupt service routine starts here:
;***************************************************************
myint PROC FAR
.DATA
count db “A”
.CODE
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DS
PUSH ES
PUSH SI
PUSH DI
PUSHF
; Always PUSH flags in hardware interrupts, as many times mentioned in the literature.
MOV al,00H
; Initialize parallel port to disable further interrupts
MOV DX,37Ah
out dx,al
MOV CX, 0FH
; Just a delay loop to kill touch debounce
here1:
mov ax,0FFH
;
here2:
DEC AX
;
JNZ here2
;
DEC CX
;
JNZ here1
;
STI
; Make other interrupts interrupt us.
mov ax,@data
; Initilize ds regis
ter, a requirement by MODEL method
mov ds,ax
mov AH,02
;Intialize the Display using BIOS INT 10H.
MOV DX,0A14h ; You can comment these three lines out using ‘;’ to do the exercise 4.
INT 10H
;
MOV AL, count
; You can alo comment these fou
r lines out to do exercise 4.
MOV CX,1
;
MOV AH, 0AH
;
INT 10H
;
mov ah, count
; And these three also
inc ah
mov count,ah
MOV al, 20h
; Programming PIC: EOI command
; 20 and 21h belong to interrupt. You do not need to do so for IRQ7!!
MOV DX,20h
; Because it is the last priority interrupt anyway.
out dx,al
MOV al,00H
; Enable all interrupts
MOV DX,21h
out dx,al
MOV al,01AH
; Program parallel port for more interrupts; See [UffenBeck]
MOV DX,37Ah
out dx,al
POPF
POP DI
P
OP SI
POP ES
POP DS
POP DX
POP CX
POP BX
POP AX
STI
IRET
myint ENDP
;(*(*(*(*(*((*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*
; *(*(
this is the satrt up program which sets everything up. It runs only ONCE ONCE ONCE.
;*)*)*)*)*)*)*)*)*)*)*)*)*)*)**)*)**)*)*
)*)*)*
.Startup
main:
; just a label to define deginning of the program
; Programming the PIC
mov dx,21h
; Enable PIC for interrupts
mov al,00H
out dx,al
; Programme the Parallel Port
mov dx,037ah
; enable parallel port to
print interuutps
mov al,1Ah
out dx,al
; Preparing parameter for DOS call AH=25H
MOV AX, SEG myint
MOV DS,AX
MOV DX, OFFSET myint
MOV AL,0FH
; Change vector 0F
MOV AH,25h
; DOS call fir changing interrupt vector
INT 21H
INT 0F
H
; Interrupt is now installed. Let us test it using software generated INT.
INT 0FH
; Prepaing parameters for using DOS call 31H
MOV AX, OFFSET myint
;
MOV DX, OFFSET main
;
SUB DX,AX
; DX has the memory 'distance' between main an my
int
DIV DX, 16
; Convert to paragraphs
ADD DX,10h
; Add few more for safety
MOV AH,31h
; DOS call for staying resident.
INT 21H
; Notice no .EXIT as that is not required.
END
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Comments 0
Log in to post a comment