Disk Files and Other I/O |
C C C |
|
C9C |
|
C C C |
|
C |
The line control register is located at base address + 3. This register controls the character format and the mapping of the divisor latch (see offset +0 and +1).
The modem control register is located at base address + 4. This register is used to control the port’s I/O connector control signals. These signals are then used to control the modem (or whatever else is connected to the port).
The line status register is located at base address + 5. It is used to pass to the program information regarding the status of the UART and the data being received.
The MODEM status register is located at base address + 6. The program uses this register to determine the status of the device connected to the port.
Note how the DLL and DLM registers (the speed registers) have the same address as the RBR and IER registers. This is accomplished with the divisor latch enable bit (0x80) of the LCR register. If this bit is set, these registers are used for the speed divisor. If this bit is cleared, these registers serve their other purpose.
A communications program can rely on the DOS MODE command setting the communications port parameters, or the program can set the parameters itself. Each of the port’s registers may be read (except transmitted data), modified, and written back. This process of reading, modifying, and writing a register is all that is required to initialize the serial port.
Listing 9.8, SENDCOMM.C, sends a single string, followed by a LF/CR character pair, to COM1:. Before you run SENDCOMM.C, COM1: must be initialized with the DOS MODE command.
Listing 9.8. SENDCOMM.C.
/* SENDCOMM, written 1992 by Peter D. Hipson
*This program outputs to the serial port. You should
*run this program under DOS on a PC. If your computer
*is not a PC-compatible, DO NOT RUN this program. Also,
*the program should be compiled with Microsoft C.
*/ |
|
|
#include <stdio.h> |
// Make includes first part of file |
#include <conio.h> |
// |
Console I/O functions |
#include <string.h> |
// |
For string functions |
continues