Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC

Status
Not open for further replies.

YAN-1

New Member
Hi. I am trying to operate the A-to-D module in the 16F877A for the first time. For some reason, I am not getting a result. Here is my code. As you can see, I am trying to get the resulting 10-bit digtial number and light 10 LEDs (RB0-RB7 and RD0-RD1). Please help. (the analog input to channel 0 is the output of a potentiometer powerd from Vdd)

LIST P=16F877A
#INCLUDE "P16F877A.INC"

ORG 0x0000
bcf STATUS, RP1
bsf STATUS, RP0

movlw b'00000000'
movwf TRISB

movlw b'00000000'
movwf TRISD

movlw b'00000001'
movwf TRISA

bcf TRISE,4


bcf ADCON1,0
bsf ADCON1,1
bsf ADCON1,2
bsf ADCON1,3

bcf ADCON1,6

bsf ADCON1,7

bcf STATUS, RP1
bcf STATUS, RP0

bcf ADCON0,3
bcf ADCON0,4
bcf ADCON0,5
bcf ADCON0,6
bsf ADCON0,7

bsf ADCON0,0

call delay

clrf PORTB

main

bsf ADCON0,GO ; start conversion

check

btfsc ADCON0,GO
goto check

bsf STATUS, RP0
movlw ADRESL
movwf PORTB
bcf STATUS, RP0
movlw ADRESH
movwf PORTD


goto main

end
 
Well I saw the tutorial and I think I understand everything. But I think there is something wrong with the way I am checking for the end of the conversion process. Can you please check that part of my program?
 
YAN-1 said:
Well I saw the tutorial and I think I understand everything. But I think there is something wrong with the way I am checking for the end of the conversion process. Can you please check that part of my program?

The only thing that 'jumps out' is the label "GO", my tutorial uses the label "GO_DONE" - this is the one in the MicroChip include file for the 877, I wouldn't have thought they have changed it for the 877A?.
 
Well either way, I am not getting any errors upon buiding the program. But still only the most significant bit (the 10th LED) is on regardless of the analog input. How do I know the ADC is converting in the first place?
 
Nigel Goodwin said:
YAN-1 said:
Well I saw the tutorial and I think I understand everything. But I think there is something wrong with the way I am checking for the end of the conversion process. Can you please check that part of my program?

The only thing that 'jumps out' is the label "GO", my tutorial uses the label "GO_DONE" - this is the one in the MicroChip include file for the 877, I wouldn't have thought they have changed it for the 877A?.

Don't worry. Both "GO" and "GO_DONE" are defined in the latest include files

Some coding errors:

Code:
    bsf STATUS, RP0 
    movf ADRESL,W     ; was movlw ADRESL
    bcf STATUS, RP0    ; moved ahead
    movwf PORTB 
    movf ADRESH,W     ; was movlw ADRESH 
    movwf PORTD
 
OH MY GOD!! OH MY GOD!! OH MY GOD!!
I can't believe I made those mistakes!! Thank you so much for going through the trouble of reading my code. I corrected it and now it is working perfectly. You just saved me hours because I was about to read a 60-page pdf file trying to start from scratch!! Thanks again
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top