ADC Not Working (Using PIC 16F877)

Status
Not open for further replies.

ipunished

Junior Member level 3
Hello,

Ive read the data sheet of PIC 16F877 and coded my microcontroller accordingly, but it does not appear to work. I am using sourceboost as my compliler.

Here is my code:

Code:
#include <system.h>
unsigned char inbyte;
void config(void);

void main(void)
{
config();
do{

}while(1);

}

{

do{

}

void config(void)
{
status |=0x20;
trisa=0xff;
trisb=0x00;
status &=0xdf;
}
ive set the registers accordingly, and Ive connected pin RA3 to Vref and RA0 is my analog input.

no matter what I do, the output value does not change and the adresl returned value is always 0.

Can anyone help me out here? Thank you

btbass

This line wont help a lot?

it selects channel 1 and turns the A/D off. (Maybe)

I think adcon1 should be 0x81 to right justify the result.

Last edited:

ipunished

Junior Member level 3
This line wont help a lot?

it selects channel 1 and turns the A/D off.
its c1, so it will set the adcon0 to 11000001.. which will select internal oscilator, choose 000 for channel selection, and turn A/D on..

correct me if im wrong please

btbass

I think adcon1 should be 0x81 to right justify the result.

ipunished

Junior Member level 3
i tried 0x81 as well, but that did not create any difference was still getting 0 as returned value

btbass

I don't think you need set and clear the STATUS bits, the compiler should take care of that.

Have you tried MPlab Sim and step through the code, use the watch window to look at the regs.

ipunished

Junior Member level 3
yeah, i know, i was just trying it out in hopes that it will work..at first the code was without the status registers, when it did not work i added them in =/

Status
Not open for further replies.