Status
Not open for further replies.

#### maria258

##### 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.
thanks
code is shown below

Code:
#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

//bit3-0:all ports configured as analog channels

//bit7-6:Fosc/2
//bit5-3:using analog channel RA0/AN0
//bit1:unimplemented
//bit0: ADON converter module is operating

while(1)
{
delay(100);
//while(GO);
delay(100);
}
}

void delay (unsigned char itime)
{
unsigned int i,j;

for(i=0;i<itime;i++)
for(j=0;j<200;j++);
}

#### wannaBinventor

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

#### ghostman11

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

Status
Not open for further replies.