Mạch đồng hồ bấm giây thể thao.

Leave a Comment

Mạch đồng hồ bấm giây thể thao.



Code:
SECOND EQU 30H
TCOUNT EQU 31H
KCOUNT EQU 32H
KEY BIT P3.7
ORG 00H
SJMP START
ORG 0BH
LJMP INT_T0
START: MOV DPTR,#TABLE
MOV P0,#3FH
MOV P2,#3FH    ;Start, digital display, "00"
MOV SECOND,#00H
MOV TCOUNT,#00H
MOV KCOUNT,#00H
MOV TMOD,#01H    ;Timer 0 is in Mode 1
MOV TL0,#(65536-50000)/256
MOV TH0,#(65536-50000) MOD 256
K1: JB KEY,$    ;Wait for key
LCALL DELAY
JB KEY,$
MOV A,KCOUNT
CJNE A,#00H,K2    ;Determine the number keys
SETB TR0    ;1st button, start timer
MOV IE,#82H
JNB KEY,$
INC KCOUNT    ;Button up, button clicks value plus 1
LJMP K1
K2: CJNE A,#01H,K3
CLR TR0    ;2nd key, turn off timer
MOV IE,#00H
JNB KEY,$
INC KCOUNT    ;Button up, button clicks value plus 1
LJMP K1
K3: CJNE A,#02H,K1    ;The 3rd button, return to initial state
JNB KEY,$
LJMP START
INT_T0: MOV  TH0,#(65536-50000)/256
MOV  TL0,#(65536-50000) MOD 256
INC TCOUNT
MOV A,TCOUNT
CJNE A,#2,I2    ;0.1 seconds is enough to account
MOV TCOUNT,#00H
INC SECOND
MOV A,SECOND
CJNE A,#100,I1    ;10 seconds is enough to account
MOV SECOND,#00H
I1: MOV A,SECOND
MOV B,#10
DIV AB
MOVC A,@A+DPTR    ;Show time
MOV P0,A
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
I2: RETI
TABLE:  DB  3FH,06H,5BH,4FH,66H
DB 6DH,7DH,07H,7FH,6FH
DELAY: MOV R6,#20
D1: MOV R7,#250
DJNZ R7,$
DJNZ R6,D1
RET

END

( Full Code + Protues)

0 nhận xét:

Đăng nhận xét