电子表显示汇编语言设计


IOCS1 EQU 8000H
IOCS2 EQU 9000H
IOCS3 EQU 0A000H
IOA EQU IOCS1+00H*2
IOB EQU IOCS1+01H*2
IOC EQU IOCS1+02H*2
IOCON EQU IOCS1+03H*2
IA EQU IOCS2+00H*2
IB EQU IOCS2+01H*2
IC EQU IOCS2+02H*2
ICON EQU IOCS2+03H*2
IO0 EQU IOCS3+00H*2
IO1 EQU IOCS3+01H*2
IO2 EQU IOCS3+02H*2
IODSC EQU IOCS3+03H*2


DATA SEGMENT
TABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H
DB 7FH,6FH
nls1 db 00h ;闹铃的数据缓冲区
nls2 db 00h
nls3 db 00h
nls4 db 00h
nls5 db 00h
nls6 db 00h
ct7 db 00h ;流水灯显示的计数变量
buf DB 0ffh,0feh,0fch,0f8h,0f0h,0e0h,0c0h,80h,00H ;流水灯的数据缓冲区
db 0ffh,7fh,3fh,1fh,0fh,07h,03h,01h,00h
db 0ffh,00h,0ffh,00h,0ffh,00h,0ffh,00h,0ffh,00h
db 0aah,55h,0aah,55h,0aah,55h,0aah,55h,0aah,55h
db 0f0h,0fh,0f0h,0fh,0f0h,0fh,0f0h,0fh,0f0h,0fh
ct1 db 00h ;时间的计时变量
ct2 db 00h
ct3 db 00h
ct4 db 00h
ct5 db 00h
ct6 db 00h
state db 00h
DATA ENDS ;数据段定义结束
STACK SEGMENT ;堆栈段开始
STA DW 50 DUP(?)
TOP EQU LENGTH STA
STACK ENDS ;堆栈段结束
CODE SEGMENT ;代码段开始
ASSUME CS:CODE, DS:DATA, ES:DATA, SS:STACK
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV AX,STACK
MOV SS,AX
;MOV AX,TOP
MOV SP,50 ;分配段寄存器

CLI
MOV DX,IOCS3+03H*2
MOV AL,76H
OUT DX,AL
MOV DX,IO1
MOV AX,1000
OUT DX,AL
MOV AL,AH
OUT DX,AL ;定时器1工作方式3,1000分频

STI
MOV DX,IOCON
MOV AL,89H
OUT DX,AL

MOV DX,ICON
MOV AL,89H
OUT DX,AL
MOV DX,IB
MOV AL,55H
OUT DX,AL ;初始化8255A端口

jud:
mov dx,ioc ;读取控制端口数据
in al,dx

p5: test al,20h ;判断清零开关是否闭合
jnz p3
jmp p2
p3: call ql ;是的话调用清零子程序
mov state,00h
p2: test al,80h ;不是的话判断启动开关是否闭合
jz jud ;没有的话重新判断


judge: cmp state,01h
jz jud1
MOV DX,IODSC
MOV AL,0b0H
OUT DX,AL
MOV DX,IO2
MOV Ax,1000
OUT DX,AL
mov al,ah
out dx,al ;定时器2工作方式0,500分频
;闭合的话调用显示子函数
mov state,01h
jud1: call dis
mov dx,ioc
in al,dx
p4: test al,40h ;判断闹铃设置开关是否闭合
jnz p1
jmp tf0
p1: call zs ;是的话调用闹铃设置程序
call dis ;调用显示子程序
jmp tf0

tf0: mov dx,ioc ;判断调时开关是否闭合
in al,dx
test al,08h
jnz tf
jmp tf1
tf: call dis ;调用显示子程序和调时子程序
call tiaoshi
mov state,00h
jmp tf0
tf1: mov dx,ioc ;判断调分开关是否闭合
in al,dx
test al,04h
jnz tf2
jmp tfm
tf2: call dis ;调用显示子程序和调分子程序
call tiaofen
mov state,00h
jmp tf1
tfm: mov dx,ioc ;判断调秒开关是否闭合
in al,dx
test al,02h
jnz tf4
jmp yx
tf4: call dis ;调用显示子程序和调秒子程序
call tiaomiao
mov state,00h
jmp tfm
yx: call dis ;其它的功能开关均没有按下,调用显示函数
mov dx,ioc
in al,dx
test al,10h ;

判断闹铃开关是否闭合
jnz p8
call gnling ;没有的话调用关闹铃函数
jmp p9
p8: call nling ;有的话调用闹铃检验函数,检验是否闹铃定时到
p9:
test al,01h ;判断秒脉冲的低电平是否到来
jnz j1 ;是的话跳到j1
mov state,01h
jmp jud ;没有的话重新进行检测


j1: mov state,00h
inc ct1 ;秒位加1
inc ct7 ;计数变量加1
cmp ct7,48 ;判断是否显示到最后
jz c1
jmp c2
c1: mov ct7,00h ;是的话清零
c2: call liushui ;调用流水灯显示子程序
cmp ct1,0ah ;判断秒位是否为10
jz j2
jmp jud
j2: mov ct1,00h
inc ct2 ;判断分位是否为6
cmp ct2,06h
jz j3
jmp jud
j3: mov ct2,00h
inc ct3
cmp ct3,0ah
jz j4
jmp jud
j4: mov ct3,00h
inc ct4
cmp ct4,06h
jz j5
jmp jud
j5: mov ct4,00h
inc ct5
cmp ct5,05h
jz j6
jmp jud
j6: mov ct5,00h
inc ct6
cmp ct6,03h
jz j7
jmp jud
j7: mov ct6,00h

jmp jud

dis proc near ;显示子函数
mov si,offset ct1

mov cl,7fh

again:
test cl,20h
jz g1
test cl,04h
jz g1
mov al,cl
mov dx,IOA
out dx,al

mov bx,offset TABLE
mov ax,0
mov al,[si]
add bx,ax
mov al,[bx]
mov dx,IOB
out dx,al

call delay
call clear

test cl,01h
jz out_dis
jmp ad
g1: mov al,cl
mov dx,IOA
out dx,al
mov al,40h
mov dx,IOB
out dx,al
call delay
call clear
ror cl,1
jmp again
ad: inc si
ror cl,1
jmp again
out_dis:
ret
dis endp


CLEAR PROC NEAR
MOV DX,IOB
MOV AL,00H
OUT DX,AL
RET
CLEAR ENDP
delay2 PROC NEAR
PUSH CX
MOV CX,01H
D3:MOV AX,0fffH
D4:DEC AX
JNZ D4
LOOP D3
POP CX
RET
delay2 ENDP
delay PROC NEAR
PUSH CX
MOV CX,01H
D1:MOV AX,043H
D2:DEC AX
JNZ D2
LOOP D1
POP CX
RET
delay ENDP
zs proc near
mov dx,ic
in al,dx
test al,02h
jz smj1
test al,04h
jz smj2
test al,08h
jz sfj1
test al,10h
jz sfj2
test al,20h
jz ssj1
test al,40h
jz ssj2
jmp quez
smj1: call delay2
mov dx,ic
in al,dx
test al,02h
jz sm1
jmp quez
sm1: mov dx,ic
in al,dx
test al,02h
jz sm1
inc nls1
cmp nls1,0ah
jz smq1
jmp quez
smq1: mov nls1,00h
jmp quez
smj2: call delay2
mov dx,ic
in al,dx
test al,04h
jz sm2
jmp quez
sm2: mov dx,ic
in al,dx
test al,04h
jz sm2
inc nls2
cmp nls2,06h
jz smq2
jmp quez
smq2: mov nls2,00h
jmp quez
sfj1: call delay2
mov dx,ic
in al,dx
test al,08h
jz sf1
jmp quez
sf1: mov dx,ic
in al,dx
test al,08h
jz sf1
inc nls3
cmp nls3,0ah

jz sfq1
jmp quez
sfq1: mov nls3,00h
jmp quez
sfj2: call delay2
mov dx,ic
in al,dx
test al,10h
jz sf2
sf2: mov dx,ic
in al,dx
test al,10h
jz sf2
inc nls4
cmp nls4,06h
jz sfq2
jmp quez
sfq2: mov nls4,00h
jmp quez
ssj1: call delay2
mov dx,ic
in al,dx
test al,20h
jz ss1
jmp quez
ss1: mov dx,ic
in al,dx
test al,20h
jz ss1
inc nls5
cmp nls6,02h
jz ssq1
cmp nls5,0ah
jz ssq12
jmp quez
ssq12: mov nls5,00h
inc nls6
jmp quez
ssq1: cmp nls5,04h
jz ssq11
ssq11: mov nls5,00h
mov nls6,00h
jmp quez
ssj2: call delay2
mov dx,ic
in al,dx
test al,40h
jz ss2
ss2: mov dx,ic
in al,dx
test al,40h
jz ss2
inc nls6
cmp nls6,03h
jz ssq2
jmp quez
ssq2: mov nls6,00h
jmp quez
quez: ret
zs endp
ql proc near
mov ct1,00h
mov ct2,00h
mov ct3,00h
mov ct4,00h
mov ct5,00h
mov ct6,00h
ret
ql endp
nling proc near
push ax
mov al,nls6
nl: cmp ct6,al
jz k3
jmp quit
k3: mov al,nls5
cmp ct5,al
jz k4
jmp quit
k4: mov al,nls4
cmp ct4,al
jz k5
jmp quit
k5: mov al,nls3
cmp ct3,al
jz naol
call gnling
jmp quit
naol:
mov dx,ia
mov al,01h
out dx,al
quit: pop ax
ret
nling endp
gnling proc near
push ax
mov dx,ia
mov al,00h
out dx,al
pop ax
ret
gnling endp
liushui proc near
mov di,offset buf
mov ax,00h
mov al,ct7
add di,ax
mov al,[di]
mov dx,ib
out dx,al
ret
liushui endp
tiaoshi proc near
mov dx,ic
in al,dx
test al,01h
jz tz
jmp que
tz: call delay2
mov dx,ic
in al,dx
test al,01h
jz tz5
jmp que
tz5: mov dx,ic
in al,dx
test al,01h
jz tz5
cmp ct6,02h
jz tz2
jmp tz1
tz2: mov ct6,02h
inc ct5
cmp ct5,04h
jz tz3
jmp que
tz3: mov ct5,00h
mov ct6,00h
jmp que

tz1: inc ct5
cmp ct5,0ah
jz tz4
jmp que
tz4: mov ct5,00h
inc ct6
jmp que
que: ret
tiaoshi endp
tiaofen proc near
mov dx,ic
in al,dx
test al,01h
jz cf
jmp quef
cf: call delay2
mov dx,ic
in al,dx
test al,01h
jz cf1
jmp quef
cf1: mov dx,ic
in al,dx
test al,01h
jz cf1
inc ct3
cmp ct3,0ah
jz cf2
jmp quef
cf2: mov ct3,00h
inc ct4
cmp ct4,06h
jz cf3
jmp quef
cf3: mov ct4,00h
inc ct5
cmp ct6,02h
jz cf4
jmp cf6
cf4: cmp ct5,05h
jz cf5
jmp quef
cf5: mov ct5,00h
mov ct6,00h
jmp quef
cf6: cmp ct5,0ah
jz cf7
jmp quef
cf7: mov ct5,00h
inc ct6
jmp quef

quef: ret
tiaofen endp
tiaomiao proc near
mov dx,ic
in al,dx
test al,01h
jz mf
jmp quem
mf: call delay2
mov dx,ic
in al,dx
test al,01h
jz mf1
jmp quem
mf1: mov dx,ic
in al,dx
test al,01h
jz mf1
inc ct1
cmp ct1,0ah
jz mf2
jmp quem
mf2: mov ct1,00h
inc ct2
cmp ct2,06h
jz mf3
jmp quem
mf3: mov ct2,00h
inc ct3
cmp ct3,0ah
jz mf4
jmp quem
mf4: mov ct3,00h
inc ct4
cmp ct4,06h
jz mf5
jmp quem
mf5: inc ct5
jmp quem

quem: ret
tiaomiao endp
CODE ENDS
END START

DATA SEGMENT
IOCS1 EQU 8000H
IOCS2 EQU 9000

H
IOCS3 EQU 0A000H
IOA EQU IOCS1+00H*2
IOB EQU IOCS1+01H*2
IOC EQU IOCS1+02H*2
IOCON EQU IOCS1+03H*2
IA EQU IOCS2+00H*2
IB EQU IOCS2+01H*2
IC EQU IOCS2+02H*2
ICON EQU IOCS2+03H*2
IO0 EQU IOCS3+00H*2
IO1 EQU IOCS3+01H*2
IO2 EQU IOCS3+02H*2
IODSC EQU IOCS3+03H*2
TABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H
DB 7FH,6FH
nls1 db 00h ;闹铃的数据缓冲区
nls2 db 00h
nls3 db 00h
nls4 db 00h
nls5 db 00h
nls6 db 00h
ct7 db 00h ;流水灯显示的计数变量
buf DB 0ffh,0feh,0fch,0f8h,0f0h,0e0h,0c0h,80h,00H ;流水灯的数据缓冲区
db 0ffh,7fh,3fh,1fh,0fh,07h,03h,01h,00h
db 0ffh,00h,0ffh,00h,0ffh,00h,0ffh,00h,0ffh,00h
db 0aah,55h,0aah,55h,0aah,55h,0aah,55h,0aah,55h
db 0f0h,0fh,0f0h,0fh,0f0h,0fh,0f0h,0fh,0f0h,0fh
ct1 db 00h ;时间的计时变量
ct2 db 00h
ct3 db 00h
ct4 db 00h
ct5 db 00h
ct6 db 00h
state db 00h
DATA ENDS ;数据段定义结束
STACK SEGMENT ;堆栈段开始
STA DW 50 DUP(?)
TOP EQU LENGTH STA
STACK ENDS ;堆栈段结束
CODE SEGMENT ;代码段开始
ASSUME CS:CODE, DS:DATA, ES:DATA, SS:STACK
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV AX,STACK
MOV SS,AX
MOV AX,TOP
MOV SP,AX ;分配段寄存器

CLI
MOV DX,IODSC
MOV AL,76H
OUT DX,AL
MOV DX,IO1
MOV AX,1000
OUT DX,AL
MOV AL,AH
OUT DX,AL ;定时器1工作方式3,1000分频

STI
MOV DX,IOCON
MOV AL,89H
OUT DX,AL

MOV DX,ICON
MOV AL,89H
OUT DX,AL
MOV DX,IB
MOV AL,55H
OUT DX,AL ;初始化8255A端口

jud:
mov dx,ioc ;读取控制端口数据
in al,dx

p5: test al,20h ;判断清零开关是否闭合
jnz p3
jmp p2
p3: call ql ;是的话调用清零子程序
mov state,00h
p2: test al,80h ;不是的话判断启动开关是否闭合
jz jud ;没有的话重新判断


judge: cmp state,01h
jz jud1
MOV DX,IODSC
MOV AL,0b0H
OUT DX,AL
MOV DX,IO2
MOV Ax,1000
OUT DX,AL
mov al,ah
out dx,al ;定时器2工作方式0,500分频
;闭合的话调用显示子函数
mov state,01h
jud1: call dis
mov dx,ioc
in al,dx
p4: test al,40h ;判断闹铃设置开关是否闭合
jnz p1
jmp tf0
p1: call zs ;是的话调用闹铃设置程序
call dis ;调用显示子程序
jmp tf0

tf0: mov dx,ioc ;判断调时开关是否闭合
in al,dx
test al,08h
jnz tf
jmp tf1
tf: call dis ;调用显示子程序和调时子程序
call tiaoshi
mov state,00h
jmp tf0
tf1: mov dx,ioc ;判断调分开关是否闭合
in al,dx
test al,04h
jnz tf2
jmp tfm
tf2: call dis ;调用显示子程序和调分子程序
call tiaofen
mov state,00h
jmp tf1
tfm: mov dx,ioc ;判断调秒开关是否闭合
in al,dx
test al,02h
jnz tf4
jmp yx
tf4: call dis ;调用显示子程序和调秒子程序
call tiaomiao
mov state,00h
jmp tfm
yx: call dis ;其它的功能开关均没有按下,调用显示函数
mov dx,ioc
in al,dx
test al,10h ;判断闹铃开关是否闭合
jnz p8
call gnling ;没

有的话调用关闹铃函数
jmp p9
p8: call nling ;有的话调用闹铃检验函数,检验是否闹铃定时到
p9:
test al,01h ;判断秒脉冲的低电平是否到来
jnz j1 ;是的话跳到j1
mov state,01h
jmp jud ;没有的话重新进行检测


j1: mov state,00h
inc ct1 ;秒位加1
inc ct7 ;计数变量加1
cmp ct7,48 ;判断是否显示到最后
jz c1
jmp c2
c1: mov ct7,00h ;是的话清零
c2: call liushui ;调用流水灯显示子程序
cmp ct1,0ah ;判断秒位是否为10
jz j2
jmp jud
j2: mov ct1,00h
inc ct2 ;判断分位是否为6
cmp ct2,06h
jz j3
jmp jud
j3: mov ct2,00h
inc ct3
cmp ct3,0ah
jz j4
jmp jud
j4: mov ct3,00h
inc ct4
cmp ct4,06h
jz j5
jmp jud
j5: mov ct4,00h
inc ct5
cmp ct5,05h
jz j6
jmp jud
j6: mov ct5,00h
inc ct6
cmp ct6,03h
jz j7
jmp jud
j7: mov ct6,00h

jmp jud

dis proc near ;显示子函数
mov si,offset ct1

mov cl,7fh

again:
test cl,20h
jz g1
test cl,04h
jz g1
mov al,cl
mov dx,IOA
out dx,al

mov bx,offset TABLE
mov ax,0
mov al,[si]
add bx,ax
mov al,[bx]
mov dx,IOB
out dx,al

call delay
call clear

test cl,01h
jz out_dis
jmp ad
g1: mov al,cl
mov dx,IOA
out dx,al
mov al,40h
mov dx,IOB
out dx,al
call delay
call clear
ror cl,1
jmp again
ad: inc si
ror cl,1
jmp again
out_dis:
ret
dis endp


CLEAR PROC NEAR
MOV DX,IOB
MOV AL,00H
OUT DX,AL
RET
CLEAR ENDP
delay2 PROC NEAR
PUSH CX
MOV CX,01H
D3:MOV AX,0fffH
D4:DEC AX
JNZ D4
LOOP D3
POP CX
RET
delay2 ENDP
delay PROC NEAR
PUSH CX
MOV CX,01H
D1:MOV AX,043H
D2:DEC AX
JNZ D2
LOOP D1
POP CX
RET
delay ENDP
zs proc near
mov dx,ic
in al,dx
test al,02h
jz smj1
test al,04h
jz smj2
test al,08h
jz sfj1
test al,10h
jz sfj2
test al,20h
jz ssj1
test al,40h
jz ssj2
jmp quez
smj1: call delay2
mov dx,ic
in al,dx
test al,02h
jz sm1
jmp quez
sm1: mov dx,ic
in al,dx
test al,02h
jz sm1
inc nls1
cmp nls1,0ah
jz smq1
jmp quez
smq1: mov nls1,00h
jmp quez
smj2: call delay2
mov dx,ic
in al,dx
test al,04h
jz sm2
jmp quez
sm2: mov dx,ic
in al,dx
test al,04h
jz sm2
inc nls2
cmp nls2,06h
jz smq2
jmp quez
smq2: mov nls2,00h
jmp quez
sfj1: call delay2
mov dx,ic
in al,dx
test al,08h
jz sf1
jmp quez
sf1: mov dx,ic
in al,dx
test al,08h
jz sf1
inc nls3
cmp nls3,0ah
jz sfq1
jmp quez
sfq1: mov nls3,00h
jmp quez
sfj2:

call delay2
mov dx,ic
in al,dx
test al,10h
jz sf2
sf2: mov dx,ic
in al,dx
test al,10h
jz sf2
inc nls4
cmp nls4,06h
jz sfq2
jmp quez
sfq2: mov nls4,00h
jmp quez
ssj1: call delay2
mov dx,ic
in al,dx
test al,20h
jz ss1
jmp quez
ss1: mov dx,ic
in al,dx
test al,20h
jz ss1
inc nls5
cmp nls6,02h
jz ssq1
cmp nls5,0ah
jz ssq12
jmp quez
ssq12: mov nls5,00h
inc nls6
jmp quez
ssq1: cmp nls5,04h
jz ssq11
ssq11: mov nls5,00h
mov nls6,00h
jmp quez
ssj2: call delay2
mov dx,ic
in al,dx
test al,40h
jz ss2
ss2: mov dx,ic
in al,dx
test al,40h
jz ss2
inc nls6
cmp nls6,03h
jz ssq2
jmp quez
ssq2: mov nls6,00h
jmp quez
quez: ret
zs endp
ql proc near
mov ct1,00h
mov ct2,00h
mov ct3,00h
mov ct4,00h
mov ct5,00h
mov ct6,00h
ret
ql endp
nling proc near
push ax
mov al,nls6
nl: cmp ct6,al
jz k3
jmp quit
k3: mov al,nls5
cmp ct5,al
jz k4
jmp quit
k4: mov al,nls4
cmp ct4,al
jz k5
jmp quit
k5: mov al,nls3
cmp ct3,al
jz naol
call gnling
jmp quit
naol:
mov dx,ia
mov al,01h
out dx,al
quit: pop ax
ret
nling endp
gnling proc near
push ax
mov dx,ia
mov al,00h
out dx,al
pop ax
ret
gnling endp
liushui proc near
mov di,offset buf
mov ax,00h
mov al,ct7
add di,ax
mov al,[di]
mov dx,ib
out dx,al
ret
liushui endp
tiaoshi proc near
mov dx,ic
in al,dx
test al,01h
jz tz
jmp que
tz: call delay2
mov dx,ic
in al,dx
test al,01h
jz tz5
jmp que
tz5: mov dx,ic
in al,dx
test al,01h
jz tz5
cmp ct6,02h
jz tz2
jmp tz1
tz2: mov ct6,02h
inc ct5
cmp ct5,04h
jz tz3
jmp que
tz3: mov ct5,00h
mov ct6,00h
jmp que

tz1: inc ct5
cmp ct5,0ah
jz tz4
jmp que
tz4: mov ct5,00h
inc ct6
jmp que
que: ret
tiaoshi endp
tiaofen proc near
mov dx,ic
in al,dx
test al,01h
jz cf
jmp quef
cf: call delay2
mov dx,ic
in al,dx
test al,01h
jz cf1
jmp quef
cf1: mov dx,ic
in al,dx
test al,01h
jz cf1
inc ct3
cmp ct3,0ah
jz cf2
jmp quef
cf2: mov ct3,00h
inc ct4
cmp ct4,06h
jz cf3
jmp quef
cf3: mov ct4,00h
inc ct5
cmp ct6,02h
jz cf4
jmp cf6
cf4: cmp ct5,05h
jz cf5
jmp quef
cf5: mov ct5,00h
mov ct6,00h
jmp quef
cf6: cmp ct5,0ah
jz cf7
jmp quef
cf7: mov ct5,00h
inc ct6
jmp quef

quef: ret
tiaofen endp
tiaomiao proc near
mov dx,ic
in al,dx
test al,01h
jz mf
jmp quem
mf: call delay2
mov dx,ic
in al,dx
test al,01h
jz mf1
jmp quem
mf1: mov dx,ic
in al,dx
test al,01h
jz mf1
inc ct1
cmp ct1,0ah
jz mf2
jmp quem
mf2: mov ct1,00h
inc ct2
cmp ct2,06h
jz mf3
jmp quem
mf3: mov ct2,00h
inc ct3
cmp ct3,0ah
jz mf4
jmp quem
mf4: mov ct3,00h
inc ct4
cmp ct4,06h
jz mf5
jmp quem
mf5: inc ct5
jmp quem

quem: ret
tiaomiao endp
CODE ENDS
END START


相关推荐
相关主题
热门推荐