交通灯控制模拟程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
交通灯控制模拟程序设计
;*************定义数据段***********************************************
data segment
title1 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 ends
code segment
assume cs:code,ds:data,es:data
start:mov ax,data
mov ds,ax
mov es,ax
call title2 ;初始化标题
q0: call mode1 ;模式选择自动或手动
call scanf
call atuo ; 默认设置参数启动
lea si,ans
cmp byte ptr[si],'y'
jz q1
cmp byte ptr[si],'n'
jnz q0
call ask1 ;设置红灯时间
call scanf0
call ask2 ;设置黄灯时间
q1: call init1 ; 初始化灯光
call init2
lea si,buff;复制数据buff-buff1,保存显示时间
inc si
inc si
lea di,buff1
cld
mov cx,3
REP movsb
lea si,buff1;复制数据buff1-buff2,保存显示时间
lea di,buff2
cld
mov cx,3
REP movsb
;********************子程序设计************************************** ;*******状态一:南北方向红灯,东西方向绿灯***************************** start1:lea si,buff2 ;复制数据buff2-buff1,保存显示时间
lea di,buff1
cld
mov cx,3
REP movsb
lea di,buff1
a0: cmp byte ptr[di+2],30h ;数据处理部分
ja a1
add byte ptr[di+2],10
sub byte ptr[di+1],1
a1: sub byte ptr[di+2],1
cmp byte ptr[di+1],30h
jnc a2
add byte ptr[di+1],10
sub byte ptr[di],1
a2: cmp byte ptr[di],30h
jnc a3
jmp start2 ; 换灯
a3: call nr
call write0
lea si,yellow
mov al,[si]
cmp byte ptr[di+2],al ;最后五秒绿灯变黄灯
jna a4
jmp a8
a4: cmp byte ptr[di+1],30h
jna a5
jmp a8
a5: cmp byte ptr[di],30h
ja a8
call ey
jmp a9
a8: call eg
a9: call delay ;延时一秒左右
jmp a0
;********状态二:南北方向绿灯,东西方向红灯**************************** start2:lea si,buff2 ;复制数据buff2-buff1,保存显示时间
lea di,buff1
cld
mov cx,3
REP movsb
lea di,buff1
b0: cmp byte ptr[di+2],30h ;数据处理部分
ja b1
add byte ptr[di+2],10
sub byte ptr[di+1],1
b1: sub byte ptr[di+2],1
cmp byte ptr[di+1],30h
jnc b2
add byte ptr[di+1],10
sub byte ptr[di],1
b2: cmp byte ptr[di],30h
jnc b3
jmp start1 ; 换灯
b3: call er
call write0