Information Technology Reference
In-Depth Information
28
Interrupt-driven RS-232
28.1 Interrupt-driven RS-232
Interrupt-driven devices are efficient on processor time as they allow the processor to run a
program without having to poll the devices. This allows fast devices almost instant access to
the processor and stops slow devices from 'hogging' the processor. For example, a line
printer tends to be slow in printing characters. If the printer only interrupted the processor
when it was ready for data then the processor can do other things while the printer is printing
the character. Another example can be found in serial communications. Characters sent over
an RS-232 link are transmitted and received relatively slowly. In a non-interrupt-driven sys-
tem the computer must poll the status register to determine if a character has been received,
which is inefficient in processor time. But, if the amount of time spent polling the status reg-
ister is reduced, there is a possibility of the computer missing the received character as an-
other could be sent before the first is read from the receiver buffer. If the serial communica-
tions port was set up to interrupt the processor when a new character arrived then it is guar-
anteed that the processor will always process the receiver buffer.
A major disadvantage with non-interrupt-driven software is when the processor is in-
volved in a 'heavy processing' task such as graphics or mathematical calculations. This can
have the effect of reducing the amount of time that can be spent in polling and/or reading
data.
28.2 DOS-based RS-232 program
Program 28.1 is a simple interrupt-driven DOS-based RS-232 program which is written for
Turbo/Borland C/C++. If possible, connect two PCs together with a cable which swaps the
TX and RX lines, as shown in Figure 13.18. Each of the computers should be able to trans-
mit and receive concurrently. A description of this program is given in the next section. The
header file associated with this program is serial.h .
Program 28.1
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <bios.h>
#include "serial.h"
void interrupt rs_interrupt(void);
void setup_serial(void);
void send_character(int ch);
Search WWH ::




Custom Search