Hello All
I am facing problem with MPLAB IDE pic kit2. in that iam trying to build prog with 16f876 , but it is saying error , saying driver error .
My program attached , please any one help me generate HEX FILE .
...MADHU.
#include<16f876.h>
#DEVICE*=16 ICD=TRUE
#use Delay(Clock=20000000)
#use RS232(Baud=9600,Xmit=PIN_C6,Rcv=PIN_C7,brgh 1 ok)
float average_ad(byte chan){
int i,avg_num=32;
float avg=0,temp_avg=0;
set_adc_channel(chan);
delay_us(100);
for(i=1;i<=avg_num;++i){
avg+=read_adc();
delay_us(100);
}
return(avg/avg_num);
}
void pwm1_duty100(long pwm_percent,long pwm_maximum){
set_pwm1_duty((pwm_maximum/100)*pwm_percent);
}
main()
{
CONST float CHARGED=14.4;
CONST long NDELTA=-1;
CONST byte AMP_CHAN=0,BAMP_CHAN=3,BVOLT_CHAN=2,VOLT_CHAN=1;
float current,voltage,watts=0.0,old_watts=0.0;
float batamps,batvolts,batwatts;
float temp_watts,watts100,amp100,volt100;
long delta=1,pwm_max,pwm100;
long boost=0,boost_counter;
byte led_count=0;
output_low(PIN_C3);
setup_port_a(ALL_ANALOG);
setup_adc(adc_clock_div_32);
setup_timer_2(T2_DIV_BY_1,49,1);
setup_ccp1(CCP_PWM);
pwm_max=200;
pwm100=85;
pwm1_duty100(pwm100,pwm_max);
output_high(PIN_C3);
output_high(PIN_C0);
delay_ms(1000);
while(TRUE){
if(batvolts>CHARGED){
delta=NDELTA;
output_high(PIN_C5);
}
else if(old_watts>watts){
delta=-delta;
output_low(PIN_C5);
}
old_watts=watts;
pwm100+=delta;
if(pwm100>100)pwm100=100;
else if(pwm100<0)pwm100=0;
pwm1_duty100(pwm100,pwm_max);
current=average_ad(AMP_CHAN)/40.885;
voltage=average_ad(VOLT_CHAN)/18.2887;
batamps=average_ad(BAMP_CHAN)/41.3428;
batvolts=average_ad(BVOLT_CHAN)/20.4831;
watts=current*voltage;
batwatts=batamps*batvolts;
if((++boost_counter%20)==0){
pwm1_duty100(100,pwm_max);
delay_ms(20);
amp100=average_ad(AMP_CHAN)/40.885;
volt100=average_ad(VOLT_CHAN)/18.2887;
if(amp100<0.05){
output_high(PIN_C4);
output_low(PIN_C3);
delay_ms(1000);
}
watts100=amp100*volt100;
temp_watts=watts/watts100;
boost=(long)((temp_watts*100)-100);
}
printf("%lu%6.2f%6.2f%6.2f%6.2f%6.2f%6.2f%li%6.2f\r\n",pwm100,current,voltage,watts,batamps,batvolts,batwatts,boost,watts100);
output_bit(PIN_C0,(++led_count&0x01));
delay_ms(500);
}
}