微机原理课程设计报告-数字时钟的实现(附代码)

附录:实验代码:(完整的源程序)

CODE SEGMENT ASSUME

CS:CODE,DS:CODE,ES:CODE ORG 3400H Start: JMP program

LedMap: 八段管显示码

db 0c0h,0f9h,0a4h,0b0h,099h,092h,082h,0f8h db

080h,090h,088h,083h,0c6h,0a1h,086h,08eh ;db 0bfh db 0f7h

KeyTable: ;键码定义

db 07h,04h,08h,05h,09h,06h,0ah,0bh db 01h,00h,02h,0fh,03h,0eh,0ch,0dh

OUTSEG equ 0ffdch ;段控制口

OUTBIT equ 0ffddh ;位控制口/键扫口 IN_KEY equ 0ffdeh ;键盘读入口 LedBuf db 6 dup(?) ;显示缓冲 time DB 0,0,0,0,0,0 ;INTNum equ 20

Port_8259_0 EQU 0FFE0H ;1110_0000 Port_8259_1 EQU 0FFE1H

Port_8253_00 EQU 0FFE4H ; 0_01 Port_8253_01 EQU 0FFE5H Port_8253_10 EQU 0FFE6H Port_8253_11 EQU 0FFE7H

program:

call initCLK0 CLI

MOV AX,OFFSET int8259 MOV BX,003CH MOV [BX],AX MOV BX,003EH MOV AX,0000H MOV [BX],AX

STI

call init8259

call update_ledbuff mainLoop: call display call handle_key jmp mainLoop

;================================ initCLK0: mov dx,Port_8253_11 mov al,00110100b out dx,al mov dx,Port_8253_00 ;clk0 mov ax,38400 out dx,al mov al,ah out dx,al ret

;================================init8259:

MOV AL,13H

MOV DX,Port_8259_0 OUT DX,AL MOV AL,08H

MOV DX,Port_8259_1 OUT DX,AL MOV AL,09H OUT DX,AL

MOV AL,7FH ;IRQ7 OUT DX,AL RET

;================================int8259: cli

push ax push bx push cx

MOV AL,20H 0010 MOV DX,Port_8259_0 OUT DX,AL

call timeInc

call update_ledbuff pop cx pop bx pop ax sti iret

;========================================= timeInc:

push bx push cx

mov bx,offset time

add bx,5 ;取time[5] inc byte ptr [bx] cmp byte ptr [bx],10 jb next5

mov byte ptr [bx],0 ;该位清零 dec bx ;下一位加1 inc byte ptr [bx] inc bx next5: dec bx

cmp byte ptr [bx],6 jb next4

mov byte ptr [bx],0 dec bx

inc byte ptr [bx] inc bx

next4: dec bx

cmp byte ptr [bx],10 jb next3

mov byte ptr [bx],0 dec bx

inc byte ptr [bx] inc bx

next3: dec bx cmp byte ptr [bx],6 jb next2

mov byte ptr [bx],0 dec bx

inc byte ptr [bx] inc bx

next2: dec bx dec bx

cmp byte ptr [bx],2 jnz cmp10

cmp4: inc bx

cmp byte ptr [bx],4 jb next1 mov byte ptr [bx],0 dec bx

mov byte ptr [bx],0 jmp over_timeInc

cmp10: inc bx

cmp byte ptr [bx],10 jb next1

mov byte ptr [bx],0 dec bx

inc byte ptr [bx] inc bx

next1: dec bx

cmp byte ptr [bx],3 jb over_timeInc mov byte ptr [bx],0

over_timeInc: pop cx pop bx ret

;================================ display:

push ax push bx

push cx push dx

mov bx,offset LEDBuf

mov cl,6 ;共6个八段管 ;从左边开始显示

mov ah,00100000b

DLoop:

mov dx,OUTBIT mov al,0

out dx,al ;关所有八段管

mov al,[bx]

mov dx,OUTSEG out dx,al

mov dx,OUTBIT mov al,ah

out dx,al ;显示一位八段管

push ax mov ah,1 call Delay pop ax

shr ah,1 inc bx dec cl jnz DLoop

mov dx,OUTBIT mov al,0

out dx,al ;关所有八段管 pop dx pop cx pop bx pop ax ret

;================================ update_ledbuff: push ax push bx push cx push dx mov cl,6

uloop: mov bx,offset time mov al,cl dec al mov ah,0

xlat ;取出time[cl-1]

mov bx,offset LEDMAP mov ah,0

xlat ;查找对应字形码

mov bx,offset LedBuf mov ch,0 add bx,cx dec bx

mov [bx],al ;放入LedBuf[cl-1]

dec cl jnz uloop pop dx pop cx pop bx pop ax ret

;================================ Delay: ;延时子程序 push cx

mov cx,256 loop $ pop cx ret

Delay1: 延时子程序 push cx mov cx,50 lxxx:

call display loop lxxx pop cx ret

;================================ handle_key:

call read_key

cmp al,0ch jne nextR jmp nextC nextR:

ret nextC:

cli

mov bx, offset time

mov cl,6 loop_d:

mov byte ptr [bx],16 inc bx loop loop_d

call update_ledbuff mov bx, offset time t1: call Display call read_key cmp al,2 ja t1 t1_over: mov [bx],al

call update_ledbuff call Delay1 t2: call Display call read_key CMP AL,0DH JNE T22 mov byte ptr [bx],16 call update_ledbuff call Delay1 JMP T1 T22:

cmp al,9 ja t2

cmp byte ptr [bx],2 je cmp_k_4 jmp t2_over

cmp_k_4:cmp al,3 ja t2

jmp t2_over t2_over:

inc bx

mov [bx],al

call update_ledbuff call Delay1 t3: call Display call read_key CMP AL,0DH JNE T33 mov byte ptr [bx],16 DEC BX call update_ledbuff call Delay1 JMP T2 T33:

cmp al,5 ja t3

t3_over:

inc bx

mov byte ptr[bx],al call update_ledbuff call Delay1 t4: call Display call read_key CMP AL,0DH JNE T44 mov byte ptr [bx],16 DEC BX call update_ledbuff call Delay1 JMP T3 T44:

cmp al,9 ja t4

t4_over:

inc bx

mov [bx],al

call update_ledbuff call Delay1 t5: call Display call read_key

;++++++++++++ CMP AL,0DH JNE T55 mov byte ptr [bx],16 DEC BX call update_ledbuff call Delay1 JMP T4 T55:

cmp al,5 ja t5

t5_over:

inc bx

mov [bx],al

call update_ledbuff call Delay1 t6: call Display call read_key CMP AL,0DH JNE T66 mov byte ptr [bx],16 DEC BX call update_ledbuff call Delay1 JMP T5 T66:

cmp al,9 ja t6

t6_over:

inc bx

mov [bx],al

call update_ledbuff call Delay1 call Delay1 key_over: sti ret

;================================ read_key:

push bx push cx push dx

mov al,0ffh ;关显示口 mov dx,OUTSEG out dx,al mov bl,0 mov ah,0feh mov cx,8 key1: mov al,ah

mov dx,OUTBIT out dx,al shl al,1 mov ah,al nop nop nop nop nop nop

mov dx,IN_KEY in al,dx not al nop nop

and al,0fh jnz key2 inc bl loop key1 nkey: mov al,20h pop dx pop cx pop bx ret key2: test al,1 je key3 mov al,0

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4