一般而言,COM口的I/O地址是固定的,
3F8/2F8 BaseAdd + 0 Transmit/Receive Buffer
3F9/2F9 BaseAdd + 1 IER
3FA/2FA BaseAdd + 2 IIR(Read)/FCR(write)
3FB/2FB BaseAdd + 3 LCR
3FC/2FC BaseAdd + 4 MCR
3FD/2FD BaseAdd + 5 LSR
3FE/2FE BaseAdd + 6 MSR
3FF/2FF BaseAdd + 7 Scratch Pad Register
Abbreviate
CD - Carrier Detect
CTS - Clear to Send
DCD - Data Carrier Detect
DCE - Data communication Equipment
DDCD - Delta Data Carrier Detect
DLAB - baud rate divisor
DSR - Data set ready
DTE - Data Terminal Equipment
DTR - Data terminal ready
FCR - FIFO Control Register
FIFO - First In First Out
IER - Interrupt Enable Register
IIR - Interrupt Identification Register
LCR - Line Control Register
LSR - Line Status Register
MCR - Modem Control Register
MSR - Modem Status Register
RD - Receive Data
RI - Ring indicator
RTS - Request to Send
TD - Transmit Data
THRE - Transmitter Holding Register Empty
TSRE - Transmitter Shift Register Empty
Set Baud Rate
当LCR(Base Address+3) BIT7是1的时候,往Base+0/Base+1这两个端口写的数据就是要设置的波特率。
Baud Rate Base+1 Base+0 Baud Rate Base+1 Base+0 50 0x09 0x00 2400 0x00 0x30 110 0x04 0x17 3600 0x00 0x20 150 0x03 0x00 4800 0x00 0x18 300 0x01 0x80 7200 0x00 0x10 600 0x00 0xC0 9600 0x00 0x0C 1200 0x00 0x60 19200 0x00 0x06 1800 0x00 0x40 38400 0x00 0x03 2000 0x00 0x3A 57600 0x00 0x02 115200 0x00 0x01
Example Code:
BaudRateTable:
dw 01h ; 115200 0
dw 02h ; 57600 1
dw 03h ; 38400 2
dw 06h ; 19200 3
dw 0Ch ; 9600 4
mov dx, Base+3
in al, dx
jmp short $+2 ; delay
or al, 80h
out dx, al ; set LCR BIT7
jmp short $+2
push ax ; save the data
lea si, cs:BaudRateTable
shl bx, 1 ; bx =0/1/2/3/4
add si, bx ; si point the divisor
mov ax, word ptr cs:[si]
; al, base+0 value
; ah, base+1 value
mov dx, Base+0
out dx, al
jmp short $+2
xchg ah, al
inc dx
out dx, al
jmp short $+2
pop ax
and al, 07fh ; clear BIT7
mov dx, base+3
out dx, al
jmp short $+2
本文地址:http://com.8s8s.com/it/it26192.htm