Bonjour j'ai récupérer un programme de pic 16F873 sur internet, par contre je ne sais pas avec quel compilateur je pourrai le compiler !!
mon code est ci dessous:
#include "16f873.h"
#include "math24f.h"
#define num1 1012
#define num2 1022
uns8 duty, mcount, ncount;
float V_batt, Vin1_S1, Vin2_S1, Iin1_S1, Iin2_S1, G_S1, dI_S1, dV_S1, dG_S1, ero;
void int_pwm(void){
TRISC = bin(00110000);
PORTC.1 = 0; // port c2 output (CCP1, PWM1)
PIE1.1 = 0; // disable timer 2 interrupts
PIE1.2 = 0; // disable ccp1 interrupts
CCP1CON = 0; // CCP1 module off
PR2 = 0b.0011.1110; // load period register (62)
CCP1CON.5 = 0;
CCP1CON.4 = 0;
duty = 0b.0001.1111; // set duty cycle
CCPR1L = 0b.0001.1111;
T2CON = bin(00000000); // prescaler 1:1
TMR2 = 0; // timer 2 off
CCP1CON = bin(00001100); // ccp1 pwm mode, ccp1 module on
}
void delay_20us (void){
char count = 0x07;
loop:
if (-- count == 0){
return;}
else goto loop;
}
void delay_100ms(void){
char mcount = 0x4f; // M counter = 256
loadn:
char ncount = 0x4f; // N counter = 256
decn:
while (-- ncount > 0){
goto decn;}
while (-- mcount > 0){
goto loadn;}
return;
}
void delay_200ms(void){
char mcount = 0xff; // M counter = 256
loadn:
char ncount = 0xff; // N counter = 256
decn:
while (-- ncount > 0){
goto decn;}
while (-- mcount > 0){
goto loadn;}
return;
}
void int_adc (void){
TRISA =bin(00011111); // inputs/outputs
ADCON1 = bin(10000000); // PortA, bit1,0 analog input
}
void incduty(void){ // Increment the duty ratio by 1
W = 60 - duty;
while (STATUS.2 == 1){
return;}
duty = duty +1;
CCPR1L = duty;
return;
}
void decduty(void){ // decrement the duty ratio by 1
W = 0x2 - duty;
while (STATUS.2 == 1){
return;}
duty = duty -1;
CCPR1L = duty;
return;
}
void start_conv(void){
delay_20us();
ADCON0.2 = 1; // start conversion
test:
if ( ADCON0.2 == 1){ // test go/done bit, conversion
finish?
goto test;}
delay_100ms();
return;
}
void get_measure_batt (void){
V_batt.low8 = ADRESL;
V_batt.mid8 = ADRESH; // conversion complete get A/D
result
}
void get_Vin1_S1 (void){
Vin1_S1.low8 = ADRESL;
Vin1_S1.mid8 = ADRESH; // conversion complete get A/D
result
}
void get_Iin1_S1 (void){
Iin1_S1.low8 = ADRESL;
Iin1_S1.mid8 = ADRESH; // conversion complete get A/D
result
}
void get_Vin2_S1 (void){
Vin2_S1.low8 = ADRESL;
Vin2_S1.mid8 = ADRESH; // conversion complete get A/D
result
}
void get_Iin2_S1 (void){
Iin2_S1.low8 = ADRESL;
Iin2_S1.mid8 = ADRESH; // conversion complete get A/D
result
}
void test1 (void){
if(Iin2_S1 == Iin1_S1 ){
return;}
if (Iin2_S1 > Iin1_S1){
incduty();
return;}
if (Iin2_S1 < Iin1_S1){
decduty();
return;}
}
void test2 (void){
if ( dG_S1 == G_S1 || ero <= 0.01){
delay_100ms();
return;}
if ( dG_S1 < G_S1){
decduty();
return;}
if ( dG_S1 > ero){
incduty();
return;}
}
void measure_batt(void){
ADCON0 = bin(01101001); // select conversion clock = 8, AN0
on
start_conv();
get_measure_batt();
}
void main (void){
int_pwm();
T2CON.2 = 1; // timer 2 on, pwm1 on
InitFpFlags();
int_adc();
measure_batt();
again:
if (V_batt >= num1 || V_batt <= num2){ // measuring the battery voltage
delay_200ms;
goto again;} // do nothing PWM module off
ADCON0 = bin(01000001); // select conversion clock = 8, AN0
on
start_conv();
get_Vin1_S1();
ADCON0 = bin(01001001); // select conversion clock = 8, AN1
on
start_conv();
get_Iin1_S1();
while(1){
char n;
for (n =0; n <256; n++){ // looping for a while
ADCON0 = bin(01000001); // select conversion clock = 8, AN0
on
start_conv();
get_Vin2_S1();
ADCON0 = bin(01001001); // select conversion clock = 8, AN1
on
start_conv();
get_Iin2_S1();
G_S1 = Iin2_S1 / Vin2_S1;
dV_S1 = Vin2_S1 - Vin1_S1;
dI_S1 = Iin2_S1 - Iin1_S1;
dG_S1 = dI_S1 / dV_S1;
ero = dG_S1 + G_S1; // error margin
if (ero<0)
ero = -ero;
if (dV_S1 < 0 ){
test2();
goto swapIV;
}
if(dV_S1 >= 0){
test1();
}
swapIV:
Iin1_S1 = Iin2_S1;
Vin1_S1 = Vin2_S1;
}
if (n == 255){ // break the while loop and go
break;} // back to measure battery voltage
}
}
pouvez vous m'aider svp ?
-----