交通灯控制模拟程序设计;*************定义数据段***********************************************data segmenttitle1 db 'Traffic-System'deng db '# # #'sing1 db 'South-North'sing2 db 'East - West'sing3 db 'Red time(scend):'time db 'Time:'sing4 db 'Yellow time(scend):'buff db 4 ;键盘缓冲区buff1 db 3 dup(?) ;工作计数区buff2 db 3 dup(?) ;数据保存区yellow db ? ;黄灯时间mode db 'Mode:auto(Y/N)?:'ans db ?ting3 db 'Red time(scend):030'ting4 db 'Yellow time(scend):5';************************主程序段********************************************** data endscode segmentassume cs:code,ds:data,es:datastart:mov ax,datamov ds,axmov es,axcall title2 ;初始化标题q0: call mode1 ;模式选择自动或手动call scanfcall atuo ; 默认设置参数启动lea si,anscmp byte ptr[si],'y'jz q1cmp byte ptr[si],'n'jnz q0call ask1 ;设置红灯时间call scanf0call ask2 ;设置黄灯时间q1: call init1 ; 初始化灯光call init2lea si,buff;复制数据buff-buff1,保存显示时间inc siinc silea di,buff1cldmov cx,3REP movsblea si,buff1;复制数据buff1-buff2,保存显示时间lea di,buff2cldmov cx,3REP movsb;********************子程序设计************************************** ;*******状态一:南北方向红灯,东西方向绿灯***************************** start1:lea si,buff2 ;复制数据buff2-buff1,保存显示时间lea di,buff1cldmov cx,3REP movsblea di,buff1a0: cmp byte ptr[di+2],30h ;数据处理部分ja a1add byte ptr[di+2],10sub byte ptr[di+1],1a1: sub byte ptr[di+2],1cmp byte ptr[di+1],30hjnc a2add byte ptr[di+1],10sub byte ptr[di],1a2: cmp byte ptr[di],30hjnc a3jmp start2 ; 换灯a3: call nrcall write0lea si,yellowmov al,[si]cmp byte ptr[di+2],al ;最后五秒绿灯变黄灯jna a4jmp a8a4: cmp byte ptr[di+1],30hjna a5jmp a8a5: cmp byte ptr[di],30hja a8call eyjmp a9a8: call ega9: call delay ;延时一秒左右jmp a0;********状态二:南北方向绿灯,东西方向红灯**************************** start2:lea si,buff2 ;复制数据buff2-buff1,保存显示时间lea di,buff1cldmov cx,3REP movsblea di,buff1b0: cmp byte ptr[di+2],30h ;数据处理部分ja b1add byte ptr[di+2],10sub byte ptr[di+1],1b1: sub byte ptr[di+2],1cmp byte ptr[di+1],30hjnc b2add byte ptr[di+1],10sub byte ptr[di],1b2: cmp byte ptr[di],30hjnc b3jmp start1 ; 换灯b3: call ercall write0lea si,yellowmov al,[si]cmp byte ptr[di+2],al ;最后五秒绿灯变黄灯jna b4jmp b8b4: cmp byte ptr[di+1],30hjna b5jmp b8b5: cmp byte ptr[di],30hja b8call nyjmp b9b8: call ngb9: call delay ;延时一秒左右jmp b0;******模式设置***************mode1 procmov cx,16 ;设置时间lea bp,modemov dh,5mov dl,2mov al,1mov bl,07hmov ah,13hint 10hretmode1 endp;**********标题***************title2 procmov cx,14 ;设置时间lea bp,title1mov dh,1mov dl,25mov al,1mov bl,07hmov ah,13hint 10hrettitle2 endp;*******交互界面时间设置1******* ask1 procmov cx,16 ;设置时间lea bp,sing3mov dh,9mov dl,2mov al,1mov bl,06hmov ah,13hint 10hretask1 endp;*********交互界面时间设置2****** ask2 procmov cx,19 ;设置时间lea bp,sing4mov dh,13mov dl,25mov al,1mov bl,06hmov ah,13hint 10hretask2 endp;***********键盘输入设置******* scanf:mov ah,01hint 21hlea si,ansmov [si],alret;***********键盘0输入设置****** scanf0:lea dx,buffmov ah,0ahint 21hret;*********键盘1输入设置******* scanf1:mov ah,01hint 21hlea si,yellowmov [si],alret;*************南北灯的初始化***** init1:mov cx,11 ;设置标题南北lea bp,sing1mov dh,7mov dl,30mov al,0mov bl,07hmov ah,13hint 10hret;***********东西方向的初始化****init2:mov cx,11 ;设置标题东西lea bp,sing2mov dh,11mov dl,30mov al,0mov bl,07hmov ah,13hint 10hret;*********南北方向交通灯函数***************************************** ng: mov cx,7lea bp,dengmov dh,7mov dl,47mov al,0mov bl,02h ;设置颜色绿色mov ah,13hint 10hretny: mov cx,7mov dh,7lea bp,dengmov dl,47mov al,0mov bl,0eh ;设置颜色黄色mov ah,13hint 10hretnr: mov cx,7mov dh,7lea bp,dengmov dl,47mov al,0mov bl,04h ;设置颜色红色mov ah,13hint 10hret;********东西方向交通灯函数***************************************** eg: mov cx,7lea bp,dengmov dh,11mov dl,47mov al,0mov bl,02h ;设置颜色绿色mov ah,13hint 10hretey: mov cx,7mov dh,11lea bp,dengmov dl,47mov al,0mov bl,0eh ;设置颜色黄色mov ah,13hint 10hreter: mov cx,7mov dh,11lea bp,dengmov dl,47mov al,0mov bl,04h ;设置颜色红色mov ah,13hint 10hret;*****************时间显示函数********************************** write0:mov cx,3lea bp,buff1mov dh,7mov dl,60mov al,1mov bl,04hmov ah,13hint 10hretwrite1:mov cx,3lea bp,buff1mov dh,11mov dl,60mov al,1mov bl,04hmov ah,13hint 10hret;*************默认设置红灯30秒,黄灯5秒************************** atuo: mov cx,19 ;红灯默认时间30秒lea bp,ting3mov dh,9mov dl,2mov al,1mov bl,07hmov ah,13hint 10hmov cx,20 ;黄灯默认时间5秒lea bp,ting4mov dh,13mov dl,2mov al,1mov bl,07hmov ah,13hint 10hlea si,buffmov byte ptr[si+2],30hmov byte ptr[si+3],33hmov byte ptr[si+4],30hlea si, yellowmov byte ptr[si],35hret;*****************延时函数*************************************** delay:mov dx,25000l1: mov cx,30000l2: loop l2dec dxjnz l1retcode endsend start。