#### osman6464

##### Newbie

how can I fix this ?

how can I add a subprogram for interrup?

thanks for your help.

here is my code:

Code:

```
#include <htc.h>
#include <stdio.h>
#include "delay.h"
unsigned int
read_adc(void){
unsigned int val;
ADIF = 0;
GO_nDONE = 1;
while ( GO_nDONE || !ADIF ) continue;
val = ADRESL;
val += ((unsigned int)ADRESH * 256);
DelayMs(10);
return val;
} //
void main(void)
{
TRISA=0x01;
TRISC=0x00;
PORTC=0x00;
PCFG3=1;
PCFG2=1;
PCFG1=1;
PCFG0=0;
ADFM=1;
ADON=1;
CHS2=0;
CHS1=0;
CHS0=0;
ADCS1=1;
ADCS0=1;
ADIF=0;
ADIE=1;
PEIE=1;
GIE=1;
CCP1X=1;
CCP1Y=1;
T2CKPS1=0;
T2CKPS0=0;
TOUTPS3=1;
TOUTPS2=1;
TOUTPS1=0;
TOUTPS0=0;
CCP1M0=0;
CCP1M1=0;
CCP1M2=1;
CCP1M3=1;
TMR2ON=1;
while(1)
{
unsigned int adc_val;
float i;
adc_val = read_adc();
i = (249./1023)*adc_val;
CCPR1L=i;
PR2=249;
DelayMs(50);
}
}
```

View attachment ADC ile PWM PROJE ödevi.X.rar