微机原理课程设计-电子钟标准版|精品课程网站设计|课程设计网报告总结心得
电子钟标准版
.486p
code segment use16assume cs:codeORG 03000H
BEG:jmp start
tab db 0c0h,0f9h,0a4h,0b0h,099h,092h,082h,0f8h,080h,090h,088h,083h,0c6h,0a1h,086h,08ehporta1 equ 200hportb1 equ 204h portc1 equ 208hportp1 equ 20chporta2 equ 201hportb2 equ 205h portc2 equ 209hportp2 equ 20dhporta3 equ 202hportb3 equ 206h portc3 equ 20ahportp3 equ 20ehporta4 equ 203hportb4 equ 207h portc4 equ 20bhportp4 equ 20fhhour dw 23min dw 59sec dw 50count db 0c10 db 10BIT EQU 10111111BPORT2 EQU 360HPORT1 EQU 340HROW DB 01H,02H,04H,08H step db 0time dw 0stop dw 0ffhstart:mov ax,0 mov ds,ax ;关中断 cli
;8255初始化 mov al,80h;A口方式0,输出;B口方式0;C口输出 mov dx,20eh out dx,al mov dx,20dh out dx,al mov dx,20ch out dx,ax mov al,80h mov dx,20fh out dx,al mov dx,portb4;203h口 mov al,0ffh out dx,al
;8253 out0产生25ms信号 mov dx,30ch;8255CS接300h mov al,00110100b ; 计数器0,读写低八位,方式2,2进制 out dx,al mov al,01110110b ; 计数器1,读写低八位,方式3,2进制 out dx,al mov ax,37500;初值 mov dx,300h;计数器0 out dx,al mov al,ah out dx,al
;8253 out1产生25MS方波 mov dx,30ch mov ax,47000; mov dx,304h;计数器1//////////////////////////////////////////////////308 out dx,al mov al,ah out dx,al
;中断向量设置 mov ax,offset interupt;中断程序的入口地址 mov bx,20h mov [bx],ax mov ax,cs mov [bx+2],ax;/////////////////////////////////////////////////////????????????? ;8259init mov dx,3a0h mov al,00010011b ; ICW1 out dx,al mov dx,3a8h mov al,00001000b;IR0的中断类型号08H ICW2 ;mov dx,3a8h out dx,al mov al,00000101b; ICW4//////////////////////////00000001 out dx,al
;写屏蔽字 mov al,11111110b; 只有IRQ0允许 mov dx,3a8h out dx,alaga: sti ; 开中断 ;输入程序WT: MOV AL,00H MOV DX,PORT2 OUT DX,AL ;使数码管全灭的同时,列线输出0判断是否有键按下 MOV DX,PORT2 ;360H地址 IN AL,DX ;是否有键按下 NOT AL AND AL,0FH JNZ LK1 ;有,转 JMP WT ;无键,继续查询等待LK1: CALL DELY MOV AL,00H MOV DX,PORT2 OUT DX,AL ;再次确认是否有键按下 MOV DX,PORT2 IN AL,DX NOT AL AND AL,0FH JZ WT
MOV CL,00H ;有键,识别按键,CL为列计数器 MOV BL,0feH ;第0列LK4: MOV AL,BL MOV DX,PORT2 OUT DX,AL MOV DX,PORT2 IN AL,DX NOT AL AND AL,0FH ;结果为行值 JNZ KEYDOWN ;此列有键按下,计算键值 NEXT: INC CL ;扫描下一列 TEST BL,08H JZ WT ROL BL,1 JMP LK4
KEYDOWN: MOV BX,0
CMPROW: CMP AL,ROW[BX] JZ KEY/////////////////////////////////////////////////////stop INC BX JMP CMPROW KEY: IMUL BX,3 mov ah,0 ADD CL,BL mov al,cl cmp al,10 jnz goto1 cmp stop,0 jnz p1 mov stop,1 jmp goto2p1: mov stop,0 jmp goto2goto1: cmp al,11 jnz goto2 mov stop,0 mov step,1aga1: call input
cmp step,1 ja cmp2 mov ax,time imul ax,10 mov hour,ax inc step jmp aga1 cmp2: cmp step,2 ja cmp3 mov ax,time add hour,ax inc step jmp aga1cmp3: cmp step,3 ja cmp4 mov ax,time imul ax,10 mov min,ax inc step jmp aga1 cmp4: cmp step,4 ja cmp5 mov ax,time add min,ax inc step jmp aga1cmp5: mov step,0 mov stop,1goto2: jmp aga
;////////////////////////////////////////////////////////////////中断程序interupt proc far
push ax push bx push cx push dx lea bx,tab ;显示秒 mov cx,sec mov ax,cx div c10
mov dx,porta3 push ax mov ah,0 xlat out dx,al pop ax
mov dx,portb3 mov al,0 xchg ah,al xlat out dx,al
;分钟 mov cx,min mov ax,cx div c10
mov dx,porta2 push ax mov ah,0 xlat out dx,al pop ax
mov dx,portb2 mov al,0 xchg ah,al xlat out dx,al
;小时 mov cx,hour mov ax,cx div c10
mov dx,porta1 push ax mov ah,0 xlat out dx,al pop ax
mov dx,portb1 mov al,0 xchg ah,al xlat out dx,al
cmp stop,0 jz exit cmp hour,24 jl aa mov hour,0aa: cmp min,60 jl bb mov min,0bb: inc count ;响铃时间为0.5秒 cmp count,20 jl exit mov al,0ffh mov dx,portb4 out dx,al cmp count ,40 jl exit mov count,0 inc sec cmp min,59 jl skip cmp sec,55 jl exit
mov al,00h mov dx,portb4 out dx,al skip: cmp sec,60 jl exit mov sec,0 inc min cmp min,60 jl exit mov min,0 mov al,0ffh mov dx,portb4 out dx,al inc hour cmp hour,24 jl exit mov hour,0 exit:mov al,00100000b; 中断结束EOI mov dx,3a0h out dx,al pop dx pop cx pop bx pop ax iretinterupt endp
DELY proc PUSH CX MOV CX,0ffffH LOOP contentnbsp;POP CX REt dely endp;//////////////////////////////////////////////////////////////////////////键盘 input proc push ax push bx push cx push dxwt1: MOV AL,00H MOV DX,PORT2 OUT DX,AL ;使数码管全灭的同时,列线输出0判断是否有键按下 MOV DX,PORT2 IN AL,DX ;是否有键按下 NOT AL AND AL,0FH JNZ lk11 ;有,转 JMP wt1 ;无键,继续查询等待lk11: CALL DELY MOV AL,00H MOV DX,PORT2 OUT DX,AL ;再次确认是否有键按下 MOV DX,PORT2 IN AL,DX NOT AL AND AL,0FH JZ wt1 MOV CL,00H ;有键,识别按键,CL为列计数器 MOV BL,0feH ;第0列lk44: MOV AL,BL MOV DX,PORT2 OUT DX,AL MOV DX,PORT2 IN AL,DX NOT AL AND AL,0FH ;结果为行值 JNZ KEYDOWN1 ;此列有键按下,计算键值 next1: INC CL ;扫描下一列 TEST BL,08H JZ wt1 ROL BL,1 JMP lk44
KEYDOWN1: MOV BX,0 ;BX为行计数器,判断哪一行有按键CMPROW1:CMP AL,ROW[BX] JZ KEY1 INC BX JMP CMPROW1KEY1: IMUL BX,3 mov ah,0 ADD CL,BL mov al,cl mov time,ax pop dx pop cx pop bx pop ax retinput endp CODE ENDS END beg