i wrote a little code to measure varience of a LDR connected to A0 and run a motor.but its not working.can some one point me the error.
i used 16F877A with 4MHz crystal,CCS C .
do i have to give ref voltages also
#include "D:\PIC C codes\16F877A\sensor+pwm\sensor+pwm.h"
int x=0,y=0;
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,99,1);
setup_ccp1(CCP_PWM);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
set_adc_channel(0);
while(1)
{
delay_ms(10);
x=read_adc();
y=(x*100)/255;
output_high(PIN_B0);
output_high(PIN_C1);
set_pwm1_duty(y);
if(x<=256)
{
output_high(PIN_B1);
}
else
{
output_high(PIN_B2);
}
}
}