Serial Programming - upload.wikimedia....
Serial Programming - upload.wikimedia....
Serial Programming - upload.wikimedia....
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Finding the Port I/O Address for the UART<br />
4.3.1 Looking up UART Base Address in RAM<br />
We will get back to the issue of the IRQ Number in a little bit, but for now we need to know<br />
where to start accessing information about each UART. As demonstrated previously, DOS<br />
also keeps track of where the UART IO ports are located at for its own purpose, so you can<br />
try to "look up" within the memory tables that DOS uses to try and find the correct address<br />
as well. This doesn't always work, because we are going outside of the normal DOS API<br />
structure. Alternative operating systems ( FreeDOS works fine here ) that are otherwise<br />
compatible with MS-DOS may not work in this manner, so take note that this may simply<br />
give you a wrong result altogether.<br />
The addresses for the serial I/O Ports can be found at the following locations in RAM:<br />
Port Segment Offset<br />
COM1 $0040 $0000<br />
COM2 $0040 $0002<br />
COM3 $0040 $0004<br />
COM4 $0040 $0006<br />
Those addresses are written to memory by the BIOS when it boots. If one of the ports<br />
doesn't exist, the BIOS writes zero to the respective address. Note that the addresses are<br />
given in segment:offset format and that you have to multiply the address of the segment<br />
with 16 and add the offset to get to the physical address in memory. This is where DOS<br />
"finds" the port addresses so you can run the first sample program in this chapter.<br />
In assembler you can get the addresses like this:<br />
; Data Segment<br />
.data<br />
Port dw 0<br />
...<br />
; Code Segment<br />
.code<br />
mov ax,40h<br />
mov es,ax<br />
mov si,0<br />
mov bx,Port ; 0 - COM1 , 1 - COM2 ...<br />
shl bx,1<br />
mov Port, es:[si+bx]<br />
In Turbo Pascal, you can get at these addresses almost the same way and in some ways<br />
even easier because it is a "high level language". All you have to do is add the following line<br />
to access the COM Port location as a simple array:<br />
var<br />
ComPort: array [1..4] of Word absolute $0040:$0000;<br />
The reserved, non standard, word absolute is a flag to the compiler that instead of<br />
"allocating" memory, that you already have a place in mind to have the computer look<br />
instead. This is something that should seldom be done by a programmer unless you are<br />
accessing things like these I/O port addresses that are always stored in this memory location.<br />
57