Need help badly please

Thread Starter

ELTnovice

Joined Dec 16, 2009
2
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....


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...

list p=16f877
#include <p16f877.inc>

org 0x00
goto Start
org 0x04 ;interupt reset address
goto ISR

Start
MOVLW B'00000000' ;PORTD = output
MOVWF TRISD
bsf STATUS, 5 ;bank 1
bcf STATUS, 6 ;bank 0
movlw H'00'
movwf TRISD ;portd outputs
clrf ADCON1 ;left justified, all inputs a/d
bcf STATUS, 5 ;bank 0
movlw B'01000001' ;Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
movwf ADCON0

Main
call Anadigi
goto Main

Anadigi
bsf ADCON0,GO ;Start A/D conversion
btfsc ADCON0,GO ;Wait for conversion to complete
movf ADRESH,W ;write A/D result to PORTD
movwf PORTD ;LEDs
return

ISR
movfw ADRESH ;moves results into register
movwf Count1
bcf PIR1, ADIF ; reset int.
bsf ADCON0,2
retfie

Count1 equ 0x30

end
THANKS TO ALL WILL CONTRIBUTE
 

Markd77

Joined Sep 7, 2009
2,806
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

MOVLW B'00000000' ;PORTD = output
MOVWF TRISD
bsf STATUS, 5 ;bank 1
bcf STATUS, 6 ;bank 0
movlw H'00'
movwf TRISD ;portd outputs
 
Last edited:

Thread Starter

ELTnovice

Joined Dec 16, 2009
2
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...

list p=16f877
#include <p16f877.inc>

org 0x00
goto Start
org 0x04 ;interupt reset address
goto ISR

Start
movlw B'00000000' ;PORTD = output
movwf TRISD
bsf STATUS,5 ;bank 1
clrf TRISD
bcf STATUS,6
clrf ADCON1 ;left justified, all inputs a/d
bcf STATUS,5 ;bank 0
movlw B'01000001' ;Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
movwf ADCON0

Main
call Anadigi
goto Main

Anadigi
bsf ADCON0,2 ;Start A/D conversion
btfsc ADCON0,2 ;Wait for conversion to complete
movf ADRESH,W ;write A/D result to PORTD
movwf PORTD ;LEDs
return
ISR
movfw ADRESH ;moves results into register
movwf Count1
bcf PIR1, ADIF ; reset int.
bsf ADCON0,2
retfie
Count1 equ 0x31

end
 

Markd77

Joined Sep 7, 2009
2,806
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.

Rich (BB code):
    list p=16f877
#include <p16f877.inc>


Count1 equ 0x31        ;xxx moved to start

    org 0x00
    goto Start
    org 0x04 ;interupt reset address
    call ISR    ;xxx can't be goto otherwise stack will overflow

Start
;    movlw B'00000000' ;PORTD = output    xxx removed -duplicate
;    movwf TRISD
    bsf STATUS,5 ;bank 1
    clrf TRISD
    clrf ADCON1 ;left justified, all inputs a/d    xxx moved ADCON1 in bank 1
    bcf STATUS,5        ;xxx not STATUS, 6 back to bank 0


    movlw B'01000001' ;Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
    movwf ADCON0
    
Main
    call Anadigi
    goto Main
    

Anadigi
    bsf ADCON0,2 ;Start A/D conversion
checkADcomplete
    btfsc ADCON0,2 ;Wait for conversion to complete
    goto checkADcomplete        ;xxx loop until AD done
    movf ADRESH,W ;write A/D result to PORTD
    movwf PORTD ;LEDs
    return


;xxx Interrupts are not enabled - this doesen't get called.
;Anadigi does the same job anyway and AD conversion only
; takes about 10 instruction cycles so not really worth using interrupt
ISR
    movfw ADRESH ;moves results into register
    movwf Count1
    bcf PIR1, ADIF ; reset int.
    bsf ADCON0,2
    retfie

    
    end
 

Markd77

Joined Sep 7, 2009
2,806
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.
 
Top