2路ADC0808测量电压,通过按键切换,仿真加程序!
LED1 EQU 31H
LED2 EQU 32H
LED3 EQU 33H
ADC EQU 35H
BIAOZHI EQU 36H
ST BIT P3.2
EOC BIT P3.3
OE BIT P3.1
ORG 00H
SJMP START
ORG 0BH
MOV BIAOZHI,#00H
START: MOV P3,#0FFH
MOV LED1,#00H
MOV LED2,#00H
MOV LED3,#00H
MOV DPTR,#TAB
JB P3.7,MAINNOKEY //检测到按键
LCALL SETCHANNEL
SETCHANNEL: //通道切换子函数
LCALL DELAY5MS //去抖动流程
JB P3.7,SETCHANNELEND
JNB P3.7,$ //等待松开按键
MOV A,BIAOZHI
CPL A
MOV BIAOZHI,A
SETCHANNELEND:
RET
MAINNOKEY:MOV R4,#250
MOV R5,#250
WAIT:
MOV A,BIAOZHI
CJNE A,#00,WAIT2
SETB P3.0
CLR ST
SETB ST
CLR ST
JNB EOC,$
SETB OE
MOV ADC,P1
CLR OE
MOV A,ADC
MOV B,#51
DIV AB
MOV LED3,A
MOV A,B
MOV B,#5
DIV AB
MOV LED2,A
MOV LED1,B
LCALL DISP
LJMP START
// DJNZ R4,WAIT
WAIT2: CLR P3.0
CLR ST
SETB ST
CLR ST
JNB EOC,$
SETB OE
MOV ADC,P1
CLR OE
MOV A,ADC
MOV B,#51
DIV AB
MOV LED3,A
MOV A,B
MOV B,#5
DIV AB
MOV LED2,A
MOV LED1,B
LCALL DISP
// DJNZ R5,WAIT2
LJMP START
DISP: MOV A,#03EH
CLR P2.3
MOV P0,A
LCALL DELAY
SETB P2.3
MOV A,LED1
MOVC A,@A+DPTR
CLR P2.2
MOV P0,A
LCALL DELAY
SETB P2.2
MOV A,LED2
MOVC A,@A+DPTR
CLR P2.1
MOV P0,A
LCALL DELAY
SETB P2.1
MOV A,LED3
MOVC A,@A+DPTR
CLR P2.0
ORL A,#80H
MOV P0,A
LCALL DELAY
SETB P2.0
RET
DELAY: MOV R6,#10
D1: MOV R7,#250
DJNZ R7,$
DJNZ R6,D1
RET
DELAY5MS:
PUSH 0X06
PUSH 0X07
MOV R6,#0c4H
DL1: MOV R7,#0CH
DL2: DJNZ R7,DL2
DJNZ R6,DL1
POP 0X07
POP 0X06
RET
TAB:DB 3FH,06H,5BH,4FH,66H
DB 6DH,7DH,07H,7FH,6FH
END |
|