《微机原理综合实验.docx》由会员分享,可在线阅读,更多相关《微机原理综合实验.docx(26页珍藏版)》请在第一文库网上搜索。
1、inc1udeio.ic.mode1sma11.stack.dataIedtbbyte3fh,06h,05bh,04fh,66h,6dh,7dh,07h,7fh,6fh1edtb_nbyte6dh,73h,38h;S,P,11etsbyte24h,44h,81h,82htimerword5timer1word40jtimer*tirer1=200表示一秒钟timer_nword400;夜间模式timer*timer_n/400秒timer_eword800;紧急模式timer*timer_e/800秒tramWord0;用于跳转tram1word0;用于判定四个状态cdbyte0;用于显示倒计
2、时tenbyte10;Itenbyte0;十位数remainderbyte0;余数1ten_rbyte0;右数码管状态红灯的十位数remainderbyte0;13状态红灯的余数.codestart:movax,datamovds,a;计数器定时准备,每一秒out1输出一次QUt1接线iRQmova1,36h;设置计数器0、先写低字节,后写高字节,工作方式3,二进制计数movdxt283houtdx,a1movdxt280h;设置计数初值movax,1000outd,a1mova1,ahoutdx,a1mova1,76h;设置通道0、1为工作方式3,二进制计数movdx1283hmovdx,2
3、81h;设置计数初值movax,1000outdx,a1mova11ahoutdx,a1movax,350Bhint21hpushespushb;设置新的OBh中断向量表项c1i;关中断pushdsmovax1segnewOBhmovds,axmovdx,offsetnewOBhmova,250Bhit21hpopds;对72h中断向量进行保护movax,3572hint21hpushespushbx;设置新的72h中断向量表项C1i;关中断pushdsmovax,segnew72hmovds,axmovdx,offsetew72hmova,2572hint21hpopds;对72h中断向量进
4、行保护mova,350fhpushespushbx设置新的72h中断向量表项c1i;关中断pushdsmova1segnewfhmovds,axmovdx,offsetnewfhmovax,250fhint21hpopds;允许IRQ3中断ina1,21h;读出IMRpushax;保存原IMR内容anda1,0f7h;允许IRQ3,其他内容不变,即置IRQ3为0out21h,a1;设置新IMR内容;允许IRQIO中断ina1,OA1h读出IMRpushax;保存原IMR内容anda1,Ofbh;允许IRQ10,其他内容不变,即置IRQ1o为OoutOA1h,a1;设置新IMR内容;允许IRQ7
5、中断ina1,21h;读出IMRpushax;保存原IMR内容anda1,07fh;允许IRQ7,其他内容不变,即置IRQ7为Oout21h1a1;设置新IMR内容Sti;开中断;主程序完成中断服务程序设置,开始处理其他事务;设置A端口方式0,输出288,289,28a,28bmovdt28bHmova1,10000000baaa:;普通模式,30秒红绿灯,5秒红黄灯movbx,0movcx,4Pa负责显示数码管,地址为288mova1,1etsbmovdx1288Houtdx,a1incbxmovtram,cmovtram1fcshrtram,1jnc12ca11de1ay5潢绿灯jmp13
6、ca11de1ay30;红绿灯1oopI1JmPaaac1i;关中断popax;恢复IMRout21h,a1popdx;恢复原中断向量表项popdsmovax,250Bhint21hsti;开中断;new7号中断服务程序;夜间模式newOBhprocsti;开中断pushaxpushsipushdspushdxpushbxpushexmovax,data;外部随机产生中断,DS也不确定,所以必须设置DSmovds,ax;写入端口控制字movdx,28bHmova1,10000000boutd,a11;黄灯movdx,288hmova1,01000010boutd,a1;数码管显示;1movcx
7、,timer_n1ow_Spead:mova1,IO1Oboutdx,a1;控制显示的内容xorbx,bxmova1,1edtb_nbx+2movdx,289houtdx,a1ca11de1aymovdx,28ahmova1,O1O1boutd,a1;控制显示的内容orbx,bmova1,1edtb-bxmovdxt289houtd,a1ca11de1ay1oop1ow_Spead;让交通灯回复原状态movbx,4subb,tram1mova1,1etsbxmovdx,288Houtdx,a1mova1,20h;发送EOI命令out20h,a1popexpopbxpopdxpopdspopsi
8、popaxiret;中断返回newOBhendp;紧急模式ew72hprocsti;开中断pushaxpushsipushdspushdxpushbxpushexmovax,()data;外部随机产生中断,DS也不确定,所以必须设置DSmovds,ax;写入端口控制字movdx,28bHmova1,10000000boutdx,a1movd,288hmova1,10000001boutdx,a1;控制哪个数码管的movdx,28ahmova1,0100boutdx,a1;控制显示的内容xorbx,bxmova1,1edtb_nbxmovdx1289houtdx,a1movcx,timer_es
9、top:ca11de1ay1oopstop;让交通灯回复原状态subbx1tram1mova1,1etsbxmovdx,288Houtdx,a1mova1,20h泼送EOI命令outOaOh1a1;写入从片EOI命令out20h,a1;写入主片EOI命令popCXpopbpopdpopdspopsipopaxiret;中断返回new72hendpewfhprocstipushaxpushsipushdsmovax.()data;外部随机产生中断,DS也不确定,所以必须设置DSmovds,axdeccdmova1,20h;发送EOI命令out20h,a1popdspopsipopaxiret;中
10、断返回newfhendp;30秒的延迟及数码管计时de1ay30procpushexmovcd,30d1:xorcx,cxmovc1,cdca11de1ay11oopd1popexretde1ay30edpde1ay5procpushcmovcd,5d2:xorcx,cxmovc1,cdca11de1ay11oopd2retde1ay5endp;一秒的延迟,同时显示到数码管Wam=I的时候右红灯,O表示左红灯de1ay1procpushexpushaxpushdxpushbx;tram1=4:左绿右红tram1=3:左黄右红;tram1=2:左红右绿:tram1=1:左红右黄xorax,axc
11、mptram1,4jzS4;4状态cmptram1t2jzS2;2状态;3状态和1状态mova1,cd;得到倒计时divtenmov1te,a1movremainder1ahmov1ten_r,a1movremainder.rtahjmpS_end;4状态:左绿右红S4:xoraxtamova1,cddivtenmov1te,a1movremainder1ahxorax,axmova1,cdadda1,5divtenmov1ten_r,a1movreraider-r,ahjmpS_endS2:;2状态:左红右绿xoraxtaxadda1,5divtenmov1te,a1movremainder
12、,ahxorax,axmova1,cddivtenmov1ten_r,a1movremainder_r,ahjmpS_endS_end:;状态准备工作完成movex,timer1;输入循环的次数;显示4号数码管;控制哪个数码管movdx,28ahmova1,08hmovb1,1ten;控制显示的内容mova1,1edtbbxmovdxt289houtdx,a1ca11de1ay;显示3号数码管;控制哪个数码管movdx,28ahmova1,04houtdx,a1movb1,remainder;控制显示的内容mova1,1edtbbxmovdxt289houtdx,a1ca11de1ay;显示2
13、号管movdx,28ahmova1,02houtd,a1movb1,1ten_r;控制显示的内容mova1,1edtbbxmovdx,289houtdx,a1ca11de1ay;显示1号管movdx,28ahmova1,O1houtdx,a1movb1,remainder_r;控制显示的内容mova1,1edtbbxmovdxt289houtdx,a1ca11de1ay1oop111popbxpopaxpopexretde1ay1endp;刷新的延迟de1ayprocpushbxpushexpushaxmovbx1tinerrepeat1:xorcx,cxrepeat2:1ooprepeat2decbjnzrepeat1popaxpopbxretde1ayendpde1ay1procpushbxpushexpushaxmovbxttimerrepeat1_10:xorcx,cxrepeat2_10:1ooprepeat2decbxjzrepeat1popaxpopexpopbxretde1ay1endp.exitOendstart