Hi there...
I use 18F4550 pic...
how can I record two values of different resistors using one adc channel (AN2) ??
I use the programming while loop and if loop, neither of them working.. whenever i run the program and write it to the pic, it don't follow the sequence of the program, it will execute the condition while loop even though it is wrong... I don't know what to do now. I'm really want to apologise because of this noob question. I am beginner in microprocessor.
so this is my code
I use 18F4550 pic...
how can I record two values of different resistors using one adc channel (AN2) ??
I use the programming while loop and if loop, neither of them working.. whenever i run the program and write it to the pic, it don't follow the sequence of the program, it will execute the condition while loop even though it is wrong... I don't know what to do now. I'm really want to apologise because of this noob question. I am beginner in microprocessor.
so this is my code
Code:
#include <18F4550.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#device ADC=10
#use delay(clock=20000000)
#include <Flex_lcd.c>
#USE FAST_IO(B)
void main()
{
set_tris_b(0x0f);
unsigned int16 adcValue, adcValue1;
float volt;
float volt1;
float load1, load;
lcd_init();
setup_adc_ports(ALL_ANALOG); // set all into analog
setup_adc(ADC_CLOCK_INTERNAL); // Use internal ADC clock.
set_adc_channel(2);
while(1)
{
lcd_gotoxy(1,1);
output_low(PIN_B6);
delay_us(50);
set_adc_channel(2);
adcValue = read_adc(); // Get ADC reading
delay_us(50); // Delay for sampling cap to charge
volt=5.0*((float)adcValue/1023);
volt=(5.00/volt)-1;
load1=(float)10000/volt;
printf(lcd_putc,"Resistor : %f",load1);
delay_ms(100);
while(input(pin_b1)!=1)
{
delay_us(50);
output_high(PIN_B6);
lcd_gotoxy(1,2);
delay_us(50);
dcValue = read_adc(); // Get ADC reading
delay_us(50); // Delay for sampling cap to charge
volt=5.0*((float)adcValue/1023);
volt=(5.00/volt)-1;
load1=(float)10000/volt;
printf(lcd_putc,"Resistor : %f",load1);
}
}
}