1、北邮微机原理与接口技术2微机原理与接口技术硬件实验报告目录2. 实验二 8255A并行接口应用 32.1. 实验目的 32.2. 实验内容 32.2.1. 静态显示学号 32.2.2. 动态显示HELLO 92.2.3. 回显小键盘输入 152.3. 心得体会 21参考资料 22声明与致谢 222. 实验二 8255A并行接口应用2.1. 实验目的2.1.1. 掌握8255A的功能及方式0、1的实现;2.1.2. 熟悉8255A与CPU的接口,以及传输数据的工作原理及编程方法;2.1.3. 了解七段数码管显示数字的原理;2.1.4. 掌握同时显示多位数字的技术。2.2. 实验内容2.2.1.
2、静态显示学号在数码管电路上静态地显示6位学号,当主机键盘按下任意键时,停止显示,返回DOS。首先,我通过debug命令,探索各个段对应的位。结果如下图:图6七段数码管利用这张图,我们可以制作出一些常见符号与段选信号的对应表。其中,09是为了第三个小步骤而列举的。表2本实验中使用的一些符号对应的数码管表示符号二进制代码十六进制代码0或O11101101ED10010000121211110100F4311110001F140011100139511011001D9611011101DD70110000161811111101FD911111001F9A011111017Db100111019DC
3、11001100CCd10110101B5E11011100DCF010111005CH001111013DL100011008C多个数码管动态扫描显示,是将所有数码管的相同段并联在一起,通过选通信号分时控制各个数码管的公共端,循环依次点亮多个数码管,利用人眼的视觉暂留现象,只要扫描的频率足够大,将看不到闪烁现象。实验证明,在扫描显示过程中,每一位显示延迟1ms是最佳选择。在代码中,Show这个过程是来显示数码管的。主程序流程图:图 7 主程序流程图源代码:CODE (070141.asm); FILENAME : 070141.asm; AUTHOR : XIAO, Zhiqing ( No
4、. 13, Cl. 07105 ); DATE : 20091216; DESCRIPTION : display 070141 on seven tubes array; macro : myOut ( WARNING : it may change the value of AL ); its strongly recommended that data be ALmyOut MACRO portAddr, data PUSH DX MOV DX, portAddr MOV AL, data OUT DX, AL POP DXENDM; macro : myDigitOut ( WARNI
5、NG : it may change the value of AL ); its strongly recommended that data be ALmyDigitOut MACRO portAddr, data PUSH DX PUSH BX MOV BX , OFFSET SegLut MOV AL , data XLAT SegLut MOV DX, portAddr OUT DX, AL POP BX POP DXENDM ; macro : myIn ( WARNING : it may change the value of AL ); its strongly recomm
6、ended that data be ALmyIn MACRO portAddr, data PUSH DX MOV DX, portAddr IN AL, DX MOV data, AL POP DXENDMData SEGMENT; Segment Lookup TableSegLut DB 0EDH , 21H , 0F5H , 0F1H , 39H ; 01234 DB 0D9H , 0DDH , 61H , 0FDH , 0F9H ; 56789 DB 7DH , 9DH , 0CDH , 0D5H , 0DCH ; ABCDEF DB 3DH , 8CH ; HL; Content
7、 index array to printContent DB 00H , 07H , 00H , 01H , 04H , 01H; 8255PortA EQU 0E800HPortB EQU 0E801HPortC EQU 0E802HPortControl EQU 0E803HData ENDSStack SEGMENT STACK STACK DB 100H DUP ( ? )Stack ENDSCode SEGMENTASSUME CS : Code , DS: Data , SS : StackMain PROC PUSH DS XOR AX, AX PUSH AX MOV AX,
8、Data MOV DS, AX myOut PortControl, 80H ; 1 000 0 00 0B means : ; A - mode 0 , output ; B - mode 0 , output ; C High - output ; C Low - output view : CALL Show JMP view RET ; unreachable instructionMain ENDP; proc Show; input argument lists : POINTShow PROC PUSH BX PUSH CX PUSH SI MOV BX, OFFSET Cont
9、ent MOV CL, 01H ; initialize ; make CL = 00000001B , which means enable the left most digit MOV SI, 0 nextDigit : myOut PortB, CL ; select tubes PUSH CX MOV AL, BYTE PTR BX + SI ; myDigitOut PortA, AL ; select segments POP CX ROL CL, 1 ; display the left digit next to current one INC SI ; next lette
10、r CALL Delay CALL CheckAndQuit CMP SI, 6 JNZ nextDigit POP SI POP CX POP BX RETShow ENDPDelay PROC PUSH CX MOV CX, 0F000HloopLabel: NOP LOOP loopLabel POP CX RETDelay ENDPcheckAndQuit PROC PUSH AX MOV AH, 0BH ; check whether user input something from keyboard INT 21H OR AL, AL ; if he does, then ret
11、urn to Dos JZ exitCheckAndQuit myOut PortA, 0 ; select tubes myOut PortB, 0 ; select tubes MOV AX, 4C00H INT 21HexitCheckAndQuit : POP AX RETcheckAndQuit ENDPCode ENDSEND Main经编译、连接、运行,显示正常,且能够成功返回DOS。图 8 静态显示学号2.2.2. 动态显示HELLO要求在数码管电路16位数码管上按下图所示的规律,动态显示字符串HELLO,当主机键盘按下任意键时结束。利用实验一读入端口的功能,控制动态显示的速度
12、。第一屏H第二屏HE第三屏HEL第四屏HELL第五屏HELLO第六屏HELLO图 9 HELLO显示次序按照我的设计,该程序要像上一个程序(070141.asm)一样,通过更新显示的下标数组Content来改变数码管显示。但是,实验指导要求使用以下方法:REQUIREMENT (实验二 8255A并行接口应用.pdf)在数据段,按下列规律设置12个字型码: MESG DB 0,0,0,0,0,0,3DH,0DCH,8CH,8CH,0EDH,0 POINT DW MESG POINT单元存放MESG单元的有效地址,程序取出POINT单元的内容BX,然后用BX间址取数送数码管电路,扫描显示6个字符
13、。每过0.5s将POINT单元的内容加1,再将POINT单元的内容BX,。POINT单元内容加1,使字符串显示的首地址向高地址移动一个单元,从而使6位字符串向“左”移动一位,实现动态显示。为了满足实验指导书的要求,我改动了程序的结构,不再使用查表的方法。图 10 动态显示HELLO流程图在本程序中,拨码开关S0控制是否移动。拨码开关往上拨,移动停止在第五屏;否则移动。拨码开关S1控制移动速度。拨码开关往上拨,移动变慢;拨码开关往下拨,移动变快。源代码如下:CODE (hello.asm); FILENAME : Hello.asm; AUTHOR : XIAO, Zhiqing ( No. 1
14、3, Cl. 07105 ); DATE : 20091216; DESCRIPTION : display Hello on seven tubes array; USAGE : ; S0 : UP still , DOWN move; S1 : UP slow , DOWN fast; macro : myOut ( WARNING : it may change the value of AL )myOut MACRO portAddr, data PUSH DX MOV DX, portAddr MOV AL, data OUT DX, AL POP DXENDM; macro : m
15、yIn ( WARNING : it may change the value of AL )myIn MACRO portAddr, data PUSH DX MOV DX, portAddr IN AL, DX MOV data, AL POP DXENDMData SEGMENTMESG DB 0, 0, 0, 0, 0, 0, 3DH, 0DCH, 8CH, 8CH, 0EDH, 0 ; HELLOPOINT DW MESG; XUE 9 MODEPortSw EQU 0E8E0H; JIAO 2 MODE; PortSw EQU 0EEE0HSwState DB 0 ; switch
16、ers : 01H - 1 still, 0 move ; 02H - 1 slow, 0 fast; 8255PortA EQU 0E800HPortB EQU 0E801HPortC EQU 0E802HPortControl EQU 0E803HViewIndex DB 0Data ENDSStack SEGMENT STACK STACK DB 100H DUP ( ? )Stack ENDSCode SEGMENTASSUME CS : Code , DS: Data , SS : StackMain PROC PUSH DS XOR AX, AX PUSH AX MOV AX, D
17、ata MOV DS, AX myOut PortControl, 80H ; 1 000 0 00 0B means : ; A - mode 0 , output ; B - mode 0 , output ; C High - output ; C Low - output animation : CALL ReadSwState TEST SwState , 02H JZ fast MOV CX, 0500H JMP viewfast : MOV CX, 0200Hview : CALL Show LOOP view CALL UpdateViewIndex JMP animation
18、 RET ; unreachable instructionMain ENDP; proc Show; input argument lists : POINTShow PROC PUSH BX PUSH CX PUSH SI MOV BX, POINT MOV CL, 01H ; initialize ; make CL = 00000001B , which means enable the right most digit MOV SI, 0 nextDigit : myOut PortB, CL ; select tubes PUSH CX MOV CL, BYTE PTR BX +
19、SI ; myOut PortA, CL ; select segments POP CX ROL CL, 1 ; display the left digit next to current one INC SI ; next letter CALL Delay CALL CheckAndQuit CMP SI, 6 JNZ nextDigit POP SI POP CX POP BX RETShow ENDPDelay PROC PUSH CX MOV CX, 2000HloopLabel: NOP LOOP loopLabel POP CX RETDelay ENDPcheckAndQu
20、it PROC PUSH AX MOV AH, 0BH ; check whether user input something from keyboard INT 21H OR AL, AL ; if he does, then return to Dos JZ exitCheckAndQuit myOut PortA , 00H myOut PortB , 00H MOV AX, 4C00H INT 21HexitCheckAndQuit : POP AX RETcheckAndQuit ENDPUpdateViewIndex PROC CALL ReadSwState TEST SwSt
21、ate, 01H JNZ stillMode INC POINT INC ViewIndex CMP ViewIndex, 7 JNZ exitUpdateViewIndex MOV POINT, OFFSET MESG MOV ViewIndex, 0 JMP exitUpdateViewIndex stillMode : MOV ViewIndex , 5 MOV POINT, OFFSET MESG ADD POINT, 5 exitUpdateViewIndex : RETUpdateViewIndex ENDPReadSwState PROC PUSH AX myIn PortSw,
22、 SwState POP AX RETReadSwState ENDPCode ENDSEND Main经过编译、连接、运行,可以正常运行。图 11 HELLO显示2.2.3. 回显小键盘输入检测行时,往控制口(0EE03H)写控制字88H,使C口(0EE02H)低八位(列)输出,高八位(行)输入。检测列时,往控制口(0EE03H)写控制字81H,使C口(0EE02H)高八位(行)输出,低八位(列)输入。首先,我利用debug,获得了每个按键对应的比特,制成了下表。根据下表,综合行值和列值,就可以知道按下了哪个键。表 3 检测到的二进制数与按钮值对应表测得键值*0111*1011*1101*1
23、1101110*01231101*45671011*89AB0111*CDEF在本程序中,设置了防抖动功能和防重复识别功能。当按下一个键后,一般情况下只会接收到一个值。但是,如果长按一个键,就会收到下一个值。这和普通PC键盘的体验相同,贴近广大用户的使用习惯。源代码:CODE (recur.asm); FILENAME : recur.asm; AUTHOR : XIAO, Zhiqing ( No. 13, Cl. 07105 ); DATE : 20091216; DESCRIPTION : display seven tubes array according to input; mac
24、ro : myOut ( WARNING : it may change the value of AL ); its strongly recommended that data be ALmyOut MACRO portAddr, data PUSH DX MOV DX, portAddr MOV AL, data OUT DX, AL POP DXENDM; macro : myDigitOut ( WARNING : it may change the value of AL ); its strongly recommended that data be ALmyDigitOut M
25、ACRO portAddr, data PUSH DX PUSH BX MOV BX , OFFSET SegLut MOV AL , data XLAT SegLut MOV DX, portAddr OUT DX, AL POP BX POP DXENDM ; macro : myIn ( WARNING : it may change the value of AL ); its strongly recommended that data be ALmyIn MACRO portAddr, data PUSH DX MOV DX, portAddr IN AL, DX MOV data
26、, AL POP DXENDM; macro : testAndSet ( WARNING : refNum and incNum should be INSTANT number )testAndSet MACRO srcData , refNum , incNum LOCAL exitTestAndSet TEST srcData , refNum JNZ exitTestAndSet OR buttonIndex , incNum OR buttonPressed , 0FFHexitTestAndSet: NOPENDMData SEGMENT; Segment Lookup Tabl
27、eSegLut DB 0EDH , 21H , 0F4H , 0F1H , 39H ; 01234 DB 0D9H , 0DDH , 61H , 0FDH , 0F9H ; 56789 DB 7DH , 9DH , 0CCH , 0B5H , 0DCH , 5CH ; ABCDEF DB 3DH , 8CH , 00H ; H ( 10H ) L ( 11H ) ( 12H ); Content index array to printContent DB 12H , 12H , 12H , 12H , 12H , 12H; 8255PortA EQU 0E800HPortB EQU 0E80
28、1HPortC EQU 0E802HPortControl EQU 0E803H; buttonPressed DB 0 ; 0FFH for pressed , 00H for not.buttonRow DB 0buttonCol DB 0buttonIndex DB 0buttonEnable DW 0000HData ENDSStack SEGMENT STACK STACK DB 100H DUP ( ? )Stack ENDSCode SEGMENTASSUME CS : Code , DS: Data , SS : StackMain PROC PUSH DS XOR AX, AX PUSH AX MOV AX, Data MOV DS, AX myOut PortControl, 80H ; 1 000 0 00 0B means : ; A - mode 0 , output ; B - mode 0 , output ; C High - o
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1