NOTES ON INTERRUPT PROGRAMMING USING PARALLEL

advertisement
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.
Interrupt (INT)
Interrupt Ack (INTA)
CPU
Data Bus
Program’
Able
Interrupt
Controller
Parallel
Port
(PIC)
IRQ7 Type No.
0F16
From Motor
Bit 6 on port
037916
The Role of Parallel Port
IRQ7 has been reserved for parallel port. The parallel port interrupt 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
MOV DX,037Ah
; Initialize parallel port to disable interrupts
out dx,al
Also notice 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
MOV DX,37Ah
out dx,al
; Program parallel port for more interrupts
; See [UffenBeck]
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 Debug 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
MOV DX,20h
out dx,al
; Programming PIC: End Of Interrupt (EOI) command word is
; 0010 0000 (20H)
;
; Port addresses 20H and 21H are where PIC is mapped.
Next step:
MOV al,00H
MOV DX,21h
out dx,al
; Command word 0000 0000 (00H) is to Enable all interrupts
; It is ent to port 21H
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, SEG 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
MOV AL,0FH
MOV AH,25h
INT 21H
; Move OFFSET value of myint
;
int 0FH
int 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
SUB DX,AX
ADD DX,100h
MOV AH,31h
INT 21H
; DX has the memory 'distance' between main an myint
; Add few more for safety
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 arranged 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 name 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
MOV BYTE PTR ES:[BX], ‘S’
INC BX
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
; Let us go 100 H bytes deep in screen memory (probably second line)
;Defult segment with all MOV is DS, we override to ES
; Jump over the attribute byte.
.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 project
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 your 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, and 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
; measurement 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 Controller
;
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 DOS 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
here1:
here2:
; Always PUSH flags in hardware interrupts, as many times mentioned in the literature.
MOV al,00H
MOV DX,37Ah
out dx,al
; Initialize parallel port to disable further interrupts
MOV CX, 0FH
mov ax,0FFH
DEC AX
JNZ here2
DEC CX
JNZ here1
; Just a delay loop to kill touch debounce
;
;
;
;
;
STI
; Make other interrupts interrupt us.
mov ax,@data
mov ds,ax
; Initilize ds register, a requirement by MODEL method
mov AH,02
MOV DX,0A14h
INT 10H
MOV AL, count
;Intialize the Display using BIOS INT 10H.
; You can comment these three lines out using ‘;’ to do the exercise 4.
;
; You can alo comment these four lines out to do exercise 4.
MOV CX,1
MOV AH, 0AH
INT 10H
;
;
;
mov ah, count
inc ah
mov count,ah
; And these three also
MOV al, 20h
; Programming PIC: EOI command
; 20 and 21h belong to interrupt. You do not need to do so for IRQ7!!
; Because it is the last priority interrupt anyway.
MOV DX,20h
out dx,al
MOV al,00H
MOV DX,21h
out dx,al
; Enable all interrupts
MOV al,01AH
MOV DX,37Ah
out dx,al
; Program parallel port for more interrupts; See [UffenBeck]
POPF
POP DI
POP 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:
; Programming the PIC
mov dx,21h
mov al,00H
out dx,al
; just a label to define deginning of the program
; Enable PIC for interrupts
; 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 0FH
INT 0FH
; Interrupt is now installed. Let us test it using software generated INT.
; 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 myint
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
Download