8251初始化
MOV DX,03FAh ;set the command port address(设定命令端口地址(奇地址))
MOV AL,71h ;to define the operation mode(设置方式选择字)
OUT DX,AL ;output to command port(写入命令端口,存到方式寄存器中。)
MOV AL,15h ;to define the command mode(设置命令字)
OUT DX,AL ;output to command port(写入命令端口,存到命令寄存器中。)
以查询方式控制数据发送
MOV AX,TXD-ADDR ;initialize DS(初始化DS)
MOV DS,AX ;
MOV SI, OFFSET TXDBUF ;to set the transmission _buffer offset(初始化变址寄存器)
MOV CX,COUNT ;initialize the transmission data number(初始化总共要传输的字符个数)
TXD: IN AL,DX ;read the state port(从命令端口读状态字)
TEST AL,01 ;transmission buffer empty?(查询输入缓冲器是否为空)
JZ TXD ;jump to TXD(不空则继续查询,直到为空,可以传送数据)
MOV AL,[SI] ;get a transmission data(读取字符)
MOV DX,03F8h ;set the data port address(设定数据端口地址)
OUT DX,AL ;output the data(向数据端口输入字符)
INC SI ;address increase(地址加1)
DEC CX ;counter decrease(计数器减1)
JNZ TXD ;continue to transmit data until the counter equal 0(继续传输直到计数器为0)
┇
以查询方式控制数据接收
MOV AX,RXD-ADDR ;initialize DS(初始化DS)
MOV DS,AX ;
MOV SI,OFFSET RXDBUF ;to set the receiver _buffer offset(初始化变址寄存器)
MOV CX,COUNT ;initialize the received data number(初始化总共要接受的字符的个数)
RXD: IN AL,DX ;read the state port(读状态字)
TEST AL,02 ;receiver buffer non-empty?(接受缓冲区是否为空)
JZ RXD ;jump to RXD(空则继续查询,直到不空,)
TEST AL,38h ;error message?(是否有出错信息)
JNZ ERR ;jump ERR process(转出错处理)
IN AL,DX ;input data(从数据端口读数,接收数据)
MOV [SI],AL ;put the data to the memory(放到内存中)
INC SI ;address increase(地址加1)
DEC CX ;counter decrease(计数器减1)
JNZ RXD ;continue to receive data until the counter equal 0(继续接收直到计数器为0)
┇
ERR: … ;error process(错误处理程序)
|