微机原理 交通灯实验源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
LCD EQU 07FE0H
LCDWI EQU LCD+0
LCDWD EQU LCD+1
LCDRS EQU LCD+2
LCDRD EQU LCD+3
TIM_CTL EQU 7FE7H
TIMER0 EQU 7FE4H
TIMER1 EQU 7FE5H
MODE02 EQU 00110100B
Port0 EQU 7FE8H
Port1 EQU 7FE9H
PA EQU 0FFD8H
PB EQU 0FFD9H
PC EQU 0FFDAH
PCTL EQU 0FFDBH
code segment
assume cs:code
org 1000h
lin db 0
col db 0
num db 0
dis_num db 0
temp0 db 0
temp1 db 0
count db 0
IRQ_num db 0
IRQ_count db 0
START:mov al,02h
call init_lcd
call send_com
call delay
mov lin,1
mov col,1
mov al,0FH
mov count,al
mov al,count
mov dis_num,al
call dis_number
call cs_led
call delay2
; mov bx,offset LCDTAB1
;mov lin,0
;mov col,1
;mov num,5
; call dis_english
lgs1: mov al,count
mov dis_num,al
call dis_number
call red_led
call delay3
call init_8259
call D8253
mov al,count
cmp al,0
jnz lgs1
call yellow1_led
mov al,0fH
mov count,al
call green_led
lgs2:
mov al,count
mov dis_num,al
call dis_number
call D8253
call init_8259
mov al,count
cmp al,0
jnz lgs2
call yellow2_led
mov al,0fH
mov count,al
jmp lgs1
INT8259:
cli
push ax
push dx
mov al,20H
mov dx,Port0
out dx,al
mov al,count
dec al
mov count,al
pop dx
pop ax
sti
IRET
init_8259 proc
CLI
mov ax,offset INT8259
mov bx,003CH
mov [bx],ax
mov bx,003EH
mov ax,0000H
mov [bx],ax
mov al,13H
mov dx,Port0
out dx,al
mov al,08H
mov dx,Port1
out dx,al
mov al,09H
out dx,al
mov al,7FH
out dx,al
mov SI,0000H
STI
RET
init_8259 endp
cs_led proc
push ax
push dx
mov al,10001001B
mov dx,PCTL
out dx,al
mov dx,PA
mov al,11011011B
out dx,al
mov dx,PB
mov al,00000110b
out dx,al
pop dx
pop ax
ret
cs_led endp
red_led proc
push ax
push dx
mov al,10001001B
mov dx,PCTL
out dx,al
mov dx,PA
mo
v al,10011110B
out dx,al
mov dx,PB
mov al,00000111B
out dx,al
pop dx
pop ax
ret
red_led endp
green_led proc
push ax
push dx
mov al,10001001B
mov dx,PCTL
out dx,al
mov dx,PA
mov al,11110011B
out dx,al
mov dx,PB
mov al,00001100B
out dx,al
pop dx
pop ax
ret
green_led endp
yellow1_led proc
push ax
push dx
push cx
mov al,10001001B
mov dx,PCTL
out dx,al
mov cx,3
L1: mov dx,PA
mov al,01011101B
out dx,al
mov dx,PB
mov al,00000111B
out dx,al
call delay4
mov dx,PB
mov al,00000111B
out dx,al
mov dx,PA
mov al,11011111B
out dx,al
call delay4
LOOP L1
pop cx
pop dx
pop ax
ret
yellow1_led endp
yellow2_led proc
push ax
push dx
push cx
mov al,10001001B
mov dx,PCTL
out dx,al
mov cx,5
L2: mov dx,PA
mov al,11101011B
out dx,al
mov dx,PB
mov al,00001010B
out dx,al
call delay4
mov dx,PA
mov al,11111011B
out dx,al
mov dx,PB
mov al,00001110B
out dx,al
call delay4
LOOP L2
pop cx
pop dx
pop ax
ret
yellow2_led endp
D8253 proc
push dx
push ax
mov dx,TIM_CTL
mov al,MODE02
out dx,al
mov dx,TIMER0
mov ax,20000
out dx,al
mov al,ah
out dx,al
pop ax
pop dx
ret
D8253 endp
dis_number proc
push ax
mov al,lin
cmp al,0
jnz nu0
mov al,80h
jmp nu1
nu0: cmp al,1
jnz nuret
mov al,0C0h
nu1: add al,col
call send_com
mov ah,0
mov al,dis_num
mov bl,10
div bl
mov temp0,ah
mov ah,0
mov bl,10
div bl
mov temp1,ah
add al,30h
call send_data
mov al,temp1
add al,30h
call send_data
mov al,temp0
add al,30h
call send_data
pop ax
nuret: ret
dis_number endp
dis_english proc
push ax
mov al,lin
cmp al,0
jnz ch0
mov al,80h
jmp ch1
ch0: cmp al,1
jnz chret
mov al,0C0h
ch1: add al,col
call send
_com
mov ah,num
ch2: mov al,[bx]
inc bx
call send_data
dec ah
jnz ch2
pop ax
chret: ret
dis_english endp
close_lcd proc
push ax
mov al, 01h
call send_com
pop ax
ret
close_lcd endp
init_lcd proc
mov dx,LCDWI
mov al,30h
out dx,al
call delay
mov al,30h
out dx,al
call delay
mov al,30h
out dx,al
call delay
mov al,38h
out dx,al
call delay
mov al,08h
out dx,al
call delay
mov al,01h
out dx,al
call delay
mov al,0eh
out dx,al
call delay
call chkbusy
lcd_p: mov al,06h
call send_com
mov al,02h
call send_com
call delay
ret
init_lcd endp
chkbusy proc
push dx
push ax
mov dx,LCDRS
rechk: in al,dx
mov cl,al
rol cl,1
jc rechk
pop ax
pop dx
ret
chkbusy endp
send_com proc
call chkbusy
push dx
mov dx,LCDWI
out dx,al
pop dx
ret
send_com endp
send_data proc
call chkbusy
push dx
mov dx,LCDWD
out dx,al
pop dx
ret
send_data endp
delay proc
push cx
mov cx,1000h
loop $
pop cx
ret
delay endp
delay1 proc
push cx
mov cx, 0080h
loop $
pop cx
ret
delay1 endp
delay2 proc
push ax
push cx
mov ah, 0
mov cx, ax
dloop: push cx
mov cx, 65535
loop $
pop cx
loop dloop
pop cx
pop ax
ret
delay2 endp
delay3 proc
push cx
mov cx, 0500h
loop $
pop cx
ret
delay3 endp
delay4 proc
push cx
mov cx, 32517
loop $
pop cx
ret
delay4 endp
LCDTAB1: DB "BEGIN: "
code ends
end START