cho em hỏi ,tại sao em đọc kênh 0 và kênh1 của adc 0809 thì good nhưng đọc kênh 2 và kênh 3 thì lại không đúng ,có phải kênh này khác kênh 0 và kênh một .xin mọi người giúp đỡ .
TRAM EQU 31H
CHUC EQU 32H
DONVI EQU 33H
NGHIN EQU 34H
SO1 EQU 35H
SO2 EQU 36H
SO3 EQU 37H
SO4 EQU 38H
NHO EQU 39H
TAM EQU 40H
SO EQU 41H
OE BIT P3.3
ST BIT P3.5
EOC BIT P2.7
ORG 00H
CAIDAT:
MOV DONVI,#00H
MOV CHUC,#00H
MOV TRAM,#00H
MOV TMOD,#11H
MOV P0,#00H
MOV P1,#00H
MOV P2,#00H
MOV P3,#00H
CLR ST
CLR OE
SETB EOC
CALL ADC
CALL SS1
CALL DOCSO
CALL HIENTHI
LJMP CAIDAT
SS1:CJNE R1,#0FFH,SO_1
CALL SS2
RET
SS2:CJNE R2,#0FFH,SO_2
CALL SS3
RET
SS3:CJNE R3,#0FFH,SO_3
CALL SO_4
RET
SO_1: MOV SO1,R1
MOV SO2,#00h
MOV SO3,#00h
MOV SO4,#00h
RET
SO_2: MOV SO1,R1
MOV SO2,R2
MOV SO3,#00h
MOV SO4,#00h
RET
SO_3: MOV SO1,R1
MOV SO2,R2
MOV SO3,R3
MOV SO4,#00h
RET
SO_4: MOV SO1,R1
MOV SO2,R2
MOV SO3,R3
MOV SO4,R4
RET
DOCSO:
MOV NHO,#0
CALL LOOP
MOV A,TAM
ADD A,#000H
MOV DONVI,A
CALL LOOP
MOV A,TAM
ADD A,#010H
MOV CHUC,A
CALL LOOP
MOV A,TAM
ADD A,#020H
MOV TRAM,A
CALL LOOP
MOV A,TAM
ADD A,#030H
MOV NGHIN,A
RET
LOOP:
MOV A,SO1
DIV AB
MOV SO,B
MOV B,#10
MOV SO1,A
MOV A,SO2
DIV AB
MOV SO2,A
MOV A,SO
ADD A,B
MOV B,#10
MOV SO,A
MOV A,SO3
DIV AB
MOV SO3,A
MOV A,SO
ADD A,B
MOV B,#10
MOV SO,A
MOV A,SO4
DIV AB
MOV SO4,A
MOV A,SO
ADD A,B
ADD A,NHO
MOV B,#10
MOV SO,A
MOV A,SO
DIV AB
MOV NHO,A
MOV TAM,B
MOV B,#10
RET
DELAY_1MS:
MOV R6,#00H
LOOPE: INC R6
NOP
CJNE R6,#250,LOOPE
RET
DELAY500:
MOV R7,#00H
LOOPD: INC R7
NOP
CJNE R7,#125,LOOPD
RET
HIENTHI:
MOV R0,#100
LOOP1:
MOV P2,DONVI
CALL DELAY_1MS
MOV P2,CHUC
CALL DELAY_1MS
MOV P2,TRAM
CALL DELAY_1MS
MOV P2,NGHIN
CALL DELAY_1MS
DJNZ R0,LOOP1
RET
ADC:
CLR P3.7
CLR P3.6
NOP
SETB ST
NOP
NOP
NOP
NOP
NOP
CLR ST
HERE1: JB EOC,HERE1
HERE2: JNB EOC,HERE2
SETB OE
NOP
NOP
MOV P1,#0FFH
MOV C,P1.0
MOV 0E7H,C
MOV C,P1.1
MOV 0E6H,C
MOV C,P1.2
MOV 0E5H,C
MOV C,P1.3
MOV 0E4H,C
MOV C,P1.4
MOV 0E3H,C
MOV C,P1.5
MOV 0E2H,C
MOV C,P1.6
MOV 0E1H,C
MOV C,P1.7
MOV 0E0H,C
MOV R1,A
CLR OE
CALL DELAY500
CLR P3.7
SETB P3.6
NOP
SETB ST
NOP
NOP
NOP
NOP
NOP
CLR ST
HERE3: JB EOC,HERE3
HERE4: JNB EOC,HERE4
SETB OE
NOP
NOP
MOV P1,#0FFH
MOV C,P1.0
MOV 0E7H,C
MOV C,P1.1
MOV 0E6H,C
MOV C,P1.2
MOV 0E5H,C
MOV C,P1.3
MOV 0E4H,C
MOV C,P1.4
MOV 0E3H,C
MOV C,P1.5
MOV 0E2H,C
MOV C,P1.6
MOV 0E1H,C
MOV C,P1.7
MOV 0E0H,C
MOV R2,A
CLR OE
CALL DELAY500
SETB P3.7
CLR P3.6
NOP
SETB ST
NOP
NOP
NOP
NOP
NOP
CLR ST
HERE5: JB EOC,HERE5
HERE6: JNB EOC,HERE6
SETB OE
NOP
NOP
MOV P1,#0FFH
MOV C,P1.0
MOV 0E7H,C
MOV C,P1.1
MOV 0E6H,C
MOV C,P1.2
MOV 0E5H,C
MOV C,P1.3
MOV 0E4H,C
MOV C,P1.4
MOV 0E3H,C
MOV C,P1.5
MOV 0E2H,C
MOV C,P1.6
MOV 0E1H,C
MOV C,P1.7
MOV 0E0H,C
MOV R3,A
CLR OE
CALL DELAY500
SETB P3.7
SETB P3.6
NOP
SETB ST
NOP
NOP
NOP
NOP
NOP
CLR ST
HERE7: JB EOC,HERE7
HERE8: JNB EOC,HERE8
SETB OE
NOP
NOP
MOV P1,#0FFH
MOV C,P1.0
MOV 0E7H,C
MOV C,P1.1
MOV 0E6H,C
MOV C,P1.2
MOV 0E5H,C
MOV C,P1.3
MOV 0E4H,C
MOV C,P1.4
MOV 0E3H,C
MOV C,P1.5
MOV 0E2H,C
MOV C,P1.6
MOV 0E1H,C
MOV C,P1.7
MOV 0E0H,C
MOV R4,A
CLR OE
RET
END
TRAM EQU 31H
CHUC EQU 32H
DONVI EQU 33H
NGHIN EQU 34H
SO1 EQU 35H
SO2 EQU 36H
SO3 EQU 37H
SO4 EQU 38H
NHO EQU 39H
TAM EQU 40H
SO EQU 41H
OE BIT P3.3
ST BIT P3.5
EOC BIT P2.7
ORG 00H
CAIDAT:
MOV DONVI,#00H
MOV CHUC,#00H
MOV TRAM,#00H
MOV TMOD,#11H
MOV P0,#00H
MOV P1,#00H
MOV P2,#00H
MOV P3,#00H
CLR ST
CLR OE
SETB EOC
CALL ADC
CALL SS1
CALL DOCSO
CALL HIENTHI
LJMP CAIDAT
SS1:CJNE R1,#0FFH,SO_1
CALL SS2
RET
SS2:CJNE R2,#0FFH,SO_2
CALL SS3
RET
SS3:CJNE R3,#0FFH,SO_3
CALL SO_4
RET
SO_1: MOV SO1,R1
MOV SO2,#00h
MOV SO3,#00h
MOV SO4,#00h
RET
SO_2: MOV SO1,R1
MOV SO2,R2
MOV SO3,#00h
MOV SO4,#00h
RET
SO_3: MOV SO1,R1
MOV SO2,R2
MOV SO3,R3
MOV SO4,#00h
RET
SO_4: MOV SO1,R1
MOV SO2,R2
MOV SO3,R3
MOV SO4,R4
RET
DOCSO:
MOV NHO,#0
CALL LOOP
MOV A,TAM
ADD A,#000H
MOV DONVI,A
CALL LOOP
MOV A,TAM
ADD A,#010H
MOV CHUC,A
CALL LOOP
MOV A,TAM
ADD A,#020H
MOV TRAM,A
CALL LOOP
MOV A,TAM
ADD A,#030H
MOV NGHIN,A
RET
LOOP:
MOV A,SO1
DIV AB
MOV SO,B
MOV B,#10
MOV SO1,A
MOV A,SO2
DIV AB
MOV SO2,A
MOV A,SO
ADD A,B
MOV B,#10
MOV SO,A
MOV A,SO3
DIV AB
MOV SO3,A
MOV A,SO
ADD A,B
MOV B,#10
MOV SO,A
MOV A,SO4
DIV AB
MOV SO4,A
MOV A,SO
ADD A,B
ADD A,NHO
MOV B,#10
MOV SO,A
MOV A,SO
DIV AB
MOV NHO,A
MOV TAM,B
MOV B,#10
RET
DELAY_1MS:
MOV R6,#00H
LOOPE: INC R6
NOP
CJNE R6,#250,LOOPE
RET
DELAY500:
MOV R7,#00H
LOOPD: INC R7
NOP
CJNE R7,#125,LOOPD
RET
HIENTHI:
MOV R0,#100
LOOP1:
MOV P2,DONVI
CALL DELAY_1MS
MOV P2,CHUC
CALL DELAY_1MS
MOV P2,TRAM
CALL DELAY_1MS
MOV P2,NGHIN
CALL DELAY_1MS
DJNZ R0,LOOP1
RET
ADC:
CLR P3.7
CLR P3.6
NOP
SETB ST
NOP
NOP
NOP
NOP
NOP
CLR ST
HERE1: JB EOC,HERE1
HERE2: JNB EOC,HERE2
SETB OE
NOP
NOP
MOV P1,#0FFH
MOV C,P1.0
MOV 0E7H,C
MOV C,P1.1
MOV 0E6H,C
MOV C,P1.2
MOV 0E5H,C
MOV C,P1.3
MOV 0E4H,C
MOV C,P1.4
MOV 0E3H,C
MOV C,P1.5
MOV 0E2H,C
MOV C,P1.6
MOV 0E1H,C
MOV C,P1.7
MOV 0E0H,C
MOV R1,A
CLR OE
CALL DELAY500
CLR P3.7
SETB P3.6
NOP
SETB ST
NOP
NOP
NOP
NOP
NOP
CLR ST
HERE3: JB EOC,HERE3
HERE4: JNB EOC,HERE4
SETB OE
NOP
NOP
MOV P1,#0FFH
MOV C,P1.0
MOV 0E7H,C
MOV C,P1.1
MOV 0E6H,C
MOV C,P1.2
MOV 0E5H,C
MOV C,P1.3
MOV 0E4H,C
MOV C,P1.4
MOV 0E3H,C
MOV C,P1.5
MOV 0E2H,C
MOV C,P1.6
MOV 0E1H,C
MOV C,P1.7
MOV 0E0H,C
MOV R2,A
CLR OE
CALL DELAY500
SETB P3.7
CLR P3.6
NOP
SETB ST
NOP
NOP
NOP
NOP
NOP
CLR ST
HERE5: JB EOC,HERE5
HERE6: JNB EOC,HERE6
SETB OE
NOP
NOP
MOV P1,#0FFH
MOV C,P1.0
MOV 0E7H,C
MOV C,P1.1
MOV 0E6H,C
MOV C,P1.2
MOV 0E5H,C
MOV C,P1.3
MOV 0E4H,C
MOV C,P1.4
MOV 0E3H,C
MOV C,P1.5
MOV 0E2H,C
MOV C,P1.6
MOV 0E1H,C
MOV C,P1.7
MOV 0E0H,C
MOV R3,A
CLR OE
CALL DELAY500
SETB P3.7
SETB P3.6
NOP
SETB ST
NOP
NOP
NOP
NOP
NOP
CLR ST
HERE7: JB EOC,HERE7
HERE8: JNB EOC,HERE8
SETB OE
NOP
NOP
MOV P1,#0FFH
MOV C,P1.0
MOV 0E7H,C
MOV C,P1.1
MOV 0E6H,C
MOV C,P1.2
MOV 0E5H,C
MOV C,P1.3
MOV 0E4H,C
MOV C,P1.4
MOV 0E3H,C
MOV C,P1.5
MOV 0E2H,C
MOV C,P1.6
MOV 0E1H,C
MOV C,P1.7
MOV 0E0H,C
MOV R4,A
CLR OE
RET
END