adresl adresh
chwoei said:
hi everyone,
i got some problem in getting the values in c programming for analog to digital input for PIC16F877A. Do anyone knows how to get the values when a infrared sensor(analog) is converted in Digital values? how to set the ports or any alogorithms needed in programing to get the values when different distance is detected.
Hope someone good in PIC could help!!
... hope to hear from u guys soon..
Kind regards,
CHANG
This code for CSS c compiler
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif
void main() {
int i, value, min, max;
printf("Sampling:");
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
do {
min=255;
max=0;
for(i=0; i<=30; ++i) {
delay_ms(100);
value = Read_ADC();
if(value<min)
min=value;
if(value>max)
max=value;
}
printf("\n\rMin: %2X Max: %2X\n\r",min,max);
} while (TRUE);
}
i hope it can help you