编程语言

img ui_ppoppopp

serial port (2) 初始化com口

发表于2004/10/29 15:28:00  931人阅读

如何让com口工作在中断模式:
1, 在8259中把com口对应的中断打开
2, MCR BIT3(OUT2)设1(X86架构)
3, IER 把需要的中断置起来,

如何让com口工作在FIFO模式:
1。设置FCR BIT0让COM知道下面是设置FIFO模式的命令。
2。设置FCR BIT7-BIT6 来决定缓冲大小
            0    0    1byte
            0    1    4byte
            1    0    8byte
            1    1    14byte
3. 设置FCR BIT3来 启动FIFO模式

下面这段代码就是初始化COM口,并工作在FIFO模式。


Sample Code

; Set IRQ enable and out2 to set enable interrupts
                                       
        mov     cl, COM_IRQ             ;
        mov     dx, 21h
        cmp     cl,7                    ; judge IRQ > 7
        jbe     short wlsp_00  
        mov     dx, 0a1h
        sub     cl, 8

wlsp_00:
        in      al, dx                  ; Program Interrupt Controller to

        mov     ah, 01
        shl     ah, cl
        xor     ah, 0FFh
        and     al, ah
        out     dx, al

        mov     cl, COM_IRQ             ;
        cmp     cl, 7
        jbe     wlsp_01

        in      al, 21h
        and     al, 0FBh
        out     21h, al

wlsp_01:

        mov     bh, MCR                 ; Modem Control Register
        call    Read_COM_Reg            ; Read the reg to

        mov     bh, MCR
        mov     bl, 008h                ; set out2 to set enable interrupts
        call    Prog_COM_Reg            ; Program the reg


; Set Enable Buad_Rate
        mov     bx, 0383h               ; Prog 3FB reg to
                                        ; Data Bits =8, Access baud rate generator
        call    Prog_COM_Reg


; Program the baud rate divisor
        mov     bh, 00h                 ; Prog 3FB reg to set
        mov     bl, DIVISER             ; Baud rate divisor LSB
        call    Prog_COM_Reg

 

        mov     bx, 0100h               ; Prog 3F9h reg to set
                                        ; Baud rate divisor MSB
        call    Prog_COM_Reg


; Reset DLAB, program 8 bits, 1 stop bit, no parity checking
        mov     bx, 0303h               ; 3FB, 8 Bits per char
        call    Prog_COM_Reg


; Program COM port Interrupt Enable Register
        mov     bx, 0100h               ; Prog 3F9 Reg to
                                        ; disable THRE, line status,
                                        ; modem-status-change, data available int
        call    Prog_COM_Reg


; FIFO Control Register
        mov     bx, 0201h               ; Prog 3FA reg to
                                        ; enable FIFOs
        call    Prog_COM_Reg

 

        mov     bx, 02C7h               ; Prog 3FA reg to
                                        ; 14-byte level trigger, TX FIFO reset,
                                        ; RX FIFO reset, enable FIFO
                                        ; Clear FIFOs, 14-byte level
        call    Prog_COM_Reg


; Interrupt Ident Register
        mov     bh, 02h                 ; 3FAh reg
        call    Read_COM_Reg

; Modem Conltrol Register
        mov     bx, 040Bh               ; Prog 3FC reg to
                                        ; Activate DTR, RTS, OUT2
        call    Prog_COM_Reg


; Interrupt Enable Register
        mov     bx, 010Fh               ; Prog 3F9 reg to
                                        ; enable THRE, line status,
                                        ; modem-status-change, data available int
        call    Prog_COM_Reg

; Line Status Register - LSR
; reset the LSR
; reset IIR
        mov     bh, 05h                 ; 3FDh reg
        call    Read_COM_Reg


; Modem Status Register - MSR
; reset MSR
; reset IIR
        mov     bh, 06h                 ; 3FEh reg
        call    Read_COM_Reg

系列文章连接
CMO 1

阅读全文
0 0

相关文章推荐

img
取 消
img