|
:: نائب المشرف العام ::
تاريخ التسجيل: Jun 2009
الدولة: القاهرة - مصر
المشاركات: 11,652
|
|
نشاط [ ماجد عباس محمد ]
قوة السمعة:
|
|
20-07-2018, 09:37 AM
المشاركة 82
|
|
الغسالة باستخدام PIC18F و لغة C:
يمكننا للسهولة نسخ البرنامج السابق فى مشروع جديد للمتحكم الجديد و ننسخه ، سنحتاج لتعديلات طفيفة مثل TMR0 سيضاف لها حرف L كبير أو صغير و Option_Reg سيتغير إلى INTCON2 و تعدل الأرقام كما فى المثال السابق فيصبح هكذا
كود:
// program WM18 Declarations section
char Switches at PORTB ;
char Leds at Portc ;
char Relays at Portd ;
sbit Fullled at Rc0_bit ;
sbit Halfled at rc1_bit ;
sbit Smallled at rc2_bit ;
sbit Hotled at rc3_bit ;
sbit Mildled at rc4_bit ;
sbit Coldled at rc5_bit ;
sbit Wateron at rc6_bit ;
sbit Drainon at rc7_bit ;
sbit HitemP at rd0_bit ;
sbit MidtemP at rd1_bit ;
sbit Waterfull at rd2_bit ;
sbit Waterempty at rd3_bit ;
sbit Run_nspin at rd5_bit ;
sbit Motoron at rd6_bit ;
sbit Heateron at rd7_bit ;
sbit Dooropen at rb0_bit ;
sbit Run at rb1_bit ;
sbit Cold at rb2_bit ;
sbit Mild at rb3_bit ;
sbit Hot at rb4_bit ;
sbit SmallLoad at rb5_bit ;
sbit Half at rb6_bit ;
sbit Full at rb7_bit ;
bit Jobpending ;
// VARIABLES
unsigned int Runtime ;
char Rinse , Cntr ;
void Timer0_int() iv 0x0018 ics ICS_AUTO {
if (INTCON.TMR0IF =1 ) {
// dec (Runtime)
if (--Runtime = 0 ) {
Jobpending = 0 ;
INTCON.TMR0IF =0 ; // ClearBit(INTCON, TMR0IF) ; // Clear flag
INTCON.TMR0Ie = 0 ; // ClearBit(INTCON, TMR0Ie) // Disable timer
} // End If
INTCON.TMR0IF =0 ;
// ClearBit(INTCON, TMR0IF) // clear Interrupt Timer0 to receive another
}
}
void main() { // Main program
INTCON2 = 0 ; // setting RB Pull up clearing bit RBPU all rising edge.
INTCON = 0B10100000 ;
// 7Interrupt Control GIE All,6Peie disabledg, 5Timer0 OV Enable
// External disable , RBIF port changeenable, Timr0Flag,Exter Flag, PB change flag
TRISB = 255 ;
TRISC = 0 ; // out
Leds = 0b00100100 ; //small Cold
TRISD = 0b00011111 ; // some in and some out
Relays = 0b00001111 ;
Heateron = 0 ;
Motoron = 0 ;
Run_nspin = 0 ;
INTCON.TMR0IF =0 ; // ClearBit(INTCON, TMR0IF) // Interrupt Timer0 Flag
INTCON.TMR0IE =0 ; // ClearBit(INTCON, TMR0IE) // Stop Interrupt Timer0
while (Run = 1 ) // Bitwait Run , Set
{} // wend // Run button release
while (1) { // Loopagain:
do {
if (Full = 0) { // Then
Leds = Leds | 0B00000111 ; // Leds OR 00000111
Fullled = 0 ; }
else if ( Half = 0) { // Then
Leds = Leds | 0b00000111 ; // Leds = Leds Or %00000111
Halfled = 0 ; }
else if ( SmallLoad = 0 ){ // Then
Leds = Leds | 0b00000111 ; //Leds = Leds Or %00000111
Smallled = 0 ; } // end if
if ( Hot = 0) { // Then
Leds = Leds | 0B00111000 ; //Leds = Leds Or %00111000
Hotled = 0 ; }
else if (Mild = 0) { // Then
Leds = Leds | 0b00111000 ; //Leds = Leds Or 0b00111000
Mildled = 0 ; }
else if (Cold = 0) // Then
{ Leds = Leds | 0b00111000 ;
Coldled = 0 ;
} // end if
} while (Run = 1) ; // loop until run = 0 // Wait Run Press
while ( DoorOpen = 1 ) ; // Bitwait Dooropen , Reset // Wait Door to close
WaterOn = 1 ; // Set Wateron Open Water Valve
while (Waterfull = 1 ) ; // Bitwait Waterfull , Reset // Wait full Tank
WaterOn = 0 ; // ReSet Wateron // Close water Valve
if (Coldled = 1) // Then // not Cold then
{ Heateron = 1 ; // Heater on
if (Mildled = 0)
{
while ( Midtemp = 1 ); // Bitwait Midtemp , Reset
} // wend
else
{ while (Hitemp = 1 ) ; // Bitwait Hitemp , Reset
} //end if
HeaterOn = 0 ; // reSet Heateron // Turn off heater
} // End if // Now Start Washing
if (Fullled = 0) // Then
Runtime = 20 * 60 ;
else if (Halfled = 0) // Elseif Halfled = 0 Then
{ Runtime = 480 ; }
else
{ Runtime = 300 ; } // end if
// Runmotor:
Jobpending = 1 ; // Set Jobpending // Timing flag
Motoron = 1 ; // Motoron = 0 // Start Motor
TMR0l = 205 ; // Load Tomer0
INTCON.TMR0IE = 1 ; // enable Timer0
INTCON.TMR0IF = 1 ; // Interrupt Timer0 Flag
while (jobPending = 1) ; // Bitwait Jobpending , Reset // Wait to Finish
motorOn = 0; // Set Motoron // stop motor
for (Cntr =0; Cntr < Rinse; Cntr++) // for Cntr = 1 To Rinse
{ Drainon = 1 ; // Reset Drainon // Open Drain
while (Waterempty = 1) ; // Bitwait Waterempty , Reset // Wait Drain
// wend
DrainOn = 0 ; // Set Drainon // Close Drain
WaterOn = 1 ; // Reset Wateron // Fill again
while (WaterFull = 1) ; // Bitwait Waterfull , Reset
// wend
WaterOn = 0 ; // Set Wateron // Close Water
Runtime = 300 ; // Rinse Time
TMR0l = 205 ;
Jobpending = 1 ; // Set Jobpending
Motoron =1 ; // Reset Motoron // Start Rinse
INTCON.TMR0IE = 1 ; // SetBit(INTCON, TMR0IE)// enable Timer0
INTCON.TMR0IF = 1 ; // setBit(INTCON, TMR0IF) // Interrupt Timer0 Flag
while (Jobpending = 1) ; // Bitwait Jobpending , Reset // Wait to Finish
Motoron = 0 ; // Set Motoron // Stop Rinse
} // Next cntr
MotorOn = 0 ; // Set Motoron // Stop Rinse
DrainOn = 1 ; // Reset Drainon // Open Drain second cycle
while (Waterempty = 1 ); // Bitwait Waterempty , Reset // Wait Drain
Runtime = 180 ; // SPIN
JobPending = 1 ; // Set Jobpending
motorOn = 1 ; // Reset Motoron // Start Spin
Run_nSpin = 1 ; // Reset Run_nspin // SPIN
TMR0L = 205 ;
Jobpending = 1 ;
INTCON.TMR0IE = 1 ; // SetBit(INTCON, TMR0IE)// enable Timer0
INTCON.TMR0IF = 1 ; // setBit(INTCON, TMR0IF) // Interrupt Timer0 Flag
while (JobPending = 1) ; // Bitwait Jobpending , Reset // Wait to Finish
Relays = 0b00001111 ; // ALL OFF, INITIAL State
} // Goto Loopagain
}
فى الأمثلة السابقة فصلنا كثيرا لتوضيح الفروق بين اللفات و المترجمات لذا أرى أنه من الأفضل فيما يلى أن نعتمد الأسيمبلى لعائلة C51 و البيزك / باسكوم لعائلة AVR و لغة C من ميكروإلكترونيكا للبيك اختصارا للوقت و أصبح لدينا القدرة للترجمة حسبما تقود الحاجة.
المرة القادمة إن شاء الله سنتحدث عن برنامج ميكروويف منزلى ثم برنامج آخر لمعالجة ADC و ربما PWM
|