Hi friends,
I am purely new in the world of microcontroller. I am trying to assemble a program on ADC and test the practical effect. I have used the PIC12F675. AN0 has been used as analogue input i.e. Vdd of 5v through 4.7k Pot. Internal oscillator is used. After conversion of an analogue input I like to subtract any value within the 8 bit range from the digital value and see the effect. If the subtraction sets the C flag of STATUS register i.e. input is greater than predetermined value, the AD conversion will continue and in the opposite case a LED connected to GP5 will glow.
After programming the device when used in practical, the LED glows continuously. Turning the Pot forward and backward has no effect on the LED. The code is given. Advice from any of my friends solicited.
Variables
STATUS EQU 03H
GPIO EQU 05H
ADRESH EQU 1EH
TRISIO EQU 85H
ANSEL EQU 9FH
ADVALUE EQU 20H ; Register to load AD value.
Main Program
BSF STATUS,5 ; Select Bank1
MOVLW B’00000001’ ; set AN0 as input and rest output.
MOVWF TRISIO ;
MOVLW B’00010001’ ; set Fosc/8 and select AN0 as analogue bit.
MOVWF ANSEL ;
BCF STATUS,5 ; Back to Bank 0
BEGIN MOVLW B’00000001’ ; Set ADFM- Left justified,
VCFG – Vdd
Analogue channel select bit – AN0
MOVWF ADCON0
CALL DELAY ; Acquisition time
BSF ADCON0,1 ; Start conversion
WAIT BTFSC ADCON0,1 ; See if conversion is complete, if not
GOTO WAIT ; continue
MOVF ADRESH,0 ; Load the result (only MSB) into W
MOVWF ADVALUE ; and finally in ADVALUE register.
MOVLW D’128’ ; Load a value and subtract it from the
SUBWF ADVALUE,0 ; ADVALUE
BTFSC STATUS,0 ; See if less than predetermined value,
GOTO BEGIN ; If not, continue conversion.
BSF GPIO,5 ; if yes, turn on LED
DELAY NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RETURN
END
I am purely new in the world of microcontroller. I am trying to assemble a program on ADC and test the practical effect. I have used the PIC12F675. AN0 has been used as analogue input i.e. Vdd of 5v through 4.7k Pot. Internal oscillator is used. After conversion of an analogue input I like to subtract any value within the 8 bit range from the digital value and see the effect. If the subtraction sets the C flag of STATUS register i.e. input is greater than predetermined value, the AD conversion will continue and in the opposite case a LED connected to GP5 will glow.
After programming the device when used in practical, the LED glows continuously. Turning the Pot forward and backward has no effect on the LED. The code is given. Advice from any of my friends solicited.
Variables
STATUS EQU 03H
GPIO EQU 05H
ADRESH EQU 1EH
TRISIO EQU 85H
ANSEL EQU 9FH
ADVALUE EQU 20H ; Register to load AD value.
Main Program
BSF STATUS,5 ; Select Bank1
MOVLW B’00000001’ ; set AN0 as input and rest output.
MOVWF TRISIO ;
MOVLW B’00010001’ ; set Fosc/8 and select AN0 as analogue bit.
MOVWF ANSEL ;
BCF STATUS,5 ; Back to Bank 0
BEGIN MOVLW B’00000001’ ; Set ADFM- Left justified,
VCFG – Vdd
Analogue channel select bit – AN0
MOVWF ADCON0
CALL DELAY ; Acquisition time
BSF ADCON0,1 ; Start conversion
WAIT BTFSC ADCON0,1 ; See if conversion is complete, if not
GOTO WAIT ; continue
MOVF ADRESH,0 ; Load the result (only MSB) into W
MOVWF ADVALUE ; and finally in ADVALUE register.
MOVLW D’128’ ; Load a value and subtract it from the
SUBWF ADVALUE,0 ; ADVALUE
BTFSC STATUS,0 ; See if less than predetermined value,
GOTO BEGIN ; If not, continue conversion.
BSF GPIO,5 ; if yes, turn on LED
DELAY NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RETURN
END