Knight-Rider/16F877A

PORTB is used to make this project and it is written in MikroC language.


void left()  {
while(PORTB.F7 !=1){   // until PORTB.F7 not equal to 1
PORTB= PORTB*2;   // multiply PORTB value by 2
Delay_ms(500);}         //delay 500ms
}
void right(){
while(PORTB.F0 !=1){  //untill PORTB.F0 not equal to 1
PORTB=PORTB/2;      // devide PORTB value by 2
Delay_ms(500);}          // delay 500ms
}
void main (){
TRISB=0;          // Set PORTB as out put
PORTB=1;        // Set PORTB vale to 1
Delay_ms(500); // delay 500ms


while(1){                    // endless loop
if (PORTB.F0 == 1); // if PORTB.F0 equal to 1
left();                         // run left cycle
if (PORTB.F7 == 1); // if PORTB.F7 equal to 1
right();}                     // run right cycle    
}








Here some more designs were added, by the way there are so many program writing methods which you can use to make different designs.
void left()  {
while(PORTB.F7 !=1){
PORTB= PORTB*2;
Delay_ms(500);}
}
void righ(){
while(PORTB.F0 !=1){
PORTB=PORTB/2;
Delay_ms(500);}
}

void leftTwo()  {
while((PORTB.F7 && PORTB.F5) != 1){
PORTB= PORTB*2;
Delay_ms(500);}
}
void righTwo(){
while((PORTB.F0 && PORTB.F2) !=1){
PORTB=PORTB/2;
Delay_ms(500);}
}
void up(){

Delay_ms(500);
PORTB=129;
Delay_ms(500);
PORTB=66;
Delay_ms(500);
PORTB=36;
Delay_ms(500);
PORTB=24;
Delay_ms(500);
PORTB=36;
Delay_ms(500);
PORTB=66;
}
void cross(){
Delay_ms(500);
PORTB=192;
Delay_ms(500);
PORTB=96;
Delay_ms(500);
PORTB=48;
Delay_ms(500);
PORTB=24;
Delay_ms(500) ;
PORTB=24;
Delay_ms(500) ;
PORTB=12;
Delay_ms(500) ;
PORTB=6;
Delay_ms(500) ;
PORTB=3;
Delay_ms(500) ;
PORTB=6;
Delay_ms(500) ;
PORTB=12;
Delay_ms(500) ;
PORTB=24;
Delay_ms(500) ;
PORTB=48;
Delay_ms(500) ;
PORTB=96;
Delay_ms(500) ;
}

int count=0;
void main (){
TRISB=0;
PORTB=1;
Delay_ms(500);

while(1){
PORTB=1;
count=0;
do{
if (PORTB.F0 == 1);
left();
count=count+1;
if (PORTB.F7 == 1);
righ();
count=count+1;}
while(count<=3);
PORTB=5;
do{
if ((PORTB.F0 && PORTB.F2) ==1)
leftTwo();
count=count+1;
if ((PORTB.F7 && PORTB.F5) ==1);
righTwo();
count=count+1;
}
while(count <=6);
do{
count=count+1;
PORTB=0XFF;
Delay_ms(500);
PORTB=0X00;
delay_ms(500);
up();
} while(count<=9);
do{
 count=count+1;
 PORTB=0XFF;
Delay_ms(500);
PORTB=0X00;
delay_ms(500);
Cross();
}  while(count<=12);    }
}

No comments:

Post a Comment