📄 t0_leddrv.asm
字号:
PUBLIC InitT0
PUBLIC DispBuf
PUBLIC KeyCode
T0Data SEGMENT DATA
RSEG T0Data
pBuf: DS 1
DispBuf:DS 6
KeyLast:DS 4
KeyTmp: DS 1
KeyCode:DS 1
CSEG AT 1*8+3
LJMP T0_ISR
T0Code SEGMENT CODE
RSEG T0Code
;--------------------------------------------------------
; T0 Initial
;--------------------------------------------------------
InitT0:
MOV pBuf,#0
MOV R0,#KeyLast
MOV B,#4
KeyLastValue:
MOV @R0,#0Fh
DJNZ B,KeyLastValue
MOV KeyCode,0
MOV A,TMOD
ANL A,#0F0h
ORL A,#00000001B
MOV TMOD,A
MOV TH0,#0FEh
MOV TL0,#0
SETB TR0
SETB ET0
SETB EA
RET
;--------------------------------------------------------
; T0 ISR
;--------------------------------------------------------
T0_ISR: MOV TH0,#0FEh
MOV TL0,#0
MOV P0,#0FFh ; Close all seg
MOV P2,#0Fh
PUSH ACC
PUSH PSW
PUSH DPL
PUSH DPH
PUSH B
DispLay:
MOV B,R0
MOV A,pBuf ; Fetch pointer
ADD A,#DispBuf ; Add Buffer Base Addr
MOV R0,A
MOV A,@R0 ; Fetch Data to be displayed
MOV DPTR,#CharTab ; Char. Table address
MOVC A,@A+DPTR ; Get Char Segs of the data
MOV P0,A ; to display
MOV A,pBuf ; Fetch pointer again
MOV DPTR,#LedSel ; Select. Table address
MOVC A,@A+DPTR
MOV P2,A
Key_Check:
MOV A,pBuf
ANL A,#0FCh
JNZ Pointer_Adapt ; if pBuf >= 4 No Keys
MOV A,pBuf
ADD A,#KeyLast
MOV R0,A
MOV A,@R0 ; fetch Last Key
MOV KeyTmp,P2
ANL KeyTmp,#0Fh ; fetch current key state
XRL A,KeyTmp
JZ Pointer_Adapt
MOV @R0,KeyTmp ; newer state saved for next fetch
Try1: CJNE A,#01,Try2
MOV KeyTmp,#0
SJMP LineCode
Try2: CJNE A,#02,Try4
MOV KeyTmp,#1
SJMP LineCode
Try4: CJNE A,#04,Try8
MOV KeyTmp,#2
SJMP LineCode
Try8: CJNE A,#08,Pointer_Adapt
MOV KeyTmp,#3
SJMP LineCode
LineCode:
MOV A,pBuf
RL A
RL A
ADD A,KeyTmp
SETB ACC.7
MOV KeyTmp,A
MOV A,P2
ANL A,#0Fh
XRL A,#0Fh
JZ ReleaseKey
MOV A,#40h
ReleaseKey:
ADD A,KeyTmp
MOV KeyCode,A
Pointer_Adapt:
INC pBuf
CLR C
MOV A,#5
SUBB A,pBuf
JNC Exit_T0
CLR A
MOV pBuf,A
Exit_T0:
MOV R0,B
POP B
POP DPH
POP DPL
POP PSW
POP ACC
RETI
;CharTab:DB 0c0h,0f9h,0a4h,0b0h,099h,092h,082h,0f8h,080h,090h,088h,083h,0C6h,0A1h,086h,08Eh,0FFh
CharTab:DB 003h,09fh,025h,00dh,099h,049h,041h,01fh,001h,009h,011h,0c1h,063h,085h,061h,071h,0FFh
LedSel: DB 1Fh,3Fh,5Fh,7Fh,9Fh,0BFh
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -