nenobara49
Newbie
My ADC conversion is not working. when voltage is below 4V it suppose to turn LED from Green to Red. help please.
*************************************************************************************************************************************************************************
*************************************************************************************************************************************************************************
Code:
BANKSEL ADCON0 ;
MOVLW b'00000001'; TURN OFF THE A/D CONVERTER
MOVWF ADCON0 ; AND SELECT PORT RCO AS INPUT
;
BANKSEL ADCON1 ;
MOVLW b'00110000'; SET PORT A1 AS ANALOG FOR A/D CONVERTER
MOVWF ADCON1 ; THE REST AS DIGITAL
************************************************************************************************************************************************************************
LVM_1
BANKSEL ADCON1 ;
MOVLW b'01110000'; SET Vref, CLOCK SOURCE & OUTPUT JUSTIFICATION
MOVWF ADCON1 ; Vref=Vdd, INTERNAL CLK, RIGHT JUSTIFY OUTPUT
;
BANKSEL ADCON0 ;
BCF ADCON0,6 ; \
BCF ADCON0,5 ; |
BSF ADCON0,4 ; |-SET THE INPUT FOR CHANNEL AN4
BCF ADCON0,3 ; |
BCF ADCON0,2 ; /
;
BSF ADCON0,0 ; TURN ON THE A/D CONVERTER
;
MOVLW D'20' ; LOAD THE AQUISITION DELAY TIMER
MOVWF D_WAIT ;
DW_1 DECFSZ D_WAIT,1 ; WAIT FOR THE PROPER AQT
GOTO DW_1 ;
;
BSF ADCON0,1 ; START CONVERSION
CV_1A NOP ;
NOP ;
NOP ;
NOP ;
BTFSC ADCON0,1 ; IF CONVERSION IS DONE
GOTO CV_1A ; THEN
NOP ;
CV_1C BCF ADCON0,0 ; TURN OFF THE A/D CONVERTER
;
; ** SET LOW BATTERY FLAG IF BATTERY REACHES 4 VOLTS OR LESS **
;
CV_2
BANKSEL STATUS ;
BCF STATUS,C ; CLEAR THE STATUS CARRY FLAG
BANKSEL S_FLAG ;
BCF S_FLAG,2 ; CLEAR THE LOW BATTERY FLAG
BANKSEL LV_PRE ;
MOVF LV_PRE,W ;
BANKSEL ADRESH ; SUBTRACT THE LOW BAT LEVEL
SUBWF ADRESH,W ; FROM THE MEASURED LEVEL
BANKSEL STATUS ;
BTFSC STATUS,C ; IF EQUAL OR LESS
GOTO CV_RTN ; THEN
BANKSEL S_FLAG ;
BSF S_FLAG,2 ; SET THE LOW BATTERY FLAG
CV_RTN RETURN ;
*************************************************************************************************************************
; ** LOW BATTERY MODE-YEL **
;
LB_00 BTFSS S_FLAG,2 ; IF THE LOW BATTERY FLAG IS SET
GOTO LB_2D ; AND
BTFSC S_FLAG,4 ; IF THE DOA FLAG IS CLEAR
GOTO LB_2D ; AND
BTFSC S_FLAG,0 ; IF THE ALARM FLAG IS CLEAR
GOTO LB_2D ; THEN
LB_2 BTFSS S_FLAG,7 ; PULSE THE YEL LED
GOTO LB_2A ;
BTFSC S_FLAG,3 ; IF THE PULSE FLAG IS SET
CALL LED_R ; TURN ON THE YELLOW LED
GOTO LB_2C ;
LB_2A CALL LED_OFF ;
GOTO LB_2C ;
LB_2B CALL LED_OFF ;
LB_2C NOP ;
LB_2D NOP ;
Last edited by a moderator: