computer interfacing tutorial-printer, serial, game, usb port
 

 

4.2. Serial Port Register

Port Address

Name
Address
IRQ
COM 1
3F8
4
COM 2
2F8
3
COM 3
3E8
4
COM 4
2E8
3
Table 3 : Standard Port Addresses

 

Above is the standard port addresses. These should work for most P.C's. If you just happen to be lucky enough to own a IBM P/S2 which has a micro-channel bus, then expect a different set of addresses and IRQ's. Just like the LPT ports, the base addresses for the COM ports can be read from the BIOS Data Area.

Start Address
Function
0000:0400
COM1's Base Address
0000:0402
COM2's Base Address
0000:0404
COM3's Base Address
0000:0406
COM4's Base Address
Table 4 - COM Port Addresses in the BIOS Data Area;

The above table shows the address at which we can find the Communications (COM) ports addresses in the BIOS Data Area. Each address will take up 2 bytes. The following sample program in C, shows how you can read these locations to obtain the addresses of your communications ports.

#include <stdio.h>
#include <dos.h>
void main(void)
{
 unsigned int far *ptraddr;  /* Pointer to location of Port Addresses */
 unsigned int address;       /* Address of Port */
 int a;
 ptraddr=(unsigned int far *)0x00000400;
 for (a = 0; a <  4; a++)
   {
    address = *ptraddr;
    if (address == 0)
                printf("No port found for COM%d \n",a+1);
    else
                printf("Address assigned to COM%d is %Xh\n",a+1,address);
    *ptraddr++;
   }
}

Table of Registers

Base Address
DLAB
Read/Write
Abr.
Register Name
+ 0
=0
Write
-
Transmitter Holding Buffer
=0
Read
-
Receiver Buffer
=1
Read/Write
-
Divisor Latch Low Byte
+ 1
=0
Read/Write
IER
Interrupt Enable Register
=1
Read/Write
-
Divisor Latch High Byte
+ 2
-
Read
IIR
Interrupt Identification Register
-
Write
FCR
FIFO Control Register
+ 3
-
Read/Write
LCR
Line Control Register
+ 4
-
Read/Write
MCR
Modem Control Register
+ 5
-
Read
LSR
Line Status Register
+ 6
-
Read
MSR
Modem Status Register
+ 7
-
Read/Write
-
Scratch Register

Table 5 : Table of Registers

DLAB

You will have noticed in the table of registers that there is a DLAB column. When DLAB is set to '0' or '1' some of the registers change. This is how the UART is able to have 12 registers (including the scratch register) through only 8 port addresses. DLAB stands for Divisor Latch Access Bit. When DLAB is set to '1' via the line control register, two registers become available from which you can set your speed of communications measured in bits per second.

The UART will have a crystal which should oscillate around 1.8432 MHZ. The UART incorporates a divide by 16 counter which simply divides the incoming clock signal by 16. Assuming we had the 1.8432 MHZ clock signal, that would leave us with a maximum, 115,200 hertz signal making the UART capable of transmitting and receiving at 115,200 Bits Per Second (BPS). That would be fine for some of the faster modems and devices which can handle that speed, but others just wouldn't communicate at all. Therefore the UART is fitted with a Programmable Baud Rate Generator which is controlled by two registers.

Lets say for example we only wanted to communicate at 2400 BPS. We worked out that we would have to divide 115,200 by 48 to get a workable 2400 Hertz Clock. The "Divisor", in this case 48, is stored in the two registers controlled by the "Divisor Latch Access Bit". This divisor can be any number which can be stored in 16 bits (ie 0 to 65535). The UART only has a 8 bit data bus, thus this is where the two registers are used. The first register (Base + 0) when DLAB = 1 stores the "Divisor latch low byte" where as the second register (base + 1 when DLAB = 1) stores the "Divisor latch high byte."

Below is a table of some more common speeds and their divisor latch high bytes & low bytes. Note that all the divisors are shown in Hexadecimal.

Speed (BPS)
Divisor (Dec)
Divisor Latch High Byte
Divisor Latch Low Byte
50
2304
09h
00h
300
384
01h
80h
600
192
00h
C0h
2400
48
00h
30h
4800
24
00h
18h
9600
12
00h
0Ch
19200
6
00h
06h
38400
3
00h
03h
57600
2
00h
02h
115200
1
00h
01h
Table 6 : Table of Commonly Used Baudrate Divisors

PREVIOUS NEXT

 

Free Software
Delphi

Lesson 1
Delphi Programming
1.1. IDE Delphi
1.2. Component


Lesson 2
Printer Port
/ LPT
1.1.Basic
1.2.Address
1.3.Port Register
1.4.8 Bit Data Input
1.5.Test Circuitry
1.6.Assignment

Lesson 3
Printer Port / LPT
Experiments

3.1.LED
3.2.Swicht
3.3.Motor Stepper
3.4.DAC
3.5.ADC
3.6.Graph Display

Lesson 4
Serial Port

4.1.Basic
4.2.Hardware
4.3.Port Register

Lesson 5
Serial Port Experiments

5.1.LED
5.2.Stepper Motor
5.3.Swicht
5.4.ADC

Lesson 6
Game Port
Joy Stick
6.1. Basic
6.2. Experiments