Saturday 22 December 2018

Switch Interfacing with led




Interfacing diagram:

SWITCH INTERFACING

 




1) Switch interfacing with single led (P0.0)

/**************************************************************************************************
Expt. 1a.: LED & switch interfacing with to LPC2148
Platform:  LPC2148 Development Board.
  

Hardware Setup:-
 Switch pin - P1.16
 LED Pins- P0.0          
********************************************************************************/
 
#include<lpc214x.h>
int main()
{
     IODIR1 = (0<<16); // explicitly making P1.16 as Input
     IODIR0 = (1<<00); // Configuring P0.0 as Output
 
     while(1)
     {
 if((IOPIN1 & (1<<16))) // check status of pin P1.16
   {
     IOCLR0 = (1<<00); // drive P0.0 LOW, turn LED OFF
   }else
 {
     IOSET0 = (1<<00); // drive P0.0 HIGH, turn LED ON
 }
     }
 return 0;
} 





/**************************************************************************************************
Expt. 1b.: LED & switch interfacing with to LPC2148
Platform:  LPC2148 Development Board.
  

Hardware Setup:-
 Switch pin - P1.16
 LED Pins- P0.0 to P0.7         
********************************************************************************/
 
#include<lpc214x.h>
int main()
{
     IODIR1 = (0<<16); // explicitly making P1.16 as Input
     IODIR0 = (0xFF<<00); // Configuring P0.0 to P0.7 as Output
 
     while(1)
     {
          if((IOPIN1 & (1<<16))) // check status of pin P1.16
          {
             IOCLR0 = (0xFF<<00); // drive P0.0 to P0.7 LOW, turn LED OFF
           }
         else
           {
              IOSET0 = (0xFF<<00); // drive P0.0 to P0.7 HIGH, turn LED ON
           }
     }
 return 0;
} 









/**************************************************************************************************
Expt. 1c.: LED & switch interfacing with to LPC2148
Platform:  LPC2148 Development Board.
  

Hardware Setup:-
 Switch pin - P0.15 (Left Shift operation), P0.16 (Right Shift operation)
 LED Pins- P1.16 to P1.23         
********************************************************************************/
 #include<lpc214x.h>
void delay(int time);

void delay(int time)
  { 
 int j,k;
 for(j=0;j<time;j++)
 {
  for(k=0;k<800;k++)
  {
  }
 }
  }

int main()
{
 unsigned int i,sw0,sw1,val;
 IODIR0=0x00<<00;
 IODIR1=0xFF<<16;
 while(1)
  
 { 
   sw0=(IOPIN0 & 0x00008000);
   sw1=(IOPIN0 & 0x00010000);
  if(sw0==0)
   {
    val=0x01;
   }
   
   if(sw1==0)
   {
    val=0x02;
   }
  
      if(val==0x01)
        {
          for(i=16;i<24;i++)
           {
           IOSET1=1<<i;
           delay(2500);
           IOCLR1=1<<i;
           delay(2500);
           }
         }
   
   
        if(val==0x02)
           {
          for(i=23;i>15;i--)
             {
              IOSET1=1<<i;
             delay(2500);
             IOCLR1=1<<i;
              delay(2500);
             }
           }
 
 }
 return 0;

}

No comments:

Post a Comment