PIC16f877a ADC RESULT SHOING ON 7 SEGMENT
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2018
    Posts
    2

    Post PIC16f877a ADC RESULT SHOING ON 7 SEGMENT

    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

  2. #2
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,043

    Default Re: PIC16f877a ADC RESULT SHOING ON 7 SEGMENT

    It looks ok, but the ADRESH register wouldn’t be any kind of BCD. It’s just a binary value.
    So between ports B & D, it’s outputting the 10 bit binary value.
    The 7447 could display some values that aren’t decimal, such as spaces and symbols for input values greater than 9 on it’s 4 bit port..
    This is also a Pic BASIC forum.

Similar Threads

  1. Replies: 4
    Last Post: - 9th April 2018, 22:55
  2. Converting 10bit ADC result to 8 bit
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 5th March 2012, 20:38
  3. Timer0 Reload based on ADC result
    By Cyborg in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd February 2011, 07:11
  4. 7 segment display with PIC16F877A 20MHZ
    By freqout in forum General
    Replies: 2
    Last Post: - 8th April 2008, 14:31
  5. PBP 16-bit ADC result math
    By sonic in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2005, 14:21

Members who have read this thread : 19

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts