 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:332
|
|
04-06-2017, 08:48 PM
المشاركة 1
|
|
تمرين :
الدائرة الكهربية :

فى البرنامج أدناه :
• اشرح البرنامج متتبعا خطوات تنفيذ البرنامج .
• قم بتعديل البرنامج مستخدما الدوال Function .
كود:
sbit LED0 at PORTB.B0; // bit is fully defined
sbit LED1 at PORTB.B1;
sbit LED2 at PORTB.B2;
sbit LED3 at PORTB.B3;
sbit LED4 at PORTB.B4;
sbit LED5 at PORTB.B5;
sbit LED6 at PORTB.B6;
sbit LED7 at PORTB.B7;
//main function
void main(void)
{
unsigned int c; //for loop Counter
TRISB = 0;
PORTB = 0;
while(1)
{
for(c=0; c<10; c++)
{
//forward
LED0 = 1;
Delay_ms(1000);
LED0 = 0;
LED1 = 1;
Delay_ms(1000);
LED1 = 0;
LED2 = 1;
Delay_ms(1000);
LED2 = 0;
LED3 = 1;
Delay_ms(1000);
LED3 = 0;
LED4 = 1;
Delay_ms(1000);
LED4 = 0;
LED5 = 1;
Delay_ms(1000);
LED5 = 0;
LED6 = 1;
Delay_ms(1000);
LED6 = 0;
LED7 = 1;
Delay_ms(1000);
LED7 = 0;
//reverse
LED6 = 1;
Delay_ms(1000);
LED6 = 0;
LED5 = 1;
Delay_ms(1000);
LED5 = 0;
LED4 = 1;
Delay_ms(1000);
LED4 = 0;
LED3 = 1;
Delay_ms(1000);
LED3 = 0;
LED2 = 1;
Delay_ms(1000);
LED2 = 0;
LED1 = 1;
Delay_ms(1000);
LED1 = 0;
LED0 = 1;
Delay_ms(1000);
}
//re-initalize PORTB
PORTB = 0b00000000;
for(c=0; c<10; c++)
{
PORTB = 0b10101010;
Delay_ms(1000);
PORTB = 0b01010101;
Delay_ms(1000);
}
for(c=0; c<10; c++)
{
PORTB = 0b11110000;
Delay_ms(1000);
PORTB = 0b00001111;
Delay_ms(1000);
}
for(c=0; c<10; c++)
{
PORTB = 0b11001100;
Delay_ms(1000);
PORTB = 0b00110011;
Delay_ms(1000);
}
for(c=0; c<10; c++)
{
PORTB = 0b10000001;
Delay_ms(1000);
PORTB = 0b01000010;
Delay_ms(1000);
PORTB = 0b00100100;
Delay_ms(1000);
PORTB = 0b00011000;
Delay_ms(1000);
PORTB = 0b00100100;
Delay_ms(1000);
PORTB = 0b01000010;
Delay_ms(1000);
}
}
}
|