微机原理与接口技术实验报告综合实验红绿灯仿真及实现专业:电气工程及其自动化班级:电气1311学号:************ 姓名:龚玉辛预习报告成绩:实验成绩:实验日期及时间:(1)2016年5月20日(2)2016年5月26日(3)机位号:一实验一:在Proteus仿真实现交通信号灯系统。
(1)交通信号灯系统设计描述(实现内容)a)在DATAS 数据段内可以任意初始化红灯,绿灯,黄灯所要显示的秒数,实现通用化。
b)紧急情况下按下按钮,所有红灯亮,数显管全部显示0c)紧急情况解除后,恢复正常,用另一个按钮(8259中断)(2)P roteus中实现原理图所用元件:7SEG-BCD、74LS138、74LS373、8086、8253A、8255A、8259、BUTTON、LED-GREEN、LED-YELLOW、LED-RED.(3)源程序清单DATAS SEGMENThong DB 55lv dW 52huang db 2h,1h,0hz=$-huangzt1 db?zt2 db?ZT3 DB?DATAS ENDSSTACK SEGMENT'STACK'SUR1 DB 1000 DUP(?) STACK ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS START:MOV AX,DATASMOV DS,AXCLIPUSH DSmov al,80hmov dx,8006HOUT DX,ALMOV DX,0A006HMOV AL,00110001BOUT DX,ALMOV DX,0A000HMOV AL,00OUT DX,ALMOV AL,10OUT DX,ALMOV AX,0MOV DS,AXMOV DI,4*60HMOV AX,OFFSET NEXT2MOV [DI],AXMOV AX,SEG NEXT2MOV [DI+2],AXmov ax,0mov ds,axMOV DI,4*61HMOV AX,OFFSET NEXT1MOV [DI],AXMOV AX,SEG NEXT1MOV [DI+2],AXMOV AX,0MOV DS,AXMOV DI,4*62HMOV AX,OFFSET NEXTMOV [DI],AXMOV AX,SEG NEXTMOV [DI+2],AXPOP DSMOV DX,9000H ;icw1MOV AL,13HOUT DX,ALMOV AL,60HMOV DX,9002H ;icw2OUT DX,ALMOV AL,00010001B ;icw4OUT DX,ALMOV AL,00000000BOUT DX,AL ; ocw 8259初始化默认 STIagain:mov dx,8000hmov al,00100001bmov zt1,alout dx,alMOV CL,HONGMOV BP,LVAGAIN2:MOV AL,CLMOV AH,0MOV DL,10DIV DLMOV CH,AHMOV DH,16MUL DHADD AL,CHmov dx,8002hout dx,alMOV AL,CLSUB AL,3MOV AH,0MOV DL,10DIV DLMOV CH,AHMOV DH,16MUL DHADD AL,CHMOV DX,8004HOUT DX,ALDEC CLMOV ZT3,0MOV DX,0A006HMOV AL,00110001BOUT DX,ALMOV DX,0A000HMOV AL,00OUT DX,ALMOV AL,10OUT DX,ALagain3:NOPCMP ZT3,0JZ AGAIN3 ;yan 1s DEC BPjnz AGAIN2mov dx,8000hmov al,00010001bmov zt1,alout dx,alMOV SI,OFFSET HUANGMOV BH,ZAGAIN4:MOV AL,[SI]mov dx,8002hout dx,alMOV DX,8004HMOV DX,0A006HMOV AL,00110001BOUT DX,ALMOV DX,0A000H ;计数初值MOV AL,00OUT DX,ALMOV AL,10OUT DX,ALmov ZT3,0again5:NOPCMP ZT3,0JZ AGAIN5INC SIDEC BHJNZ AGAIN4mov dx,8000hmov al,00001100bmov zt1,alout dx,alMOV CL,HONGMOV BP,LVAGAIN6:MOV AL,CLMOV AH,0MOV DL,10DIV DLMOV CH,AHMOV DH,16MUL DHADD AL,CHmov dx,8004hout dx,alMOV AL,CLSUB AL,3MOV AH,0MOV DL,10DIV DLMOV DH,16MUL DHADD AL,CHMOV DX,8002HOUT DX,ALDEC CLMOV DX,0A006HMOV AL,00110001BOUT DX,ALMOV DX,0A000H ;计数初值MOV AL,00OUT DX,ALMOV AL,10OUT DX,ALmov ZT3,0again7:NOPCMP ZT3,0JZ AGAIN7 ;yan 1s DEC BPjnz AGAIN6mov dx,8000hmov al,00001010bmov zt1,alout dx,alMOV SI,OFFSET HUANGMOV BH,ZAGAIN8:MOV AL,[SI]mov dx,8002hout dx,alMOV DX,8004HOUT DX,ALMOV DX,0A006HMOV AL,00110001BOUT DX,ALMOV DX,0A000H ;计数初值MOV AL,00OUT DX,ALOUT DX,ALmov ZT3,0again9:NOPCMP ZT3,0 JZ AGAIN9INC SIDEC BHJNZ AGAIN8jmp againNEXT PROC FARPUSH CXPUSH DSpush AXpush dxpush bppush bxPUSH SIPUSH DIPUSHFMOV DX,8000HMOV AL,00001001BOUT DX,ALMOV AL,0MOV DX,8002HOUT DX,ALMOV DX,8004hOUT DX,AXSTImov zt2,0aa1:cmp zt2,0JE AA1MOV AL,20HMOV DX,9000HOUT DX,ALCLIpopfPOP DIPOP SIpop BXpop BPpop DXpop AXPOP DSPOP CXmov dx,8000hmov al,zt1out dx,alIRETNEXT ENDPNEXT1 PROC FAR PUSH DSPUSHFinc zt2MOV AL,20HMOV DX,9000HOUT DX,ALpopfPOP DSIRETNEXT1 ENDPinc zt3MOV AL,20HMOV DX,9000HOUT DX,ALpopfPOP DSSTIIRETNEXT2 ENDPENDLESS:JMP ENDLESSCODES ENDSEND STARTNEXT2 PROC FAR PUSH DSPUSHFinc zt3MOV AL,20HMOV DX,9000HOUT DX,ALpopfPOP DSSTIIRETNEXT2 ENDPENDLESS:JMP ENDLESSCODES ENDSEND START(4)实验结果及描述:1)开始仿真前,改动源程序初始化数据段中hong,lv,huang,的数字,便可以设定计时的时间(所记录数字即为设定时间)。
按照本人程序设定红灯55s,绿灯52s,黄灯3s,红绿黄灯不断循环计数2)按动IR2,所有红灯亮起,数显管全部为0,按动IR1返回至之前按动IR2中断前的状态。
(5)仿真遇到的问题及解决方法:1)进出堆栈段遵从先进后出,后进先出的原则,否则一定混乱。
2)为防止中断错误,将计时8253产生的每秒中断至于IR0,优先级IR0>IR1>IR23)程序数显的通用化,为操作方便,采用了BCD数显管,并加以循环计数,利用10进制到16进制的转化,实现了轻松设置数据段3个数字,即可控制红绿黄灯计时秒数。
二实验二:在实验室实验箱上仿真实现交通信号灯系统。
(1)交通信号灯系统设计描述(实验内容)用发光二极管模拟交通信号灯,尽量完成仿真中实现的功能。
(2)实验接线图(3)实验程序清单DA TAS SEGMENTA8253 EQU 06c0H; 0#计数器的端口地址B8253 EQU 06c2HC8253 EQU 06C4HJ8253 EQU 06C6H; 控制寄存器端口地址A8255 EQU 0640H; 8255端口A地址B8255 EQU 0642HC8255 EQU 0644HK8255 EQU 0646H; 控制端口地址DA TAS ENDSSTACKS SEGMENTSTACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DA TAS,SS:STACKS START:;中断向量表初始化PUSH DSMOV AX,0000HMOV DS,AXMOV AX,OFFSET BREAKMOV SI,003CHMOV [SI],AXMOV AX,SEG BREAKMOV SI,003EHMOV [SI],AXCLIPOP DS;初始化8259MOV AL,19HOUT 20H,ALMOV AL,08HOUT 21H,ALMOV AL,04HOUT 21H,ALMOV AL,01HOUT 21H,ALMOV AL,7FHOUT 21H,ALSTI;初始化8253MOV DX,J8253;写计数器0号方式字MOV AL,00110001B;使用计数器0 ,方式0 ,BCD计数OUT DX,ALMOV DX,J8253MOV AL,01110111BOUT DX,ALMOV DX,B8253MOV AX,1000HOUT DX,ALMOV AL,AHOUT DX,AL;初始化8259MOV DX, K8255MOV AL, 10001001B; 方式0,A输出,C输入OUT DX, ALAGAIN:MOV DX,A8255MOV AL,00100001B;南北绿灯东西红灯30sOUT DX,ALMOV DX,A8253;给计数器0赋初值MOV AX,3000H;OUT DX,ALMOV AL,AHOUT DX,ALAGAIN1:MOV AL,0MOV DX,C8255IN AL,DXAND AL,00000001BCMP AL,1BJNZ AGAIN1MOV DX,A8255MOV AL,00010001B;南北黄灯东西红灯5sOUT DX,ALMOV DX,A8253;给计数器0号赋初值MOV AX,500H;OUT DX,ALMOV AL,AHOUT DX,ALAGAIN2:MOV AL,0MOV DX,C8255IN AL,DXAND AL,00000001BCMP AL,1HJNZ AGAIN2附件2DA TAS SEGMENTA8253 EQU 06c0H; 0#计数器的端口地址B8253 EQU 06c2HC8253 EQU 06C4HJ8253 EQU 06C6H; 控制寄存器端口地址A8255 EQU 0640H; 8255端口A地址B8255 EQU 0642HC8255 EQU 0644HK8255 EQU 0646H; 控制端口地址DA TAS ENDSSTACKS SEGMENTSTACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DA TAS,SS:STACKS;中断向量表初始化PUSH DSMOV AX,0000HMOV DS,AXMOV AX,OFFSET BREAKMOV SI,003CHMOV [SI],AXMOV AX,SEG BREAKMOV SI,003EHMOV [SI],AXCLIPOP DS;初始化8259MOV AL,19HOUT 20H,ALMOV AL,08HOUT 21H,ALMOV AL,04HOUT 21H,ALMOV AL,01HOUT 21H,ALMOV AL,7FHOUT 21H,ALSTI;初始化8253MOV DX,J8253;写计数器0号方式字MOV AL,00110001B;使用计数器0 ,方式0 ,BCD计数OUT DX,ALMOV DX,J8253MOV AL,01110111BOUT DX,ALMOV DX,B8253MOV AX,1000HOUT DX,ALMOV AL,AHOUT DX,AL;初始化8259MOV DX, K8255MOV AL, 10001001B; 方式0,A输出,C输入OUT DX, ALAGAIN:MOV DX,A8255MOV AL,00100001B;南北绿灯东西红灯30sOUT DX,ALMOV DX,A8253;给计数器0赋初值MOV AX,3000H;OUT DX,ALMOV AL,AHOUT DX,ALAGAIN1:MOV AL,0MOV DX,C8255IN AL,DXAND AL,00000001BCMP AL,1BJNZ AGAIN1MOV DX,A8255MOV AL,00010001B;南北黄灯东西红灯5sOUT DX,ALMOV DX,A8253;给计数器0号赋初值MOV AX,500H;OUT DX,ALMOV AL,AHOUT DX,ALAGAIN2:MOV AL,0MOV DX,C8255IN AL,DXAND AL,00000001BMOV DX,A8255MOV AL,00001100B;南北红灯东西绿灯30s OUT DX,ALMOV DX,A8253;给计数器0赋初值MOV AX,3000H;OUT DX,ALMOV AL,AHOUT DX,ALAGAIN3:MOV AL,0MOV DX,C8255IN AL,DXAND AL,00000001BCMP AL,1BJNZ AGAIN3MOV DX,A8255MOV AL,00001010B;南北红灯东西黄灯5sOUT DX,ALMOV DX,A8253;给计数器0赋初值MOV AX,500H;OUT DX,ALMOV AL,AHOUT DX,ALAGAIN4:MOV AL,0MOV DX,C8255IN AL,DXAND AL,00000001BCMP AL,1HJNZ AGAIN4JMP AGAIN;中断服务程序BREAK:PUSH DXPUSH AXMOV DX,A8255MOV AL,00001001BOUT DX,ALMOV AL,20HOUT 20H,ALPOP AXPOP DXSTIIRETCODES ENDSEND START(4)实验操作及实验结果描述a)由于没有BCD 灯管,无法完成数字显示功能,在原有程序的基础上,改动8253,8255,8259的初始化地址为实现箱的默认地址,按照仿真中的元件,以及之前做实验的经验连线即可。