Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Cs609@vu.edu.pk
Lecture # 10
Sample Program
The inner while loop in the program is used to induce delay. The outer loop simply
reloads the divisor value each time it iterates after reducing this value by 30. In this way
the output frequency of the interval timer changes after every quarter of a second
approximately. The speaker will turn on with a low frequency pitch and this frequency
will increase gradually producing a spectrum of various sound pitches.
Sample Program
#include <dos.h>
#include <bios.h>
void interrupt (*oldint15) ( );
void interrupt newint15 (unsigned int BP, unsigned int DI,
unsigned int SI, unsigned int DS, unsigned int ES,
unsigned int DX, unsigned int CX, unsigned int BX,
unsigned int AX, unsigned int IP, unsigned int CS,
unsigned int flags);
void main ( )
{
oldint15 = getvect (0x15);
setvect (0x15, newint15);
keep (0, 1000);
}
The above program is a TSR program that can be used to turn the speaker on/off. The
above program intercepts the int 15h. Whenever this interrupt occurs it looks for service #
0x4f (keyboard hook). If ‘S’(0x1f scan code) has been pressed it toggles the speaker.
Sample Program
#include <dos.h>
#include <bios.h>
unsigned int divisors[4]={0x21ff,0x1d45,0x1b 8a,,0x1e4c};
unsigned long int far *time =(unsigned long int far *)0x0040006C;
void main ()
{ unsigned long int tx;
int i=0;
while (!kbhit ())
{
while (i<4)
{ outport(0x43,0xB4);
outport(0x42,*((char *)(&d ivisor[i])));
outport(0x42,*(((char *)(&div isor[i]))+1));
outport(0x61, inport(0x61)|3);
tx=*time;
tx=t x+4;
while (t x >= (*time));
i++;
}
i=0;
}
outport(0x61,inport(0x61)&0xFC);
}
This program generates a tune with 4 different pitches. This program is quite similar to
the one discussed earlier. The only major difference is that in that program the pitch was
gradually altered from low to high in this the pitches change periodically until a key is
pressed to terminate the outer loop. Four various pitches are maintained and their divisor
values are placed in the divisors[] array. All these divisor values are loaded one by one
after a delay of approximately quarter of a second and this continues until a key is
pressed.
Sample Program
#include <stdio.h>
#include <dos.h>
#include <bios.h>
struct tagTones
{ unsigned int divisor;
unsigned int delay;
};
struct tagTones Tones[4]={
{0x21ff,3},{0x1d45,2},{0x1b8a,3},{0x1e4c,4}};
int i,ticks,flag=0 ;
void interrupt (*oldint15)();
void interrupt (*oldint8)();
void interrupt newint15();
void interrupt newint8();
void main ()
{
oldint15=getvect(0x15);
setvect(0x15,newint15);
oldint8=getvect(0x08);
setvect(0x08,newint8);
keep(0,1000);
}
This is an interrupt driven version of the previous program. This program makes use of
the timer interrupt rather than a loop to vary the divisor value. Moreover interrupt 15 is
used to turn the speaker on /off.
The speaker turns on whenever ‘S’ (scan code 0x1f) is pressed and turns off whenever ‘A’
(scan code 0x1E) is pressed.
The timer interrupt shift the divisor value stored in the tones structure whenever the
required numbered of ticks( timer counts) have passed as required by the value stored in
the delay field of the tone structure.
More such divisor values and their delays can be initialized in the tones structure to
generate an alluring tune.
Parallel Communication
Output
D0
D1
D2
CPU Parallel Out Put Device
D7
Busy
Strobe
PPI is used to perform parallel communication. Devices like printer are generally based
on parallel communication. The principle of parallel communication is explained in the
slide above. Its called parallel because a number of bits are transferred from one point ot
another parallel on various lines simultaneously.
Parallel Communication
Input
D0
D1
D2
CPU Parallel Input Device
D7
DR
CPU I/O
Controller
Parallel Communication
Faster
Only Economically Feasible For
Small Distances