derrick826
New Member
hi guys,
i have read the datasheet of the PIC16F877A from microchip regarding on the configuration of all the registers needed to program the ADC. i have used a potential resistor to vary different input voltages into my analogue pin RA0 starting from (0v - 4.80V) . my Vref+, voltage reference would be Vdd while Vref- would be Vss. The particular result which i get in ADRES is being displayed on 10 led lights to indicate that 10-bits are the result of the analogue being converted to digital. As i vary my pot , the results are in the following:
---------------9876543210
1v to pin RA0 = 0000000000
2v to pin RA0 = 0100000001
3v to pin RA0 = 1000000010
4v to pin RA0 = 1100000011
what may have gone wrong? how come the other LEDs of bit 7,6,5,4,3,2 is not lighting up? Must i use any component to fix to the pin RA0 of PIC16F877A?
here my coding:
org 0x000
goto start
int org 0x004
goto int
start
call initial
again
call startconv
call check
call result
goto again
initial
BCF STATUS,RP1
BSF STATUS,RP0
MOVLW b'00000001'
MOVWF TRISA
MOVLW b'00000000'
MOVWF TRISB
MOVLW b'00000000'
MOVWF TRISC
MOVLW b'00000000'
MOVWF TRISD
MOVLW b'10001110'
MOVWF ADCON1
BCF STATUS,RP1
BCF STATUS,RP0
MOVLW b'10000001'
MOVWF ADCON0
RETURN
startconv
BSF ADCON0,GO
RETURN
check
BTFSS PIR1,ADIF
goto check
MOVLW b'00000001'
MOVWF PORTC
BCF PIR1,ADIF
return
result
BCF STATUS,RP1
BSF STATUS,RP0
MOVFW ADRESL
MOVWF PORTB
BCF STATUS,RP1
BCF STATUS,RP0
MOVFW ADRESH
MOVWF PORTD
RETURN
END
Btw is there a specific calculation to get the digital values of 10bit?
what i know is this =
actual analogue voltage = [digital values in 10 bit (decimal)] * (5v/1023)
I dun really understand how this equation comes abt. I have read nigel-gwin's tutorial but still no improvement. Perhaps one to one attention right here might be a good help. thanks guys
i have read the datasheet of the PIC16F877A from microchip regarding on the configuration of all the registers needed to program the ADC. i have used a potential resistor to vary different input voltages into my analogue pin RA0 starting from (0v - 4.80V) . my Vref+, voltage reference would be Vdd while Vref- would be Vss. The particular result which i get in ADRES is being displayed on 10 led lights to indicate that 10-bits are the result of the analogue being converted to digital. As i vary my pot , the results are in the following:
---------------9876543210
1v to pin RA0 = 0000000000
2v to pin RA0 = 0100000001
3v to pin RA0 = 1000000010
4v to pin RA0 = 1100000011
what may have gone wrong? how come the other LEDs of bit 7,6,5,4,3,2 is not lighting up? Must i use any component to fix to the pin RA0 of PIC16F877A?
here my coding:
org 0x000
goto start
int org 0x004
goto int
start
call initial
again
call startconv
call check
call result
goto again
initial
BCF STATUS,RP1
BSF STATUS,RP0
MOVLW b'00000001'
MOVWF TRISA
MOVLW b'00000000'
MOVWF TRISB
MOVLW b'00000000'
MOVWF TRISC
MOVLW b'00000000'
MOVWF TRISD
MOVLW b'10001110'
MOVWF ADCON1
BCF STATUS,RP1
BCF STATUS,RP0
MOVLW b'10000001'
MOVWF ADCON0
RETURN
startconv
BSF ADCON0,GO
RETURN
check
BTFSS PIR1,ADIF
goto check
MOVLW b'00000001'
MOVWF PORTC
BCF PIR1,ADIF
return
result
BCF STATUS,RP1
BSF STATUS,RP0
MOVFW ADRESL
MOVWF PORTB
BCF STATUS,RP1
BCF STATUS,RP0
MOVFW ADRESH
MOVWF PORTD
RETURN
END
Btw is there a specific calculation to get the digital values of 10bit?
what i know is this =
actual analogue voltage = [digital values in 10 bit (decimal)] * (5v/1023)
I dun really understand how this equation comes abt. I have read nigel-gwin's tutorial but still no improvement. Perhaps one to one attention right here might be a good help. thanks guys
Last edited: