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
I am trying to drive an LED bar graph with the ADC of pic16f877a, I have written and compiled the code in mikroC but it does not simulates as it should on the proteus. I am sharing the code too please help me out.
I am using AN0 channel with Vref+ = Vdd and Vref-=Vss, with Left Justified scheme. I am also sharing the proteus simulation.
here is the code:
unsigned int value;
void main()
{
TRISA=0x01;
TRISB=0x00;
TRISD=0x00;
ADCON0=0x81;
ADCON1=0x0E;
do
{
ADCON0.F2=1;
while(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);
}
I am using AN0 channel with Vref+ = Vdd and Vref-=Vss, with Left Justified scheme. I am also sharing the proteus simulation.
here is the code:
unsigned int value;
void main()
{
TRISA=0x01;
TRISB=0x00;
TRISD=0x00;
ADCON0=0x81;
ADCON1=0x0E;
do
{
ADCON0.F2=1;
while(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);
}