Bonjour,
je veux faire une comparaison entre deux tension analogique en utilisant Pic 16f877 et faire allumer la LED qui correspant a la condition
le code : sous PWC (PIC C)
merci de m'aider svpCode:#include <16F877.h> #device ADC = 8 //8-bit coversion #use delay(clock = 4000000) #use rs232(baud = 9600, xmit = PIN_D0, rcv = PIN_D1) //LCD output void main() //************************************************* { float vin0,vin1; // Input variable setup_adc(ADC_CLOCK_INTERNAL); // ADC clock setup_adc_ports(AN0); setup_adc_ports(ALL_ANALOG); // Input combination for(;;) { //set_tris_a(0x11); //set_tris_d(0x00); //delay_ms(500); set_adc_channel(0); // Select RA0 delay_ms(2); vin0 = read_adc(); //Get input byte //vin0 = (vin0*5/255); //Convert to ASCII set_adc_channel(1); delay_ms(2); vin1 = read_adc(); //Get input byte //vin1 = (vin1*5/255) ; //Convert to ASCII //putc(254); putc(1); delay_ms(10); // Clear screen //printf( " Input = " ); putc(vin0); // Display input if (vin0<vin1) { output_high(PIN_D0);// led red } else if (vin0>vin1) { output_high(PIN_D1);// led yellow } else { output_high(PIN_D2);// led bleu } } }
-----