Chapter VII summarizes the finale --8251A

Chapter VII finally put this review is over, I put a little bit about the rest of the hair Come on 8251A

Originally on the books also explain 8251A on RS232 serial communication and explanations, but too shallow, on hold, and friends who are interested can refer to other articles on their own

 Serial communication chip 8251A

It has the following characteristics

  1. May be used for synchronous or asynchronous transmission, synchronous 0-64kbps, asynchronous 0-19.2kpbs
  2. When an isochronous transfer, 5-8 bits / character, the character may be used to synchronize the external sync or synchronization, can be automatically inserted
  3. When asynchronous transmission, 5-8 / character, stop bits have 1,2,1.5
  4. Full duplex, double-buffered send and receive data
  5. Having error checking, parity, overrun, and framing error detection circuitry, etc.

 Well, why should this 8251A

Because the internal computer is transmitting data in parallel, but the serial communication are used in long-distance communication (these concepts do not understand their own friends can not understand the concept of Baidu, or read a book)

It must be something to transform it

8251

8251 internal structure

An internal structure comprising a receiver, a transmitter, a read / write control logic, a data bus buffer control circuit and a modem five major

 

 

 

receiver

It includes a reception buffer, and receiving three parallel conversion logic circuit of the control section

External pin receiving buffer RxD, a function is received from the serial data on the pins, and then converted into parallel data, is received by the receiving shift register and the data buffer composed of dual buffer structure

Receiving control circuit is a buffer with the work, the following effect

1. In the asynchronous mode, the chip reset, to detect a valid input signal, upon detection that it is then determined to find effective low-level start bit

2 to eliminate interference false start

3 information received parity, and establish a corresponding status bit in accordance with the check result

4 detects the stop bit, the establishment of status bits and detecting structure

 

 

Transmitter

And a receiver similar, also a transmission buffer, the transmission control logic circuit and a parallel-serial conversion section 3

A transmission buffer is above TxD pin contact, transmit data buffer and transmit shift register composed of a double-buffered configuration of a transmission, the transmission control circuit is an auxiliary transmission buffer, but not the same function and acceptable

Acting as the transmission control circuit

  1. Insert start bit, parity and stop bits in asynchronous mode
  2. In synchronous mode, inserting a synchronization character, a parity bit inserted in the data

 

Data bus buffer

8251A provides the CPU to the system bus, while the CPU performs input and output operations, read and write commands or data exchange

 

Read / write control logic circuit

To work with the bus buffer

  1. Write signal WR #, the data bus signals (data / control word) 8251A
  2. Read signal RD #, send status / data word to the CPU (sent to the data bus)
  3. Receiving control / data signal C / D #, and read. Write signal combination, is being processed 8251A identification data or control word
  4. Receiving a clock signal CLK, the timing of the completion of the interior 8251
  5. Receiving a reset signal RESET, let idle 8251

 

Modulation / demodulation control circuit

Time to remote communication, when the modulator of the digital transmission signal into an analog signal, when the demodulator receiving the analog signal into a digital signal, which may be used as contact pins for controlling data transmission line other peripherals

 

8251A defined external pins

Signal and connected to the CPU

CS #, chip select signal, obtained from the M / IO # and an address decoder

D0-D7 data transmission signal

Read signal RD #, CPU reads information from the 8251A

WR # write signal, CPU writes 8251A

C / D # control / data selection signal, if the signal is 0, represents the transfer from the data bus is the data amount, if 1, showing now written on the data bus control information (English is very good in mind, control data )

 

 

 

 

 

8251 addresses only two ports, port data is an even address (input port is output), the control information is an odd address, is used in 8086 to distinguish the parity address A1, if A1 is 0, the address is even, A1 1 is an odd address, it is just and C / D # correspondence, so A1 pin is usually connected C / D #

 

TxRDY: transmitter is ready, output, high, represents the transmitter is ready, which means that transmit data buffer empty (not empty how hair ah), CPU can send data to 8251A. If interrupted form, it can also do this TxRDY interrupt request signal, if the query is a query will continue to get away with it

TxE null signal transmission, output, high, and represents the conversion is empty string (data undergo serial converter and the converted parallel data into serial data to send). If you get a 8251 data, TxE will go low. In synchronous mode spaced strings allowed, but if the CPU time to send data to 8251A, the TxE to 1, inserting a synchronization character

 

RxRDY, represents the receiver is ready, you can accept the data, if the data is received from a peripheral to wait for the CPU, of course, can also be used interrupted, use this as an interrupt request signal, the program will search query he gets the job done

 

SYNDET:同步检测/断电检测信号,高有效,输出/输入 同步方式时表示同步检测,如果为内同步,作为输出,输出为1,表示找到同步字了;在外同步的时候,作为输入,变高后,在RxC#(接收器时钟)的下一个下降沿装配字符,在异步方式下,作为空白检测信号,输出,如果接收到全0的字符,输出高电平

 

和外设连接的信号脚

DTR#    数据终端准备好了,由8251A发给外设,表示CPU准备就绪

DER#    数据设备请求好了,由外设发给8251A,表示外设已经准备就绪

RTS#    请求发送信号,由8251A发送给外设,表示CPU已经准备好发送

CTS#    清除请求发送信号,由外设发送8251A,表示可以往外设发送数据

TxD      数据传送端,CPU送到8251A的并行数据变成串行数据后,由TxD送往外设

RxD      数据接收端,数据从外设进入8251A后,变成并行数据

CLK      8251A的内部时序时钟,同步要求是波特率的30倍,异步的话要求波特率的4.5倍

TxC,发送时钟,输入,控制字符的发送速度,同步是等于字符传送的波特率,异步方式是初始化定义的

RxC,和TxC差不多,是控制接受端的接受速度

在实际中,把RxC和TxC连在同一个时钟上,CLK是由另一个频率更高的外部时钟提供(啊引脚太多了,考试会给的)

8251A的工作方式

异步方式

  1. 接受

在异步方式准备接收一个字符的时候,RxD就在线上检测低电平(没有检测的时候就是高电平),假如这个时候检测到了低电平,8251A就会以这个低电平作为起始位,并且启动内部定时计数器,当计数器到一半数位传输时间(比如初始设置时间脉冲为波特率的16倍),则定时器到第八个脉冲的时候,又重新对RxD进行取样,如果仍为低电平就确定是一个有效的起始位,(如果这个时候为高电平了,8251A会认为刚刚低电平是一个干扰信号,这个过程就重头开始了),8251就开始进行常规取样并进行字符装配(就是每隔一段时间对RxD进行采样)数据进入移位寄存器后(并进行去掉奇偶校验位和停止位),变成并行数据,在通过内部总线送到数据输入寄存器,同时发出RxRDY信号到CPU,表示外设的数据已经收到了,是可用的。对于少于八位的,高位自动填零

  1. 发送

当程序把TxEn(允许发送信号)和CTS#(清除请求发送信号,不懂的朋友再仔细看看上文)后就开始发送。在发送的时候,发送器自动添加1个起始位,再按照初始化的格式添加奇偶校验位,停止位。数据及起始位,校验位,停止位总是在发送时钟的TxC下降沿时发出

同步方式

  1. 接受

其实和异步也差不多,就是RxD先进行搜索同步字符,找到第一个数据了,送到移位寄存器移位,然后和同步字符的内容进行比较,相等就是找到了,SYNRET=1;开始接收数据块,不相等就重新来(双同步也差不多,就是第一次找到了再来一次,第二次找不到重头开始找第一个字符) ,如果是外同步的话,如果SYNDET=1;的时候,直接开始,RxD就不用找起始位了直接开始采样数据块。

实现同步之后,就利用时钟信号对RxD进行数据采样,送到移位寄存器移位,然后从RxRDY引脚发出一个信号,表示已经收到了一个字符,一旦CPU读完之后,这个RxRDY=0;

  1. 发送

发送也差不多,程序先对TxEN和CTS#初始化了,这个时候就开始发送,程序会先发1/2个同步字符,然后发送数据块,发送数据块的时候,发送器自动按初始化要求添加奇偶校验位(没有就不加)。如果8251正在发送的时候CPU来不及发送数据了(比如说遇到了中断之类的),那么就会重新发1/2个同步字符,等待CPU。满足了同步字符之间没有空隙。

 

8251A的编程(当然是考试的重点啦)

必须按照下面的规定进行编程

  1. 芯片复位之后,第一次用奇地址写控制字,在控制字中规定是同步还是异步

如果是同步,CPU会接着发1/2个字节就是同步字符,写入同步字符寄存器,然后再把控制命令字写入奇端口

如果是异步方式,CPU往奇端口输出的一个字就是命令控制字

  2. 在相关命令设置好了之后,只要不复位,用奇端口写控制字,偶端口写的是数据,送到数据输出缓冲器中

 

 

工作模式字(写入奇端口)

最低两位如果为00,则为同步方式,否则就是异步方式

在同步方式下接受和发送的频率同TxD和RxD相同,异步方式下,TxD/RxD=波特率因子*波特率

 

 

同步字符的控制命令字如下,从高到低说起

第一位是同步字符的位数,0是1个同步字符,1是2个同步字符

第二位决定是内同步还是外同步,0是内同步,1是外同步

第三位是奇偶校验位,0是奇校验,1是偶校验

第四位是有没有校验,0是没有校验,1是有校验

第五第六位是决定数据块的位数,00是5位,01是6位,10是7位,11是8位

最后两位必定是00

举个例子,比如说现在要求发送的是同步方式,1个同步字符外同步,偶校验,数据位是8位,那么初始化命令字就应该向奇端口(假如为FFF2H)写01111100B,换成16进制就是79H

汇编初始化就应该是

MOV DX FFF2H

MOV AL 79H

OUT DX AL

 

现在看看异步通信的初始化命令字(从高到低)

前两位是停止位的数目,00非法,01是1位,10是1.5位,11是2位停止位

第三位是EP(奇偶校验类型),0为奇校验,1为偶校验

第四位是有无校验,0是无,1是有

第五第六位是数据的大小,00是5位,01是6位,10是7位,11是8位

最后两位是决定波特率因子(不能是00,00就表示同步通信了),01表示波特率因子为1,10表示波特率因子为16,11表示波特率因子为64

举个例子,异步通信,1个停止位,无校验,8个数据位(刚好最近在做单片机的串口通信,这就是8N1格式)波特率因子为16,则应该向奇端口(假设还是FFF2H吧)写入01001110B,HEX格式为4EH

MOV DX, FFFEH

MOV AL, 4EH

OUT DX, AL

命令控制字格式

同步字符的控制命令字如下,从高到低说起

第一位是同步字符的位数,0是1个同步字符,1是2个同步字符

第二位决定是内同步还是外同步,0是内同步,1是外同步

第三位是奇偶校验位,0是奇校验,1是偶校验

第四位是有没有校验,0是没有校验,1是有校验

第五第六位是决定数据块的位数,00是5位,01是6位,10是7位,11是8位

最后两位必定是00

举个例子,比如说现在要求发送的是同步方式,1个同步字符外同步,偶校验,数据位是8位,那么初始化命令字就应该向奇端口(假如为FFF2H)写01111100B,换成16进制就是79H

汇编初始化就应该是

MOV DX FFF2H

MOV AL 79H

OUT DX AL

 

现在看看异步通信的初始化命令字(从高到低)

前两位是停止位的数目,00非法,01是1位,10是1.5位,11是2位停止位

第三位是EP(奇偶校验类型),0为奇校验,1为偶校验

第四位是有无校验,0是无,1是有

第五第六位是数据的大小,00是5位,01是6位,10是7位,11是8位

最后两位是决定波特率因子(不能是00,00就表示同步通信了),01表示波特率因子为1,10表示波特率因子为16,11表示波特率因子为64

举个例子,异步通信,1个停止位,无校验,8个数据位(刚好最近在做单片机的串口通信,这就是8N1格式)波特率因子为16,则应该向奇端口(假设还是FFF2H吧)写入01001110B,HEX格式为4EH

MOV DX, FFFEH

MOV AL, 4EH

OUT DX, AL

命令控制字格式

同步字符的控制命令字如下,从高到低说起

第一位是同步字符的位数,0是1个同步字符,1是2个同步字符

第二位决定是内同步还是外同步,0是内同步,1是外同步

第三位是奇偶校验位,0是奇校验,1是偶校验

第四位是有没有校验,0是没有校验,1是有校验

第五第六位是决定数据块的位数,00是5位,01是6位,10是7位,11是8位

最后两位必定是00

举个例子,比如说现在要求发送的是同步方式,1个同步字符外同步,偶校验,数据位是8位,那么初始化命令字就应该向奇端口(假如为FFF2H)写01111100B,换成16进制就是79H

汇编初始化就应该是

MOV DX FFF2H

MOV AL 79H

OUT DX AL

 

现在看看异步通信的初始化命令字(从高到低)

前两位是停止位的数目,00非法,01是1位,10是1.5位,11是2位停止位

第三位是EP(奇偶校验类型),0为奇校验,1为偶校验

第四位是有无校验,0是无,1是有

第五第六位是数据的大小,00是5位,01是6位,10是7位,11是8位

最后两位是决定波特率因子(不能是00,00就表示同步通信了),01表示波特率因子为1,10表示波特率因子为16,11表示波特率因子为64

举个例子,异步通信,1个停止位,无校验,8个数据位(刚好最近在做单片机的串口通信,这就是8N1格式)波特率因子为16,则应该向奇端口(假设还是FFF2H吧)写入01001110B,HEX格式为4EH

MOV DX, FFFEH

MOV AL, 4EH

OUT DX, AL

命令控制字格式

 

 

命令控制字还是写入的是奇端口

看图片吧,懒得打字了,一般EH位是用在内同步方式的,为1就开始搜索同步字,RTS(发送允许)(第三位)为1就让RTS#有效(这初始化太容易混了),DTR,同理(数据终端准备好了),RxD接受有效,比如说0011 0111就是发送允许,接受允许,发送启动,接受启动,出错复位,多看看前面引脚定义吧,我刚开始有点混,上面的例子是书上的,应该是不会错的

 

还有一个状态字格式(太多了…根本记不住啊)

DSR(这里对DSR#取了非)(表示外设准备好了的信号),如果为1就是准备好了

SYNDET (同步检测/断电端)

TxE 为1就是8251接收到CPU的数据了,正在向发送缓冲器发

FE 格式错 OE 覆盖错误,PE 奇偶校验错误,这三个可以用命令控制字重新写

大概就这些了,上面这些还是得多看看例子,书上例子,课后题多看看,这些就得看个人了,不多写了,我就赶紧溜了去看题了,下个星期考试了

Guess you like

Origin www.cnblogs.com/Kevin-Weng/p/12022509.html