السلام عليكم ورحمة الله وبركاته
اخوانى الكرام عندى مشكلة فى برنامج وقُمت بعرضها فى احد المشاركات لكن لم اجد لها حل فحبيت اعرضها فى موضوع مستقل
المشكلة باختصار انا اقوم بعمل مشروع للتحكم فى سرعة مروحة حسب درجة الحرارة باستخدام temprature sensor مع امكانية زيادة السرعة يدويا عن طريق مفتاح ضغط
البرنامج بيتم عمل build له بدون أخطاء على ال mikroc
لكن الكود مش بيشتغل على برنامج proteus لا يظهر أى نتائج على شاشة ال LCD + المروحة لا تدور ولا حتى بالمفتاح
ولا استطيع تحديد اين الخطأ فى الكود
كود:
// Lcd pinout settings
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
void main()
{
// variables
float temp , act_temp , duty;
char disp[10], duty1 [5];
int i = 0 , flag = 0;
trisa = 1; trisb = 0; trisc = 0; trisd = 1; trise = 0;
porta = 0; portb = 0; portc = 0; portd = 0; porte = 0;
adcon1= 0b11011110 ; //initialize A0 as analog input
// LCD instruction
Lcd_Init();
Lcd_cmd(_Lcd_cursor_off);
Lcd_out( 1, 1, "temp = ");
PWM1_Init(5000); //initialise PWM1 at 5KHz
while(1) // start infinit loop
{
// temperature reading & calculation
temp = ADC_Read(0);
act_temp = (temp * 500) / 1024;
floattostr(act_temp, disp); //converting float to char
Lcd_out(1, 8,disp);
portc.f0 = 1; //signal to motor forward direction
// PWM orders
if (act_temp == 25 && act_temp <30 )
{PWM1_Start(); PWM1_Set_Duty(32); Lcd_out( 2, 1,"Duty cycle=12.5%");}
if (act_temp == 30 && act_temp <35 )
{PWM1_Start(); PWM1_Set_Duty(64); Lcd_out( 2, 1,"Duty cycle= 25%"); }
if (act_temp == 35 && act_temp <40 )
{PWM1_Start(); PWM1_Set_Duty(96); Lcd_out( 2, 1,"Duty cycle=37.5%");}
if (act_temp == 40 && act_temp <45 )
{PWM1_Start(); PWM1_Set_Duty(127); Lcd_out( 2, 1,"Duty cycle= 50%"); }
if (act_temp == 45 && act_temp <50 )
{PWM1_Start(); PWM1_Set_Duty(159); Lcd_out( 2, 1,"Duty cycle=62.5%");}
if (act_temp == 50 && act_temp <55 )
{PWM1_Start(); PWM1_Set_Duty(191); Lcd_out( 2, 1,"Duty cycle= 75%"); }
if (act_temp == 55 && act_temp <60 )
{PWM1_Start(); PWM1_Set_Duty(223); Lcd_out( 2, 1,"Duty cycle=87.5%");}
if (act_temp >= 60 )
{PWM1_Start(); PWM1_Set_Duty(255); Lcd_out( 2, 1,"Duty cycle= 100%");}
if (portd.f0 == 1) flag = 1;
if (portd.f0 == 0 && flag == 1) // if the push button is pushed
{
i++;
PWM1_Start(); //start PWM1
duty = (i*255)/8 ;
floattostr(duty,duty1);
PWM1_Set_Duty(duty); // set duty cycle from 25% to 100%
Lcd_out( 2, 1,"Duty cycle="); Lcd_out_cp(duty1); Lcd_out_cp("%");
flag=0;
delay_ms(10000);
}
if (i == 9 || act_temp < 25)
{
i = 0 ;
PWM1_Stop();
Lcd_Cmd(_LCD_CLEAR);
}
} //end loop
} //end main
وهذا ملف دائرة المحاكاة على برنامج proteus 8
http://www.4shared.com/rar/18AGN6xyba/proteus_8.html
وهذه صورة للاخطاء التى يظهرها برنامج proteus