Hail to thee;
I'm utterly beginner in C programming, and i made two codes using MikroC PRO, and i'm seeking out your help to make the two of them working in the main time.
the first code is just an A/D conversion and display the result on an LCD. with some conditions on account of commanding a DC FAN and LEDs.
the second code (and this is the matter), the second one is SPWM signals with square signals dedicated to control MOSFETs drivers.
i need to make the two codes working at same time, separately they do work perfectly but i need to combine them and i get told to use interrupt but it doesn't work out 'cause i'm so beginner.
i'm using pic16f877a.
Anyone can be on ready to help would be welcomed
and thank you
I'm utterly beginner in C programming, and i made two codes using MikroC PRO, and i'm seeking out your help to make the two of them working in the main time.
the first code is just an A/D conversion and display the result on an LCD. with some conditions on account of commanding a DC FAN and LEDs.
the second code (and this is the matter), the second one is SPWM signals with square signals dedicated to control MOSFETs drivers.
i need to make the two codes working at same time, separately they do work perfectly but i need to combine them and i get told to use interrupt but it doesn't work out 'cause i'm so beginner.
i'm using pic16f877a.
Anyone can be on ready to help would be welcomed
and thank you
C:
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D3 at RD6_bit;
sbit LCD_D2 at RD7_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D2_Direction at TRISD6_bit;
sbit LCD_D3_Direction at TRISD7_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
unsigned char bb1,bb2,bb3,bb4,bb5,bb6,flage;
unsigned int a,aa,bb,cc,vb,vs;
int duty=50;
void tension (){
vb = ADC_Read(3);
if(vb>=34) { aa=(vb-34)/30; bb1=aa/10; lcd_chr(2,9,bb1+48); bb2=aa-(bb1*10); lcd_chr(2,10,bb2+48);}
if(vb>=341 & vb<435){ RB6_bit=1; RB7_bit=1; RC3_bit=1;lcd_out(4,1,"BATTERY IS CHARGING");}
else{if(vb<341){RB6_bit=1;RB7_bit=0;RC0_bit=1;RC3_bit=1;delay_ms(250);RC3_bit=0;lcd_out(4,1,"WAIT..LACK OF ENERGY!"); }}
if(vb>=435){RB6_bit=0;RB7_bit=1;RC5_bit=1;lcd_out(4,1,"BATTERY IS CHARGED");}
}
void tension_panel (){
vs = ADC_Read(1);
if(vs>=34) { aa=(vs-34)/30; bb3=aa/10; lcd_chr(3,9,bb3+48); bb4=aa-(bb3*10); lcd_chr(3,10,bb4+48);}
}
void SPWM (){
while (1){RB2_bit=1;
while(duty<=100){pwm1_set_Duty(duty*2.55); delay_us(22); duty+=2;}
while(duty>=50){ pwm1_set_Duty(duty*2.55); delay_us(22); duty-=2;}
pwm1_set_Duty(0);RB2_bit=0;delay_us(140);RB1_bit=1;
while(duty<=100){pwm2_set_Duty(duty*2.55);delay_us(22);duty+=2;}
while(duty>=50){pwm2_set_Duty(duty*2.55);delay_us(22);duty-=2;}
pwm2_set_Duty(0);RB1_bit=0;delay_us(130);}
}
void main (){
PORTB=0x00;
PORTC=0x00;
TRISB=0x00;
TRISC=0x00;
ADC_init();
lcd_init();
lcd_Cmd(_lcd_CLEAR);
lcd_Cmd(_lcd_CURSOR_OFF);
lcd_out(1,1,"TEMP: ");
lcd_out(1,11,"C");
Lcd_Out(2,1,"BATTERY: ");
Lcd_Out(2,11,"V");
Lcd_Out(3,1,"S.PANEL: ");
Lcd_Out(3,11,"V");
PWM1_start(); //initalize PWM1
PWM2_start(); //initalize PWM2
PWM1_init(5000); //set pwm frequency to 5khz
PWM2_init(5000); //set pwm2 frequency to 5khz
}