#include <16f877.H>
#fuses xt,noPROTECT,noWDT,noPUT,noBROWNOUT,nolvp,nowrt
#use delay(clock=10000000)
#use standard_io(a) // set io port a
#use standard_io(b) // set io port b
#use standard_io(c) // set io port c
#use standard_io(d) // set io port d
#use rs232(baud=9600, xmit=pin_c6, rcv=pin_c7) // set rs232 port
main(){
int value; // aset up storage in memory
setup_port_a(ALL_ANALOG); // se port a to all analoges
setup_adc(adc_clock_div_2); // set up adc
setup_timer_2(T2_div_by_4,0xc0,2); // initialize timer 2
setup_ccp1(ccp_pwm); // capture compair pwm on ccp1 (C1)
while (1) // all ways
{
set_adc_channel(0); // adc A0
delay_us (5); // delay 5 us
value= read_adc(); // point to value(store input from A0)
delay_ms (100); // delay 100 ms
if(value >= 190) // if A0 >=190 Store 190
{
value = 190;
}
if(value<=90) // if A0 <=90 Store 90
{
value = 90;
}
set_pwm1_duty(value); // depending on value set pwm output (C1)
delay_ms(10); //// delay 10 ms
}
}