Com port (1)

Port Address

    一般而言,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 RateBase+1Base+0Baud RateBase+1Base+0
500x090x0024000x000x30
1100x040x1736000x000x20
1500x030x0048000x000x18
3000x010x8072000x000x10
6000x000xC096000x000x0C
12000x000x60192000x000x06
18000x000x40384000x000x03
20000x000x3A576000x000x02
1152000x000x01

 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


Transmission parameters Knowledge

 LCR BIT1 BIT0 ---- Word length
      0    0            5 bit
      0    1            6 bit
      1    0            7 bit
      1    1            8 bit


 LCR BIT2 ---- stop bits length
      0   1bits
      2   2bits

 LCR BIT3 ---- Parity or not
      0   disable parity
      1   enable parity

 LCR BIT5 BIT4 ---- Parity control
      0    0  odd parity
      0    1  even parity
      1    0  parity is always 1
      1    1  parity is always 0


 如果我们要设置字长是8,停止位是1,无奇偶校验程序如下:

Sample Code

        mov     dx, base+3
        in      al, dx
        jmp     short $+2
        or      al, 03          ; set 8bit
        and     al, 011111011b  ; set 1 stop bit
        and     al, 011110111b  ; set no parity
        out     dx, al
        jmp     short $+2

    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值