serial port (2) 初始化com口

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

如何让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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航