هذا الكود يقوم بالضبط بما تريده
حيث تظهر للمستخدم رسالة Enter the Degree
وبعدها يدخل درجة الحرارة عن طريق كي باد
ثم تظهر رسالة Enter the Time
وبعدها يدخل الوقت بالدقائق (يمكن تغييره لأي وحدة زمن لكن انا وضعته كمثال) عن طريق كي باد
وبعدها يبدا البرنامج بالدخول إلى الفنكشن on
يقوم بتحويل الوقت والدرجة المدخلة إلى أحاد وعشرات
ثم يدخل في لوب بحيث يقراء درجة الحرارة
اذا كانت لا تساوي القيمة المدخلة يقوم بتشغيل البورت D0 والذي يكون مشبوك على الريلاي
حتى تفهم المشروع اكثر ارجوا انك تبحث عن درس تشغيل 46 ريلاي للأستاذي الفاضل أحمد سمير فايد
فقد شرح طريقة استخدام الكي باد وهي نفس الطريقة التي استخدمتها في مشروعك هذا
المشروع قمت بكتابتة ولم اقم بمحاكاته بعد وذلك لضيق الوقت
لكن الكود سليم ان شاء الله ..و ان كان هناك اخطاء فهي في السنتاكس فقط
حتى تجرب الدائرة لا تقم بتشغيلها دفعه واحده عندها ربما لا تعمل ولن تستطيع حل مشكلتها بسهولة
انما قم بتركيب الريلاي أولاً على البورت D وجربه
ثم قم بتركيب ال LCD على البورت B وجربها
ثم قم بتركيب ال Keypad على البورت C وجربها
ثم أخر شئ ركب ADC على بورت A وجربها
اذا اشتغلت كل واحده على حده
عندها جرب البرنامج وستكون متقن للمشروع وتستيطع عمل اي تعديل او حل اي مشكلة فيه
Read more:
http://www.qariya.com/vb/newreply.ph...#ixzz0yaq8L4g2
كود:
char m;
char w;
char result=0;
char result_t=0;
char number[]={'x',' ','9','8','7','x','6','5','4','x','3','2','1','x','x','0','x'};
char number2[]={'x',' ',9,8,7,'x',6,5,4,'x',3,2,1,'x','x',0,'x'};
char tens=0,ones=0;
char tens1=0,ones1=0;
unsigned long temp,aa;
int kk;
int x;
char txt[14];
///////////////////////////////// Controlling the relay according to the degree:
void on() {
result=(tens*10)+ones;
result_t=(tens1*10)+ones1;
if(result>99 || result<1){Lcd_Cmd(Lcd_Clear);lcd_out_cp("error");delay_ms(1000);return;}
x=result_t/60;
while(1)
{
for(x=0; x<result_t; x--){
delay_ms(1000);
temp=adc_read(0);
temp=(temp*5000)>>10;
temp=temp/10;
longToStr(temp,txt);
lcd_out(1,1,"temp = ");
lcd_out(2,1,txt);
lcd_chr_cp('C');
delay_ms(500);
lcd_cmd(lcd_clear);
if(temp<result)
{
portd.f0=1;
}else {portd.f0=0;}
}
}
}
void main()
{
adcon1=0b00001110; // using Port A as analog to digital converting
trisa=0xff;// using Port A as in put
trisd=0;
Keypad_Init(&PORTC); // Using Port C for Keypad
lcd_init(&portb); // Using POrt B for LCD
lcd_cmd(LCD_CURSOR_OFF);
lcd_out(1,1,"Enter the Degree");
lcd_out(2,1," C");
/////////////////////////////////////Entering Degree
loop: //testing the first pushing down
m=keypad_read();
if(m==0) {goto loop;}
else if(m==14){goto loop;}
else if(m==16){Lcd_Cmd(Lcd_Clear);goto loop;}
else {Lcd_Cmd(Lcd_Clear);tens=number2[m];lcd_chr_cp(number[m]);delay_ms(500);}
test2: //testing the second pushing down
m=keypad_read();
if(m==0) {goto test2;}
else if(m==14){ones=tens;tens=0;on();goto test3;}
else if(m==16){Lcd_Cmd(Lcd_Clear);goto loop;}
else {ones=number2[m];lcd_chr_cp(number[m]);delay_ms(500);}
test3: //testing the third pushing down
m=keypad_read();
if(m==0) {goto test3;}
else if(m==14){goto loop2;}
else if(m==16){Lcd_Cmd(Lcd_Clear);goto loop;}
else {goto test3;}
}
/////////////////////////////////// Entering Time by mints
loop2: //testing the first pushing down
lcd_cmd(lcd_clear);
lcd_out(1,1,"Enter the Time");
w=keypad_read();
if(w==0) {goto loop2;}
else if(w==14){goto loop2;}
else if(w==16){Lcd_Cmd(Lcd_Clear);goto loop;}
else {Lcd_Cmd(Lcd_Clear);tens1=number2[m];lcd_chr_cp(number[m]);delay_ms(500);}
test2: //testing the second pushing down
w=keypad_read();
if(w==0) {goto test2;}
else if(w==14){ones1=tens;tens1=0;on();goto test3;}
else if(w==16){Lcd_Cmd(Lcd_Clear);goto loop;}
else {ones=number2[m];lcd_chr_cp(number[m]);delay_ms(500);}
test3: //testing the third pushing down
w=keypad_read();
if(w==0) {goto test3;}
else if(w==14){on();}
else if(w==16){Lcd_Cmd(Lcd_Clear);goto loop;}
else {goto test3;}
}