本帖最后由 eehome 于 2013-1-5 10:00 编辑
程序如下ctrl_port EQU 0106H
A_PORT EQU 0100H
B_PORT EQU 0102H
c_port equ 0104h
count equ 0206h
count0 equ 0200h
count1 equ 0202h
INTR EQU 0304H
INTR1 EQU 0306H
DCOUNT EQU 6
data segment
LEDTAB DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H
BUF DB 0,0,0,0,0,0
buff db 20 dup(?)
DAT1 DB 0
DAT2 DB 0
DAT3 DB 1
dat4 db 0
data ends
CODE SEGMENT
ASSUME CS:CODE,ds:data
START: CLI
PUSH DS
MOV SI,2*4
MOV AX,0
MOV DS,AX
MOV [SI],OFFSET INTB
MOV 2[SI], SEG INTB
POP DS
MOV AL,00010011B
MOV DX,INTR
OUT DX,AL
MOV AL,00000010B
MOV DX,INTR1
OUT DX,AL
MOV AL,00000001B
MOV DX,INTR1
OUT DX,AL
S
ti
mov ax,data
mov ds,ax
mov al,00110111b ;8253初始化
mov dx,count
out dx,al
mov dx,count0
mov ax,500h
out dx,al
mov al,ah
out dx,al
mov al,01110111b
mov dx,count
out dx,al
mov dx,count1
mov ax,50h
out dx,al
mov al,ah
out dx,al
MOV AL,10000001B ;8255初始化,
MOV DX,CTRL_PORT
OUT DX,AL
back: MOV DX,C_PORT
in al,dx
test al,00000010b
jz b2 ;判断是否清0
again: MOV DX,C_PORT
in al,dx
test al,00000001b
jz b1 ;判断是暂停还是继续?
mov cx,6
jia6: inc si
loop jia6
MOV AL,00000000B
MOV DX,C_PORT
OUT DX,AL
MOV AL,DAT1 ;DTA1中是秒
CMP AL,100
JZ A1
MOV BL,10
DIV BL
MOV BUF,AH ;秒的个位
MOV BUF+1,AL ;秒的十位
CALL DISPLAY_DEC
INC DAT1
JMP back
A1: MOV DAT1,0 ;满60秒,对DAT1清0
MOV AL,0
MOV AH,0
MOV BUF,AH
MOV BUF+1,AL
CALL DISPLAY_DEC ;先显示00,再进位
INC DAT2
MOV AL,DAT2 ;DAT2中是分
CMP AL,60
JZ A2
MOV BL,10
DIV BL
MOV BUF+2,AH ;分的个位
MOV BUF+3,AL ;分的十位
CALL DISPLAY_DEC
MOV CX,60
LOOP AGAIN
A2: MOV DAT2,0 ;满60分对DAT2清0
MOV AL,0
MOV AH,0
MOV BUF+2,AH
MOV BUF+3,AL
CALL DISPLAY_DEC ;先显示00:00再进位
MOV AL,DAT3 ;DAT3中是时
CMP AL,24
JZ A3
MOV BL,10
DIV BL
MOV BUF+4,AH ;时的个位
MOV BUF+5,AL ;时的十位
CALL DISPLAY_DEC
MOV CX,60
DEC CX
JZ back
A3: INC DAT3
JMP back
b1: CALL DISPLAY_DEC
mov al,01110000b ;对8253送GATE1控制信号
mov dx,c_port
out dx,al
call cunchu
CALL DELAY
jmp back
b2:
mov dx,c_port
in al,dx
test al,00000100b
jnz li
call xianshicj
call display_dec
mov cx,1
jz next2
mov si,6
dec cx
next2: call delay
jmp back
li: mov buf,0 ;清0
mov buf+1,0
mov buf+2,0
mov buf+3,0
mov buf+4,0
mov buf+5,0
mov dat2,0
mov dat3,1
call display_dec
; mov bx,1000
;jz back
mov al,10110000b ;对8253送GATE0控制信号
mov dx,c_port
out dx,al
CALL DELAY
;dec bx
jmp back
DISPLAY_DEC PROC
DA:
MOV DI,2
DISPAGAIN1:
MOV BL,BUF
MOV BH,0
LEA SI,LEDTAB ;以十进制显示
MOV AL,[BX][SI] ;取个位段码
not al ;共阳
MOV DX,A_PORT
OUT DX,AL ;用数码管显示个位
MOV AL,11100000B ;位选,1点亮
MOV AH,0
MOV DX,B_PORT
OUT DX,AL
CALL DELAY
MOV AL,0H ;清屏
MOV DX,B_PORT
OUT DX,AL
CALL DELAY1
CALL DELAY1
LEA SI,LEDTAB
MOV BL,BUF+1
MOV BH,0
MOV AL,[BX][SI] ;取十位段码
not al
MOV DX,A_PORT
OUT DX,AL ;用数码管显示十位
MOV AL,11010000B
MOV DX,B_PORT
OUT DX,AL
CALL DELAY
MOV AL,0H
MOV DX,B_PORT
OUT DX,AL
CALL DELAY1
LEA SI,LEDTAB
MOV BL,BUF+2
MOV BH,0
MOV AL,[BX][SI] ;取分个位段码
not al
MOV DX,A_PORT
OUT DX,AL ;用数码管显示分个位
MOV AL,11001000B
MOV DX,B_PORT
OUT DX,AL
CALL DELAY
MOV AL,0H
MOV DX,B_PORT
OUT DX,AL
CALL DELAY1
CALL DELAY1
LEA SI,LEDTAB
MOV BL,BUF+3
MOV BH,0
MOV AL,[BX][SI] ;取分十位段码
not al
MOV DX,A_PORT
OUT DX,AL ;用数码管显示分十位
MOV AL,11000100B
MOV DX,B_PORT
OUT DX,AL
CALL DELAY
MOV AL,0H
MOV DX,B_PORT
OUT DX,AL
CALL DELAY1
LEA SI,LEDTAB
MOV BL,BUF+4
MOV BH,0
MOV AL,[BX][SI] ;取时个位段码
not al
MOV DX,A_PORT
OUT DX,AL ;用数码管显示时个位
MOV AL,11000010B
MOV DX,B_PORT
OUT DX,AL
CALL DELAY
MOV AL,0H
MOV DX,B_PORT
OUT DX,AL
CALL DELAY1
CALL DELAY1
LEA SI,LEDTAB
MOV BL,BUF+5
MOV BH,0
MOV AL,[BX][SI] ;取时十位段码
not al
MOV DX,A_PORT
OUT DX,AL ;用数码管显示时十位
MOV AL,11000001B
MOV DX,B_PORT
OUT DX,AL
CALL DELAY
MOV AL,0H
MOV DX,B_PORT
OUT DX,AL
CALL DELAY1
DEC DI
JNZ DISPAGAIN1
RET
DISPLAY_DEC ENDP
DELAY PROC
MOV CX,1dh
LOOP $
RET
DELAY ENDP
DELAY1 PROC
MOV CX,3h
LOOP $
RET
DELAY1 ENDP
cunchu proc
push ax
push bx
push cx
mov al,buf
mov ah,buf+1
mov bl,buf+2
mov bh,buf+3
mov cl,buf+4
mov ch,buf+5
mov buff[si],al
mov buff[si+1],ah
mov buff[si+2],bl
mov buff[si+3],bh
mov buff[si+4],cl
mov buff[si+5],ch
pop ax
pop bx
pop cx
ret
cunchu endp
xianshicj proc
push ax
push bx
push cx
mov al,buff[si]
mov ah,buff[si+1]
mov bl,buff[si+2]
mov bh,buff[si+3]
mov cl,buff[si+4]
mov ch,buff[si+5]
mov buf,al
mov buf+1,ah
mov buf+2,bl
mov buf+3,bh
mov buf+4,cl
mov buf+5,ch
pop ax
pop bx
pop cx
ret
xianshicj endp
INTB PROC FAR
PUSH AX
PUSH BX
PUSH CX
MOV SI,6
MOV AL,20H
OUT 20H,AL
POP CX
POP BX
POP AX
IRET
INTB ENDP
CODE ENDS
END START
一周热门 更多>