Need help badly please

Discussion in 'Embedded Systems and Microcontrollers' started by ELTnovice, Dec 16, 2009.

  1. ELTnovice

    Thread Starter New Member

    Dec 16, 2009
    2
    0
    Im doing a project containing AD conversions...basically I have a Microphone running thru a 741 op Amp chip and then into a Pic16f877, out to som LEDS...Basically whats supposed to happen is I speak into the mic and the LED is to act as a sound meter bridge.

    here's a picture....
    [​IMG]

    My LED ports are hooked into PORTD of my pic16 the port numbers are 19, 20, 21, 22, 27, 28, 29, 30....

    My Mic is hooked into PORTA pin number 2

    What I want is for the signal from portA to display on the LEDs in portD

    I know i have a signal coming from the mic becuase i hooked up a oscillator to the output to show me the voltage wave forms.

    heres my code so far, PLEASE HELP ME IF IM WRONG
    Thankyou...

    THANKS TO ALL WILL CONTRIBUTE
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I think you may have a problem in this section. You need to put the movwf instruction in between the bank 1 and bank 0 lines (and also get rid of the duplication).
    I would replace the whole section with:
    bsf STATUS, 5 ;bank 1
    clrf TRISD
    bcf STATUS, 6 ;bank 0

     
    Last edited: Dec 16, 2009
  3. ELTnovice

    Thread Starter New Member

    Dec 16, 2009
    2
    0
    I put in your suggestion and still no luck, do u suggest anything else, ive been working on this code for hours, trying to google and everything but no luck...

     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I had another look and I missed a few things the first time. I've edited and made corrections everywhere you see xxx in the below. I think it works now but I may have missed something else.
    ps. use the code quote (icon is #) and it keeps the indenting.

    Code ( (Unknown Language)):
    1.     list p=16f877
    2. #include <p16f877.inc>
    3.  
    4.  
    5. Count1 equ 0x31        ;xxx moved to start
    6.  
    7.     org 0x00
    8.     goto Start
    9.     org 0x04 ;interupt reset address
    10.     call ISR    ;xxx can't be goto otherwise stack will overflow
    11.  
    12. Start
    13. ;    movlw B'00000000' ;PORTD = output    xxx removed -duplicate
    14. ;    movwf TRISD
    15.     bsf STATUS,5 ;bank 1
    16.     clrf TRISD
    17.     clrf ADCON1 ;left justified, all inputs a/d    xxx moved ADCON1 in bank 1
    18.     bcf STATUS,5        ;xxx not STATUS, 6 back to bank 0
    19.  
    20.  
    21.     movlw B'01000001' ;Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
    22.     movwf ADCON0
    23.    
    24. Main
    25.     call Anadigi
    26.     goto Main
    27.    
    28.  
    29. Anadigi
    30.     bsf ADCON0,2 ;Start A/D conversion
    31. checkADcomplete
    32.     btfsc ADCON0,2 ;Wait for conversion to complete
    33.     goto checkADcomplete        ;xxx loop until AD done
    34.     movf ADRESH,W ;write A/D result to PORTD
    35.     movwf PORTD ;LEDs
    36.     return
    37.  
    38.  
    39. ;xxx Interrupts are not enabled - this doesen't get called.
    40. ;Anadigi does the same job anyway and AD conversion only
    41. ; takes about 10 instruction cycles so not really worth using interrupt
    42. ISR
    43.     movfw ADRESH ;moves results into register
    44.     movwf Count1
    45.     bcf PIR1, ADIF ; reset int.
    46.     bsf ADCON0,2
    47.     retfie
    48.  
    49.    
    50.     end
    51.  
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    You probably know this but you won't get a level reading on the LEDs, because you are just outputting the binary value to the bargraph. Some more conversion will be required to get a nice output.
     
Loading...