微机原理与接口技术硬件实验报告2/18目录4.实验四串行口8251A实验.................................................................................34.1.实验目的......................................................................................................34.2.实验内容......................................................................................................34.2.1.自收自发线路连接............................................................................34.2.2.通信程序编写....................................................................................64.2.3.双机通信线路连接..........................................................................154.3.思考题........................................................................................................174.4.心得体会....................................................................................................17参考资料......................................................................................................................17声明与致谢..................................................................................................................183/184.实验四串行口8251A实验4.1.实验目的1.了解串行通信的一般原理和8251A的工作原理;2.初步了解RS232串行口标准及与TTL电路的连接方法;3.学会扩充8251A的方法,并设计实现用8251A进行数据传输;4.掌握8251A的编程方法。4.2.实验内容4.2.1.自收自发线路连接采用查询方式,将内存制定区域内存放的一批数据通过8251A的TXD发送出去,然后从RXD接收回来,并在屏幕上或数码管上显示出来。电路连接8MHz信号接分频器74LS393的CLK端(已接好),从74LS393的Q4(250kHz)接8253的CLK;T/C接地或接RESET;GATE接+5V;8253的OUT和8251A的TXC、RXC相连,作为发送时钟和接收时钟;8251A的CS和Y2相连,Y2地址为EE40-EE47H;8253的CS和Y1相连,Y1地址为EE20-EE27H;用导线将TXD和RXD相接,成为自发自收方式;CTS端必须为低电平(实验台中已接为低电平),8251A才可想外发送信号,RTS、DTR、DSR可不用。(但实验台中RTS、DTR、DSR均已接地)4/18图1自收自发连线图(局部)5/18图2自收自发实物连接图(局部)下面,我们在debug下检测电路连接是否正常。CODE(debugmode)oE82316oE82010oE84140oE8414EoE84137iE841oE84045iE84187iE84045三次执行i命令,显示的结果分别为858745说明8251A和8253工作正常。6/184.2.2.通信程序编写该通信程序既能适用与自收自发的情况,又能适用与双机通信。当发方按下小键盘的按钮时,在收方的七段数码管上能够显示发端按下的按钮序号。双方任意一方在标准输入下按键时,退出己方程序。程序流程图:StartEndInitializeNYDelayReleaseResourcesShowTubeGetStateException?StandardKeybroadInput?CatchExceptionRecvData?ReceiveYYNSendData?NNewButtonInput?SendYY图3通信程序流程图7/18程序源代码CODE(commu.asm);FILENAME:commu.asm;AUTHOR:XIAO,Zhiqing(No.13,Cl.07105);DATE:20091230;DESCRIPTION:communicatebyoneself;=============macro=============;macro:myOut(WARNING:itmaychangethevalueofAL);it'sstronglyrecommendedthatdatabeALmyOutMACROK8255PortAddr,dataPUSHDXMOVDX,K8255PortAddrMOVAL,dataOUTDX,ALPOPDXENDM;macro:myLutOut(WARNING:itmaychangethevalueofAL);it'sstronglyrecommendedthatdatabeALmyLutOutMACROK8255PortAddr,lut,dataPUSHDXPUSHBXMOVBX,OFFSETlutMOVAL,dataXLATlutMOVDX,K8255PortAddrOUTDX,ALPOPBXPOPDXENDM;macro:myIn(WARNING:itmaychangethevalueofAL);it'sstronglyrecommendedthatdatabeALmyInMACROK8255PortAddr,dataPUSHDXMOVDX,K8255PortAddrINAL,DXMOVdata,AL8/18POPDXENDM;=============datasegment=============DataSEGMENT;SegmentsLookupTableSegLutDB0EDH,21H,0F4H,0F1H,39H;01234DB0D9H,0DDH,61H,0FDH,0F9H;56789DB7DH,9DH,0CCH,0B5H,0DCH,5CH;ABCDEFDB3DH,8CH;'H'(10H)'L'(11H)DB00H,10H,00H;''(12H)'-'(13H)unvalid(14H)spaceEQU12HbarEQU13HunvalidEQU14H;buttonmatrixbuttonPressedDB0;0FFHforpressed,00Hfornot.buttonRowDB0buttonColDB0buttonIndexDBunvalidsendEnDB0;0FFHstandsforthatthereisnewinput,00HfornotsendDataDBunvalidrecvDataDBunvalidKTrueEQU0FFHkFalseEQU00HlabEQU1;1standforXue9,0standforJiao2IFlab;Xue9KPortSwAndLedEQU0E8E0H;8255K8255PortAEQU0E800H9/18K8255PortBEQU0E801HK8255PortCEQU0E802HK8255ControlEQU0E803H;8253K8253Timer0EQU0E820HK8253ControlEQU0E823H;8251K8251DataEQU0E840HK8251ControlEQU0E841HELSE;Jiao2KPortSwAndLedEQU0EEE0H;8255K8255PortAEQU0EE00HK8255PortBEQU0EE01HK8255PortCEQU0EE02HK8255ControlEQU0EE03H;8253K8253Timer0EQU0EE20HK8253ControlEQU0EE23H;8251K8251DataEQU0EE40HK8251ControlEQU0EE41HENDIFDataENDS;=============stacksegment=============StackSEGMENTSTACK'STACK'DB100HDUP(?)StackENDS;=============codesegment=============10/18CodeSEGMENTASSUMECS:Code,DS:Data,SS:StackMainPROCFARPUSHDSXORAX,AXPUSHAXMOVAX,DataMOVDS,AXmyOutK8255Control,80H;send(10000000B)toControlPortof8255;A--mode0,output;B--mode0,output;CHigh--output(itwillchangeduringrunning);CLow--output(itwillchangeduringrunning)myOutK8255PortA,00HmyOutK8253Control,16H;send00010110toPortControlof8253;00:Timer#0;01:Lowbyteonly;*11:Mode3;0:BinarymyOutK8253Timer0,10HmyOutK8251Control,40H;reset8251CALLBasicDelay;waitamomentmyOutK8251Control,4EH;send(01001110B)toPortControlof8251;01:1stopbit;00:noverifybits;11:8bitsperframe;10:Baudrate16CALLBasicDelay;waitamomentmyOutK8251Control,37H;send(00110111B)toPortControlof8251,readyCALLBasicDelay;waitamomentendlessLoopLabel:CALLShowTube11/18CALLBasicDelayCALLCheckExitmyInK8251Control,AL;readstatebyteof8251TESTAL,38H;checkifthereareerrors;001(FE)1(OE)1(PE)000BJNZthrowExceptionTESTAL,02H;checkiftherearedatarecieved;0000001(RxRDY)0JNZreceiveLabelTESTAL,01H;checkiftherearedatarecieved;00000001(TxRDY)JNZsendLabelthrowException:myOutK8251Control,37H;clearerrorbitsJMPendlessLoopLabelreceiveLabel:myInK8251Data,recvData;recieveJMPendlessLoopLabelsendLabel:CALLCheckButtonInputTESTsendEn,0FFHJZendlessLoopLabelmyOutK8251Data,sendData;sendJMPendlessL