P4M1 DATA 0B3H
P4M0 DATA 0B4H
P5M1 DATA 0C9H
P5M0 DATA 0CAH
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW,#80H
MOV DPTR,#CMPEXCFG
CLR A
ANL A,#NOT 03H ;P3.7 is CMP+ input pin
ORL A,#04H ;internal 1.19V reference voltage is CMP- input pin
MOVX @DPTR,A
MOV P_SW,#00H
MOV P1M0,#00111111B ;P1.5 ~ P1.0 are initialized to open-drain mode
MOV P1M1,#00111111B
MOV P1,#0FFH
MOV CMPCR2,#10H ;Output comparator result after 16 debounce clocks
MOV CMPCR1,#00H
ANL CMPCR1,#NOT 02H ;Disable comparator output
ORL CMPCR1,#80H ;Enable comparator module
LOOP:
MOV R0,#00000000B ;Voltage <2.5V
MOV P1,#11111110B ;P1.0 outputs 0
CALL DELAY
MOV A,CMPCR1
JNB ACC.0,SKIP
MOV R0,#00000001B ;Voltage>2.5V
MOV P1,#11111101B ;P1.1 outputs 0
CALL DELAY
MOV A,CMPCR1
JNB ACC.0,SKIP
MOV R0,#00000011B ;Voltage>3.0V
MOV P1,#11111011B ;P1.2 outputs 0
CALL DELAY
MOV A,CMPCR1
JNB ACC.0,SKIP
MOV R0,#00000111B ;Voltage>3.5V
MOV P1,#11110111B ;P1.3 outputs 0
CALL DELAY