TLOW EQU 0F0H
THIGH EQU 0D8H
FLAG_DIR BIT 20H.0;FANGXIANG
COUNT_INT DATA 30H
COUNT_K DATA 31H
LEDVALUE DATA 32H
COUNT_KEY DATA 33H
KEY0 EQU P2.0
KEY1 EQU P2.1
KEY2 EQU P2.2
KEY3 EQU P2.3
;--------------------------------------------------
ORG 0000H
JMP MAIN
ORG 0BH
JMP T0_INT
;--------------------------------------------------
MAIN:
MOV SP,#60H
CALL INIT_TIMER
SETB TR0
CLR FLAG_DIR
MOV LEDVALUE,#01H
MOV COUNT_KEY,#50
MOV COUNT_K,#50
MAIN_LOOP:
READKEY0:
JB KEY0,READKEY1
JNB KEY0,$
SETB FLAG_DIR
AJMP READKEYEND
READKEY1:
JB KEY1,READKEY2
JNB KEY1,$
CLR FLAG_DIR
AJMP READKEYEND
READKEY2:
JB KEY3,READKEY3
JNB KEY3,$
CLR C
MOV A,COUNT_KEY
ADDC A,#5
JNC COUNT_KEY_NOT_OV
MOV A,#250
COUNT_KEY_NOT_OV:
MOV COUNT_KEY,A
MOV COUNT_K,A
AJMP READKEYEND
READKEY3:
JB KEY2,READKEYEND
JNB KEY2,$
MOV A,COUNT_KEY
SUBB A,#5
JNC COUNT_KEY_NOT_OV2
MOV A,#5
COUNT_KEY_NOT_OV2:
MOV COUNT_KEY,A
MOV COUNT_K,A
AJMP READKEYEND
READKEYEND:
; MOV A,COUNT_KEY
; MOV COUNT_K,A
JMP MAIN_LOOP
;;-------------------------
;;-------------------------
INIT_TIMER: ;初始化定时器
MOV TMOD,#01H ;设置定时器0 工作模式为模式1
MOV IE, #82H ;启用定时器0 中断产生
MOV TL0,#TLOW ;10MS
MOV TH0,#THIGH
RET
;;-------------------------
T0_INT:
PUSH ACC
PUSH PSW
MOV TL0,#TLOW
MOV TH0,#THIGH
INC COUNT_INT
MOV A,COUNT_INT
CJNE A,#1,RUNOUT
MOV COUNT_INT,#0
DJNZ COUNT_K,RUNOUT
MOV A,COUNT_KEY
MOV COUNT_K,A
RUN:
JB FLAG_DIR,RUN_R;
RUN_L:
MOV A,LEDVALUE
RL A
MOV LEDVALUE,A
AJMP RUNOUT
RUN_R:
MOV A,LEDVALUE
RR A
MOV LEDVALUE,A
AJMP RUNOUT
RUNOUT:
; MOV A,LEDVALUE
MOV P0,LEDVALUE
T0_T:
POP PSW
POP ACC
RETI
;;-------------------------
END
|