bu yazdığım programla picde pwm oluşturuyırum.butonla arıtırıp azaltıyorum
#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT, NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)
#use fast_io(c)
#use fast_io(e)
#define use_portb_lcd TRUE
#include <lcd.c>
int i=2;
int32 j=65;
int32 k;
float f,s;
void main()
{
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_1(T1_DISABLED);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
set_tris_a(0x0f);
set_tris_c(0x00);
set_tris_e(0x0f);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,j,1);
set_pwm1_duty(i);
set_pwm2_duty(i);
lcd_init();
printf(lcd_putc,"\ffreq=");
printf(lcd_putc,"\nduty=");
while(1)
{
j=j+1;
k=4*j*16;
f=4000000/k;
lcd_gotoxy(6,1);
printf(lcd_putc,"%f",f);
j=j-1;
s=i*1.562;
lcd_gotoxy(6,2);
printf(lcd_putc,"%f",s);
if(input(pin_a0))
{
delay_ms(20);
while(input(pin_a0));
i+=2;
if(i>64)
i=64;
set_pwm1_duty(i);
}
if(input(pin_a1))
{
delay_ms(20);
while(input(pin_a1));
i-=2;
if(i<2)
i=2;
set_pwm1_duty(i);
set_pwm2_duty(i);
}
if(input(pin_a2))
{
i=10;
set_pwm1_duty(i);
delay_ms(20);
while(input(pin_a2));
j+=5;
if(j>250)
j=250;
setup_timer_2(T2_DIV_BY_16,j,1);
}
if(input(pin_a3))
{
i=10;
set_pwm1_duty(i);
delay_ms(20);
while(input(pin_a3));
j-=5;
if(j<65)
j=65;
setup_timer_2(T2_DIV_BY_16,j,1);
}
}
}