当前位置:文档之家› 交通灯控制模拟程序

交通灯控制模拟程序

交通灯控制模拟程序设计data segment title1 db 'Traffic-System' deng db '# # #' sing1 db'South-North' sing2 db 'East - West' sing3 db 'Redtime(scend):' time db 'Time:' sing4 db 'Yellowtime(scend):' buff db 4 ;键盘缓冲区 buff1 db 3dup(?) ;工作计数区 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'・************************ Jdata ends code segmentassume cs:code,ds:data,es:data start:mov ax,datamov ds,ax mov es,ax call title2 ; 初始化标题 q0: call mode1 ; 模式选择 自动或手动 call scanf call atuo ;默认设置参数启动 lea si,anscmp byte ptr[si],'y'jz q1cmp byte ptr[si],'n'jnz q0call ask1 ;设置红灯时间call scanf0 call ask2 ;设置黄灯时间・*************定义数据段 ***********************************************主程序段 **********************************************call scanf1q1: 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 movsbclda3: call nrcall write0子程序设计 ************************************** 状态一 :南北方向红灯,东西方向绿灯 ***************************** start1:lea si,buff2 ; 复制数据 buff2-buff1 ,保存显示时间 di,buff1・******************** ・******* leaa0: a1: a2: mov REP cx,3movsblea di,buff1cmp byte ptr[di+2],30h ; 数据处理部分ja a1add byte ptr[di+2],10sub byte ptr[di+1],1sub byte ptr[di+2],1cmp byte ptr[di+1],30hjnc a2add byte ptr[di+1],10sub byte ptr[di],1cmp byte ptr[di],30hjnc a3jmp start2 ; 换灯lea si,yellowmov al,[si]cmp byte ptr[di+2],al ;最后五秒绿灯变黄灯jna a4jmp a8a4: cmp byte ptr[di+1],30h jna a5 jmp a8a5: cmp byte ptr[di],30h ja a8 call ey jmp a9a8: call ega9: call delay ; 延时一秒左右jmp a0******** 状态二 :南北方向绿灯,东西方向红灯; 复制数据 buff2-buff1 ,保存显示时间 lea di,buff1 cldmov cx,3 REP movsb lea di,buff1b0: cmp byte ptr[di+2],30h;数据处理部分 ja b1 add byte ptr[di+2],10 sub byte ptr[di+1],1b1: sub byte ptr[di+2],1 cmp byte ptr[di+1],30h jnc b2 add byte ptr[di+1],10 sub byte ptr[di],1b2: cmp byte ptr[di],30h jnc b3 jmp start1 ; 换灯b3:call er call write0**************************** start2:lea si,buff2lea 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,mode mov dh,5mov dl,2 mov al,1 mov bl,07h mov ah,13h int 10hret mode1 endp title2 proc・**********标题***************mov cx,14 ; 设置时间lea bp,title1 mov dh,1mov dl,25mov al,1 mov bl,07h mov ah,13h int 10h ret title2endpask1 proc mov cx,16;设置时间 lea bp,sing3 mov dh,9 mov dl,2mov al,1 mov bl,06h movah,13h int 10h retask1 endpask2 procmov cx,19 ;设置时间 leabp,sing4 mov dh,13 mov dl,25mov al,1 mov bl,06h movah,13h int 10hret ask2 endp・*********** J键盘输入设置 *******scanf:mov ah,01h int 21hlea si,ans mov [si],al ret ・***********J 键盘 0 输入设置****** scanf0:lea dx,buffmov ah,0ahint 21h ret・********* J 键盘 1 输入设置scanf1:mov ah,01h int 21hlea si,yellow mov [si],al ret init1:mov cx,11 ;设置标题南北・******* 交互界面时间设置 1*******・*********交互界面时间设置 ******・************* 南北灯的初始化 *****lea bp,sing1 mov dh,7 movdl,30 mov al,0 mov bl,07h movah,13h int 10h ret;*********** 东西方向的初始化****init2:mov cx,11 ;设置标题东西lea bp,sing2 mov dh,11 movdl,30 mov al,0 mov bl,07h movah,13h int 10hret・********* 南北方向交通灯函数***************************************** ng: mov cx,7 leabp,deng movdh,7mov dl,47mov al,0mov bl,02h ; 设置颜色绿色mov ah,13hint 10hretny: mov cx,7mov dh,7 lea bp,deng movdl,47 mov al,0mov bl,0eh ; 设置颜色黄色mov ah,13h int 10hretnr: mov cx,7 mov dh,7 lea bp,dengmov dl,47 mov al,0mov bl,04h ; 设置颜色 红色mov ah,13hint 10hretmov dh,11mov dl,47 mov al,0mov bl,02h ; 设置颜色 绿色mov ah,13hint 10hretey: mov cx,7mov dh,11 lea bp,deng movdl,47 mov al,0mov bl,0eh ; 设置颜色 黄色mov ah,13h int 10hreter: mov cx,7 mov dh,11 lea bp,dengmov dl,47 mov al,0mov bl,04h ; 设置颜色 红色mov ah,13h int 10h retwrite0:mov cx,3 lea bp,buff1 mov dh,7 mov dl,60 mov al,1 mov bl,04h mov ah,13h int 10h ret・*****************时间显示函数 **********************************东西方向交通灯函数 *****************************************eg: mov cx,7 lea bp,deng・********write1:mov cx,3 lea bp,buff1 mov dh,11 mov dl,60 mov al,1mov bl,04h mov ah,13h int 10hret・************* 默认设置红灯30 秒,黄灯5秒************************** atuo: mov cx,19 ;红灯默认时间30 秒lea bp,ting3 mov dh,9 mov dl,2 mov al,1 mov bl,07h movah,13h int 10hmov cx,20 ;黄灯默认时间 5 秒lea bp,ting4mov dh,13mov dl,2 mov al,1 mov bl,07h mov ah,13h int 10h lea si,buffmov byte ptr[si+2],30h mov byte ptr[si+3],33h mov byteptr[si+4],30h lea si, yellowmov byte ptr[si],35h ret・ *****************J延时函数delay:mov dx,25000 l1: mov cx,30000 l2: loop l2 dec dx jnz l1 ret code endsend start。

相关主题