kudepadi
Newbie level 1
adc c programming
Guys, need help with my project. I intend to read the output of my ADC and output the value to a 7 segment LED display. The analog input i'm using is a DC 5v source. I want to display the voltage value on the 7-segment (i.e. 1v = 1, 2v=2...). I'm using a pic16f877A with Vdd (5v) as reference. I've tried using 'if' and 'else if' but i only managed to display '0' and '1' (voltage under 0.7v displays 0 while anything over that displays only 1). Here is my source code..
unsigned int temp;
void main()
{
ADCON1 = 0x80;
ADCON0 = 0x85;
TRISA = 0xFF;
TRISB = 0;
do {
temp = Adc_Read(0);
switch (temp) {
if (temp<0x8F) PORTB=0x3F;
else if (0x90<temp<0x15c) PORTB=0x06;
else if (0x15D<temp<0x229) PORTB=0x5B;
else if (0x230<temp<0x2F6) PORTB=0x4F;
else if (0x2F7<temp<0x3C2) PORTB=0x66;
else PORTB=0x6D;
}
while(1);
}
programming is done using mikroC. i use range(xx<temp<yy) for the adc value to enable the 7-segment to show a stable display. any help would be greatly appreciated.
Guys, need help with my project. I intend to read the output of my ADC and output the value to a 7 segment LED display. The analog input i'm using is a DC 5v source. I want to display the voltage value on the 7-segment (i.e. 1v = 1, 2v=2...). I'm using a pic16f877A with Vdd (5v) as reference. I've tried using 'if' and 'else if' but i only managed to display '0' and '1' (voltage under 0.7v displays 0 while anything over that displays only 1). Here is my source code..
unsigned int temp;
void main()
{
ADCON1 = 0x80;
ADCON0 = 0x85;
TRISA = 0xFF;
TRISB = 0;
do {
temp = Adc_Read(0);
switch (temp) {
if (temp<0x8F) PORTB=0x3F;
else if (0x90<temp<0x15c) PORTB=0x06;
else if (0x15D<temp<0x229) PORTB=0x5B;
else if (0x230<temp<0x2F6) PORTB=0x4F;
else if (0x2F7<temp<0x3C2) PORTB=0x66;
else PORTB=0x6D;
}
while(1);
}
programming is done using mikroC. i use range(xx<temp<yy) for the adc value to enable the 7-segment to show a stable display. any help would be greatly appreciated.