برنامج أضواء متحركة light chaser بخمس نماذج قابل للتطوير
الشرح فى التعليقات
كود:
/* 1- Comments :
Name : LEDS Light Chser with multi modes
MCU : PIC16F877A - 4MHz
By : Eng.F.Abdelaziz
http://www.eeecb.com/vb/index.php */
// 2- Definitions :
sbit LED0 at PORTD.B0; // this is where LED0 is fully defined
sbit LED1 at PORTD.B1; // this is where LED1 is fully defined
sbit LED2 at PORTD.B2; // this is where LED2 is fully defined
sbit LED3 at PORTD.B3; // this is where LED3 is fully defined
sbit LED4 at PORTD.B4; // this is where LED4 is fully defined
sbit LED5 at PORTD.B5; // this is where LED5 is fully defined
sbit LED6 at PORTD.B6; // this is where LED6 is fully defined
sbit LED7 at PORTD.B7; // this is where LED7 is fully defined
// 3- Variables Declaration
unsigned int count; //for loop event loop
//4- Main function
void main(void)
{
// a- PORT Initialization
TRISD = 0x00;// All pins of PORTD as outputs
PORTD = 0b00000000;// Initially Clear PORTD
// b- Form an endless loop
while(1)
{
for(count=0; count<10; count++) // 1- Repeat 10 times the following as Pattern 1 :
{
//1- Forward from LED0 to LED7
LED0 = 1;//LED0 ON
Delay_ms(250);// Pause
LED0 = 0;// LED0 OFF
LED1 = 1;//LED1 ON
Delay_ms(250);// Pause
LED1 = 0;//LED1 OFF
LED2 = 1;//LED2 ON
Delay_ms(250);// Pause
LED2 = 0;
LED3 = 1;
Delay_ms(250);
LED3 = 0;
LED4 = 1;
Delay_ms(250);
LED4 = 0;
LED5 = 1;
Delay_ms(250);
LED5 = 0;
LED6 = 1;
Delay_ms(250);
LED6 = 0;
LED7 = 1;
Delay_ms(250);
LED7 = 0;
//2- Reverse From LED6 to LED0
LED6 = 1;
Delay_ms(250);
LED6 = 0;
LED5 = 1;
Delay_ms(250);
LED5 = 0;
LED4 = 1;
Delay_ms(250);
LED4 = 0;
LED3 = 1;
Delay_ms(250);
LED3 = 0;
LED2 = 1;
Delay_ms(250);;
LED2 = 0;
LED1 = 1;
Delay_ms(250);
LED1 = 0;
LED0 = 1;
Delay_ms(250);
}
//Re-initalize PORTD
PORTD = 0b00000000;
for(count=0; count<10; count++) // 2- Repeat 10 times the following :
{
PORTD = 0b10101010;//Create LEDS Pattern 2 : 1 = ON & 0 = OFF
Delay_ms(500);
PORTD = 0b01010101;//Inverse Pattern 2
Delay_ms(500);
}
for(count=0; count<10; count++) //3- Repeat 10 times the following :
{
PORTD = 0b11110000;//Create LEDS Pattern 3 : 1 = ON & 0 = OFF
Delay_ms(500);
PORTD = 0b00001111;//Inverse Pattern 3
Delay_ms(500);
}
for(count=0; count<10; count++)//4- Repeat 10 times the following :
{
PORTD = 0b11001100;//Create LEDS Pattern 4 : 1 = ON & 0 = OFF
Delay_ms(500);
PORTD = 0b00110011;//Inverse Pattern4
Delay_ms(500);
}
for(count=0; count<10; count++)//5- Repeat 10 times the following :
{
PORTD = 0b10000001;//Create LEDS Pattern 5 : 1 = ON & 0 = OFF
Delay_ms(250);
PORTD = 0b01000010;//IN
Delay_ms(250);
PORTD = 0b00100100;//IN
Delay_ms(250);
PORTD = 0b00011000;//IN-OUT
Delay_ms(250);
PORTD = 0b00100100;//OUT
Delay_ms(250);
PORTD = 0b01000010;//OUT
Delay_ms(250);
}//end of last for loop
}// end of while(1)
}//end of main function