• 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 not working properly

Not open for further replies.


New Member
whilst the compiling is successful, when put to the proteus simulation, it is not working as required. can someone help me to find the fault? could it be something regarding the tris bits? but i dont know whats the problem with that.
code is shown below

#include <pic.h>
 unsigned int itime;
 void delay (unsigned char itime);
 void main (void)
 TRISA=0b10000000;    //RA0 input for analog
 TRISC=0b11000000; //RC0, RC1 are set as outputs
 TRISD=0x11111111;    //D is set as output
 //bit7:ADFM:right justified
 //bit6-4:unused, read as 0
 //bit3-0:all ports configured as analog channels
 //bit5-3:using analog channel RA0/AN0
 //bit2:ADON not on
 //bit0: ADON converter module is operating
 //GODONE=1;    //start converting ***ADGO=1
 void delay (unsigned char itime)
     unsigned int i,j;
I don't know C, but unless things are reversed in the language/compiler there are some errors on the TRIS settings.

Most things I've ever encountered go MSB ---->>> LSB as you read it from right to left.

In actuality it looks like you have PORTA.7 set as in input, and all others as output, with a similar problem on TRISB. As an aside, you've got TRISD set to all input even though your comment shows them as outputs.

Plus you only list 7 bits (not 8) on your ADCON0 register.


Well-Known Member
TRISD=0x11111111; //D is set as output
this actualy sets the TRIS reg to input

for out put you need TRISD=0x00; //D is set as output

TRISA=0b10000000; //RA0 input for analog

this is also wrong and should be TRISA=0b00000001; //RA0 input for analog

a couple of things i noticed as well is you have confused input and output on the TRIS reg think of it like this 0=0ut 1 =1nput
also try not to mix your number bases it might be easier to use 0b rather than 0x
as wouldbeinventor says bit 0 of a port is on the right and bit 7 on the left 76543210
Not open for further replies.

EE World Online Articles