Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - sronrham

#1
#include <reg52.h>

sbit SW_L=P3^0;
sbit SW_STOP=P3^1;
sbit SW_R=P3^2;


sbit SW_SLOW=P3^3;
sbit SW_MEDIUM=P3^4;
sbit SW_FAST=P3^5;


void RIGHT();
void LEFT();

void delay(int z)
{
int x;
for(x=0;x<z;x++);

}

void main()
{
        P1=0;

      if(SW_R==0)
         { 
            RIGHT();
         }
      if(SW_L==0)
         {
            LEFT();
         }
}

void RIGHT()
{
   int l = 1000;
   int m = 9000;

   while(SW_STOP==1)
      {
      if(SW_SLOW==0)
         {
            l=2000;
            m=3000;
         }
      if(SW_MEDIUM==0)
         {
            l= 4500;
            m= 500;
         }
      if(SW_FAST==0)
         {
            l= 1000;
            m= 50000; 
         }

      P1=0xFD;
      delay(l);
      P1=0xFF;
      delay(m);
   }
}

void LEFT()
{
   int l = 1000;
   int m = 0000;

   while(SW_STOP==1)
      {
      if(SW_SLOW==0)
         {
            l=2000;
            m=3000;
         }
      if(SW_MEDIUM==0)
         {
            l= 4500;
            m= 500;
         }
      if(SW_FAST==0)
         {
            l= 1000;
            m= 50000; 
         }

      P1=0xFE;
      delay(l);
      P1=0xFF;
      delay(m);
   }
}