利用定时器1的定时模式制作一个秒表。
电路说明:
HT48R50A-1 的端口A,端口C控制4个共阳极七段显示器以显示秒表的s及1/100s。
HT48R50A-1 的复位键SW1作为秒表的开始计时,停止计时和回零按键。
程序:
; *************************************************** ; * Filename : 9712a.ASM * ; * Function : Stop watch * ; * Microprocessor : HT48R50A-1/28SKDIP-A * ; * Crystal : 4MHz * ; *************************************************** #INCLUDE HT48R50A-1.INC TIMER_START EQU 55H TIMER_STOP EQU 66H ;---------------------------------------------------- DATA .SECTION AT 60H 'DATA' WARM_RESET DB ? ;[60H] DELAY_COUNTER DB ? ;[61H] DISPLAY_DATA DB ? ;[62H] DISPLAY_COUNTER DB ? ;[63H] DISPLAY_SHIFT DB ? ;[64H] SECOND DB 4 DUP(?);[65H] ;---------------------------------------------------- CODE .SECTION AT 00H 'CODE' ORG 00H JMP START ORG 0CH JMP TIMER1 ORG 20H START: CLR PAC CLR PCC MOV A,WARM_RESET SUB A,TIMER_START SZ ACC JMP TIMER_STOP_C MOV A,TIMER_STOP MOV WARM_RESET,A JMP TIMER_START_GO TIMER_STOP_C: MOV A,WARM_RESET SUB A,TIMER_STOP SZ ACC JMP TIMER_ONE CLR WARM_RESET JMP DISPLAY TIMER_ONE: MOV A,TIMER_START MOV WARM_RESET,A CALL CLEAN JMP DISPLAY TIMER_START_GO: MOV A,09H MOV INTC,A MOV A,80H MOV TMR1C,A MOV A,0F0H MOV TMR1L,A MOV A,0D8H MOV TMR1H,A SET TMR1C.4 CALL CLEAN TIMER: MOV A,OFFSET SECOND MOV MP1,A MOV A,R1 SUB A,0AH SZ ACC JMP DISPLAY CLR R1 INC MP1 INC R1 MOV A,R1 SUB A,0AH SZ ACC JMP DISPLAY CLR R1 INC MP1 INC R1 MOV A,R1 SUB A,0AH SZ ACC JMP DISPLAY CLR R1 INC MP1 INC R1 MOV A,R1 SUB A,06H SZ ACC JMP DISPLAY CALL CLEAN DISPLAY: MOV A,OFFSET SECOND MOV MP0,A MOV A,0FEH MOV DISPLAY_SHIFT,A MOV A,04H MOV DISPLAY_COUNTER,A DISPLAY_LOOP: MOV A,R0 MOV TBLP,A TABRDL DISPLAY_DATA MOV A,DISPLAY_DATA MOV PA,A MOV A,DISPLAY_SHIFT MOV PC,A INC MP0 RL DISPLAY_SHIFT CALL DELAY SDZ DISPLAY_COUNTER JMP DISPLAY_LOOP MOV A,WARM_RESET SUB A,TIMER_STOP SZ ACC JMP DISPLAY JMP TIMER RET ;---------------------------------------------------- TIMER1: INC SECOND RETI ;---------------------------------------------------- CLEAN PROC MOV A,OFFSET SECOND MOV MP1,A MOV A,04H MOV DISPLAY_COUNTER,A CLEAN_LOOP: CLR R1 INC MP1 SDZ DISPLAY_COUNTER JMP CLEAN_LOOP RET CLEAN ENDP ;---------------------------------------------------- DELAY PROC MOV A,0FFH MOV DELAY_COUNTER,A WAIT: SDZ DELAY_COUNTER JMP WAIT RET DELAY ENDP ;---------------------------------------------------- ORG 0F00H DC 081H,0CFH,092H,086H ;0123 DC 0CCH,0A4H,0A0H,08FH ;4567 DC 080H,084H ;89 ;---------------------------------------------------- END
上一篇:74HC595驱动LCD1602程序
下一篇:HOLTEK单片机-4X4键盘使用软件扫描
推荐阅读最新更新时间:2024-03-16 14:26