Hi,
I am trying to perform analog to digital conversion on PIC16f877a. well the problem is when I am showing my result on led it working fine but when I am showing my result on 7 segment I have some invalid output may be I am unable to convert binary to decimal properly **("for BCD conversion I am using 74ls47")** can any one help me.
Regards,
Haziq.





RES_VECT CODE 0x0000 ; processor reset vector
GOTO START ; go to beginning of program

; TODO ADD INTERRUPTS HERE IF USED
CNT0 EQU 0x21 ;

MAIN_PROG CODE ; let linker place main program

START

BSF STATUS,RP0
MOVLW b'00000000'
MOVWF TRISB
MOVLW b'11110000'
MOVWF TRISD
MOVLW b'00000001'
MOVWF TRISA
BCF STATUS,5

MAIN_LOOP
CALL ADC_INIT ;INIT ADC MODULE
CALL ADC_READ ;READ ANALOG VALUE AND STORE TO ANVAL REGISTER

;OUTPUT ANVAL TO
;==================================
GOTO MAIN_LOOP
;================================================= =======================================
ADC_INIT
BSF STATUS,RP0 ;SELECTING BANK 01 FOR ADCON1 REG
MOVLW b'00001110' ;LEFT JUSTIFIED, FOcs/8, +VREF=VDD, -VREF=VSS,
AN0=ANALOG
MOVWF ADCON1
BCF STATUS,5 ;GOING BACK TO BANK 00
MOVLW b'010000001' ;FOcs/8, A0=ANALOG INPUT,
MOVWF ADCON0
RETURN
;================================================= ========================================
ADC_READ
BCF STATUS,5 ;SELECTING BANK 00
BSF ADCON0, 2 ;START CONVERTION PROCESS (WE SET THE GO BIT)
WAIT:
BTFSC ADCON0, 2
GOTO WAIT ;WAIT FOR CONVERTION TO FINISH (WAIT FOR GO BIT TO CLEAR)
MOVF ADRESH, W ;MOVE ADRESH TO W
MOVWF PORTB ;SHOWING 8 MOST SIGNIFICANT BITS OF A/D RESULT
MOVLW 0x06
MOVWF CNT0
AGAIN_0:
BCF STATUS, C ;WE WANT SHIFT (NOT ROTATE), SO WE CLEAR CARRY
RLF ADRESL, 1 ;SHIFT LEFT 6 BITS A/D RESULT HIGH BYTE
DECFSZ CNT0
GOTO AGAIN_0
MOVF ADRESL, W ;MOVE ADRESH TO W
MOVWF PORTD ;SHOWING 2 LEAST SIGNIFICANT BITS OF A/D RESULT
RETURN

END