标题: 单片机汇编语言红绿灯程序 [打印本页]

作者: 1909788766    时间: 2024-6-25 17:53
标题: 单片机汇编语言红绿灯程序
name "traffic"
menu_text db ' input:', 0Dh, 0Ah
          db '1.normal', 0Dh, 0Ah
          db '2.accident', 0Dh, 0Ah
          db '3.construction', 0Dh, 0Ah
          db '4.malfunction', 0Dh, 0Ah
          db '5.exit', 0Dh, 0Ah
          db '$'
menu:
    mov ah, 09h
    lea dx, menu_text
    int 21h
    ; 获取用户输入
    mov ah, 01h
    int 21h
    ; 根据用户输入执行相应操作
    cmp al, '1'
    je normal_traffic
    cmp al, '2'
    je road_accident
    cmp al, '3'
    je road_construction
    cmp al, '4'
    je signal_fault
    cmp al, '5'
    je exit_program
    jmp menu

normal_traffic:
mov ax, all_red
out 4, ax
mov si, offset situation
mov ah, 9
lea dx, msg1
int 21h
first:
mov ax, [si]
out 4, ax
; wait 5 seconds (5 million microseconds)
mov     cx, 4Ch    ;    004C4B40h = 5,000,000
mov     dx, 4B40h
mov     ah, 86h
int     15h
add si, 2 ; next situation
cmp si, sit_end
jb  first
mov si, offset situation
jmp menu
situation        dw      0000_0011_0000_1100b
s1               dw      0000_0110_1001_1010b
s2               dw      0000_1000_0110_0001b
s3               dw      0000_1000_0110_0001b
s4               dw      0000_0100_1101_0011b
sit_end = $
road_accident:
mov ax, all_red
out 4, ax
mov si, offset situation2
mov ah, 9
lea dx, msg2
int 21h
second:
mov ax, [si]
out 4, ax
; wait 5 seconds (5 million microseconds)
mov     cx, 4Ch    ;    004C4B40h = 5,000,000
mov     dx, 4B40h
mov     ah, 86h
int     15h
add si, 2 ; next situation
cmp si, sit_end1
jb  second
mov si, offset situation2
jmp menu
situation2       dw       0000_0011_0000_1100b
s5               dw       0000_0110_1000_1010b
s6               dw       0000_1000_0100_1001b
s7               dw       0000_1000_0100_1001b
s8               dw       0000_0100_1100_1001b
sit_end1 = $
road_construction:
mov ax, all_red
out 4, ax
mov si, offset situation3
mov ah, 9
lea dx, msg3
int 21h
thrid:
mov ax, [si]
out 4, ax
; wait 5 seconds (5 million microseconds)
mov     cx, 4Ch    ;    004C4B40h = 5,000,000
mov     dx, 4B40h
mov     ah, 86h
int     15h
add si, 2 ; next situation
cmp si, sit_end3
jb  thrid
mov si, offset situation3
jmp menu
situation3      dw      0000_0011_0000_1001b
s10             dw      0000_0110_1001_1001b
s11             dw      0000_1000_0110_0001b
s12             dw      0000_1000_0110_0001b
s13             dw      0000_0100_1101_0001b            
sit_end3 = $
signal_fault:
mov ax, all_red
out 4,ax
mov ah, 9
lea dx, msg4
int 21h
jmp menu
exit_program:
mov ah, 9
lea dx, msg5
int 21h   
mov ax, 4C00h
int





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1