ViewNumber EQU 20H
ViewParityPeriod EQU 30H
ViewBuffer EQU 31H
ROW_ONE BIT P3.2
ROW_TWO BIT P3.3
ROW_THREE BIT P3.4
COL_ONE BIT P3.5
COL_TWO BIT P3.7
;--=========================键盘监听=========================
InceptSpaceTime EQU 39H
KeyValue EQU 21H
RemoveTingleFlag BIT 10H
RemoveTingleTime EQU 40H
SendBuffer EQU 41H
IntegralSendPeriod EQU 42H
IntegralWaiterTime EQU 43H
RemoveTingleTimeMAX DATA 04H; 去抖动时间
IntegralWaiterTimeMAX DATA 64H; 积分发送等待时间
IntegralSendPeriodMAX DATA 32H; 积分发送周期
InceptSpaceTimeMAX DATA 14H; 键值接收最长间隔时间
;--==========================键值编码定义======================
STOP_RESET_KEY DATA 16H;
PRG_KEY DATA 15H
SET_KEY DATA 19H
UP_KEY DATA 0EH
DOWN_KEY DATA 0DH
PVN_KEY DATA 0BH
PRG_SET_KEY DATA 11H
PRG_UP_KEY DATA 04H
PRG_DOWN_KEY DATA 05H
InceptNumber EQU 44H
InceptBuffer EQU 45H
ORG 0000H
AJMP MAIN
ORG 000B
AJMP Timer0
ORG 0023H
AJMP DATAINCEPT
MAIN:MOV R0, #7FH
LOOP:MOV @R0, #00H
DJNZ R0, LOOP; 清0内部RAM低128K地址空间
MOV SP, #60H; 设定堆栈指针
MOV TMOD, #00H
MOV TL0, #18H
MOV TH0, #0E0H; 设置定时器定时时钟为5ms
SETB EA
SETB ET0
SETB TR0; 启动定时器0
SETB ES
JUMP:AJMP JUMP
Timer0:PUSH ACC
PUSH B
PUSH PSW
PUSH DPH
PUSH DPL
ACALL KeyboadMonitoring; 调用键盘监听字程序
ACALL DATAVIEW; 调用数据显示子程序
ACALL DATASEND; 调用数据发送子程序
ACALL ADDInceptSpaceTime; 键值接收间隔时间递增
POP DPL
POP DPH
POP PSW
POP B
POP ACC
RETI
;--================键盘监听==========================
KeyboadMonitoring:JB RemoveTingleFlag, GotoCheckKey
MOV C, COL_ONE
ANL C, COL_TWO
JC GetKeyValueEXIT
SETB RemoveTingleFlag
MOV RemoveTingleTime, #00H
AJMP EXIT
;--================键值监听判断==========================
GotoCheckKey: MOV A, RemoveTingleTime
CJNE A, #RemoveTingleTimeMAX, GetKeyValueEXIT
MOV RemoveTingleTime,#RemoveTingleTimeMAX
AJMP GetKeyValue
AJMP TreatMentKey
RET
;--================监听键值==========================
GetKeyValue: MOV KeyValue, #00H
MOV A, P3
CLR P3.2
SETB P3.3
SETB P3.4
NOP
MOV C, P3.5
MOV KeyValue.5, C
MOV C, P3.7
MOV KeyValue.4, C
CLR P3.3
SETB P3.2
SETB P3.4
NOP
MOV C, P3.5
MOV KeyValue.3, C
MOV C, P3.7
MOV KeyValue.2, C
NOP
CLR P3.4
SETB P3.2
SETB P3.4
MOV C, P3.5
MOV KeyValue.1, C
MOV C, P3.7
MOV KeyValue.0, C
MOV P3, A
GetKeyValueEXIT: RET
;--==================处理键值===========================
TreatMentKey: MOV A, KeyValue
CJNE A, #00H, Release
CJNE A, #STOP_RESET_KEY, Integral
MOV SendBuffer, A
RET
Release: CJNE A, #PRG_KEY, ReleaseCheck1
AJMP PreserveKey
ReleaseCheck1: CJNE A, #SET_KEY, ReleaseCheck2
AJMP PreserveKey
ReleaseCheck2: CJNE A, #PVN_KEY, ReleaseCheck3
AJMP PreserveKey
ReleaseCheck3: CJNE A, #PRG_SET_KEY, ReleaseCheck4
AJMP PreserveKey
ReleaseCheck4: CJNE A, #PRG_UP_KEY, ReleaseCheck5
AJMP PreserveKey
ReleaseCheck5: CJNE A, #PRG_DOWN_KEY, ReleaseCheck6
AJMP PreserveKey
ReleaseCheck6: CJNE A, #UP_KEY, ReleaseCheck7
AJMP PreserveKey
ReleaseCheck7: CJNE A, #DOWN_KEY, ReleaseCheck8
AJMP PreserveKey
ReleaseCheck8: AJMP KeyBoradRelease
PreserveKey: MOV SendBuffer, A
;--===============键盘无闭合====================
KeyBoradRelease: CLR RemoveTingleFlag
MOV IntegralWaiterTime, #00H
MOV IntegralSendPeriod, #00H
RET
;--==================去抖动处理=========================
Integral: CJNE A, #UP_KEY, Integral1
AJMP TreanMentIntegral
Integral1: CJNE A, #DOWN_KEY, Integral2
AJMP TreanMentIntegral
Integral2: RET
TreanMentIntegral: MOV A, IntegralWaiterTime
CJNE A, #IntegralWaiterTimeMAX, INCIntegralWaiterTime
AJMP CheckIntegralSend
INCIntegralWaiterTime: INC IntegralWaiterTime
CheckIntegralSend: MOV A, IntegralSendPeriod
CJNE A, #00H, NoTSendIntegralKey
MOV KeyValue, SendBuffer
NoTSendIntegralKey: INC IntegralSendPeriod
CJNE A, #IntegralSendPeriodMAX, Integral2
MOV IntegralSendPeriod, #00H
RET
;--=====================InceptSpaceTime处理================
ADDInceptSpaceTime: MOV A, InceptSpaceTime
CJNE A, #InceptSpaceTimeMAX, ADDInceptSpaceTimeEXIT
INC InceptSpaceTime
ADDInceptSpaceTimeEXIT: RET
;--=====================数据显示============================
DATAVIEW:MOV C, ViewNumber.2
MOV ROW_ONE, C
MOV C, ViewNumber.1
MOV ROW_TWO, C
MOV C, ViewNumber.0
MOV ROW_THREE, C
MOV A,ViewParityPeriod
CJNE A, #00H, CheckGlintFlag
CheckGlintFlag:MOV DPTR, #ViewBuffer
MOV A, #08H
MOVC A, @A+DPTR
MOV R0, ViewNumber
LEFTMOVE: CJNE R0, #1, GetGlintFlag
AJMP CheckFlag
GetGlintFlag: RR A
DJNZ R0,LEFTMOVE
CheckFlag: JNB ACC.0, GetViewData
MOV P1, #00H
AJMP INCMUNBER
GetViewData: MOV A, ViewNumber
MOVC A, @A+DPTR
MOV P1, A
INCMUNBER: INC ViewNumber
MOV A, ViewNumber
CJNE A, #07H, EXIT
MOV ViewNumber, #00H
INC ViewParityPeriod
MOV A, ViewParityPeriod
CJNE A, #03H, EXIT
MOV ViewParityPeriod, #00H
EXIT: RET
;--=====================数据发送==============================
DATASEND: MOV A, SendBuffer
CJNE A, #00H, SendData
RET
SendData: MOV SBUF, A
MOV SendBuffer, 00H
RET
;--=====================数据接收=============================
DATAINCEPT: MOV A, SBUF
MOV R0, A
CheckInceptData: MOV A, InceptNumber
CJNE A, #00H, CheckInceptSpaceTime
CJNE R0, #0FH, DATAINCEPTEXIT
AJMP InceptDataEnd
CheckInceptSpaceTime: MOV R1, InceptSpaceTime
CJNE R1, #InceptSpaceTimeMAX, InceptData
MOV InceptNumber, #00H
AJMP CheckInceptData
InceptData: MOV A, InceptNumber
ADD A, #InceptBuffer
MOV R1, A
MOV A, R0
MOVX @R1, A
InceptDataEnd: MOV InceptSpaceTime, #00H
INC InceptNumber
MOV A, InceptNumber
CJNE A, #09H, DATAINCEPTEXIT
MOV InceptNumber, #00H
DATACOPY: MOV R0, #00H
DATACOPY1: MOV A, R0
ADD A, #InceptBuffer
MOV R1, A
MOV A, @R1
MOV R2, A
MOV A, R0
ADD A, #InceptBuffer
MOV R1, A
MOV A, R2
MOV @R1, A
INC R0
CJNE R0, #08H, DATACOPY1
DATAINCEPTEXIT: RET
END