salman.
Member level 1
- Joined
- Jul 30, 2012
- Messages
- 40
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,591
while(ADCON0.GO!=0);
while(ADCON0.GO == 1)
ADCON0.GO = 0
unsigned int value;
void main()
{
TRISA = 0x01;
TRISB = 0x00;
TRISD = 0x00;
ADCON0 = 0x81;
ADCON1 = 0x8E;
CMCON = 0x07;
CVRCON.CVROE = 0;
do{
ADCON0.F2=1;
while(ADCON0.GO==1);
ADCON0.GO = 0;
value=((ADRESL)|(ADRESH<<8));
switch (value)
{
case 102:
PORTB=0b10000000;
break;
case 204:
PORTB=0b11000000;
break;
case 306:
PORTB=0b11100000;
break;
case 307:
PORTB=0b11100000;
break;
case 409:
PORTB=0b11110000;
break;
case 511:
PORTB=0b11111000;
break;
case 512:
PORTB=0b11111000;
break;
case 613:
PORTB=0b11111100;
break;
case 614:
PORTB=0b11111100;
break;
case 716:
PORTB=0b11111110;
break;
case 818:
PORTB=0b11111111;
break;
case 920:
PORTD=0b10000000;
PORTB=0b11111111;
break;
case 921:
PORTD=0b10000000;
PORTB=0b11111111;
break;
case 1023:
PORTD=0b11000000;
PORTB=0b11111111;
break;
default:
PORTD=0b00000000;
PORTB=0b00000000;
}
}while(1);
}
case 511:
PORTB=0b11111000;
break;
ADCON0.GO=1;
while(ADCON0.GO==1);
//value=((ADRESL)|(ADRESH<<8));
can you post the .hex and .cof files?
Try thisCode:unsigned int value; void main() { TRISA = 0x01; TRISB = 0x00; TRISD = 0x00; ADCON0 = 0x81; ADCON1 = 0x8E; CMCON = 0x07; CVRCON.CVROE = 0; do{ ADCON0.F2=1; while(ADCON0.GO==1); ADCON0.GO = 0; value=((ADRESL)|(ADRESH<<8)); switch (value) { case 102: PORTB=0b10000000; break; case 204: PORTB=0b11000000; break; case 306: PORTB=0b11100000; break; case 307: PORTB=0b11100000; break; case 409: PORTB=0b11110000; break; case 511: PORTB=0b11111000; break; case 512: PORTB=0b11111000; break; case 613: PORTB=0b11111100; break; case 614: PORTB=0b11111100; break; case 716: PORTB=0b11111110; break; case 818: PORTB=0b11111111; break; case 920: PORTD=0b10000000; PORTB=0b11111111; break; case 921: PORTD=0b10000000; PORTB=0b11111111; break; case 1023: PORTD=0b11000000; PORTB=0b11111111; break; default: PORTD=0b00000000; PORTB=0b00000000; } }while(1); }
ADCON0.GO=1;
while(ADCON0.GO==1);
ADCON0.GO = 0;
2.5V means 511d or 0x1FF or 111111111
So you are getting right value for 511d but you make PORTB = 11111000 if value = 1111111111
So F8 is the right value for your code.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?