MOV P3M0,#00H
MOV P3M1,#00H
MOV P4M0,#00H
MOV P4M1,#00H
MOV P5M0,#00H
MOV P5M1,#00H
MOV R7,#50
LCALL F_delay_ms
CLR ET0 ;Initialize Timer0 to output a 300KHz clock
CLR TR0
ORL AUXR,#080H ;Timer0 set as 1T mode
ORL AUXR2,#01H ;Enable clock output
MOV TMOD,#0 ;Timer0 set as Timer,16 bits Auto Reload.
MOV TH0,#HIGH Reload
MOV TL0,#LOW Reload
SETB TR0
LCALL F_ADC_init
MOV R7,#50
LCALL F_delay_ms
MOV R0,#adc_prev ;Initialize the previous ADC value
L_Init_Loop1:
MOV @R0,#03H
INC R0
MOV @R0,#0FFH
INC R0
MOV A,R0
CJNE A,#(adc_prev + CHANNEL * 2),L_Init_Loop1
MOV R0,#TouchZero ;Initialize the ADC 0-point value
L_Init_Loop2:
MOV @R0,#03H
INC R0
MOV @R0,#0FFH
INC R0
MOV A,R0
CJNE A,#(TouchZero+CHANNEL * 2),L_Init_Loop2
MOV R0,#TouchZeroCnt ;Initialize the automatic tracking count value
L_Init_Loop3:
MOV @R0,#0
INC R0
MOV A,R0
CJNE A,#(TouchZeroCnt + CHANNEL),L_Init_Loop3
MOV cnt_250ms,#5
L_MainLoop:
MOV R7,#50 ;Delay 50ms
LCALL F_delay_ms
LCALL F_ShowLED ;Handle key value once
DJNZ cnt_250ms,L_MainLoop
MOV cnt_250ms,#5 ;Processing once 0-point automatic tracking value every 250ms
LCALL F_AutoZero ; Zero tracking
SJMP L_MainLoop
F_ADC_init:
MOV P1M0,#00H ;8 channels ADC
MOV P1M1,#0FFH
MOV ADC_CONTR,#080H ;Enable ADC
RET