Normal Open Switches

Normal Open Switches 

Normal – Open switches is the name given to the switches we are very much used to. The switches that turn on when we press and goes off when we release. These switches are called Normal-Open because in their normal state they behave like an open circuit. It is  by pressing the switch that we actually close the circuit. This behavior is contrary to that of Normal-Close switches. To learn more about Normal- Close switches please see this lesson. See the circuit diagram and example source code’s link  below.

Connecting a Normal Open switch to a microcontroller

  1. Enable the clock of the GPIO pin
  2. Set GPIO pin as input
  3. Enable internal Pull-down resistor for GPIO pin

Two programs are presented in this example page. The first program is an example of connecting Normal-Close switches to the TM4C Tiva C Launchpad while the second example talks about connecting Normal-Open switches to the same microcontroller.

Program 1 : Normal-Close Switches 

//Function : Demonstrates how NC switches work
 
#include "TM4C123.h" // Device header
#include<stdint.h>
 
#define BLUE_LED (1U<<2)
#define NC_Switch (1U<<4) int main() { SYSCTL->RCGCGPIO |=(1U<<0); SYSCTL->RCGCGPIO |=(1U<<5); GPIOF->DIR |= BLUE_LED;
GPIOF->DEN |= BLUE_LED;
GPIOA->PUR |= NC_Switch;
GPIOA->DEN |= NC_Switch;
 
while(1)
{
if((GPIOA -> DATA & NC_Switch) !=0)
GPIOF->DATA |=BLUE_LED;
else
GPIOF -> DATA &= ~BLUE_LED;
}
 
}

Program 2 : Normal-Open Switches 

//Function : Demonstrates how NO switches work
 
#include "TM4C123.h" // Device header
#include<stdint.h>
 
#define BLUE_LED (1U<<2)
#define NO_Switch (1U<<4) int main() { SYSCTL->RCGCGPIO |=(1U<<0); SYSCTL->RCGCGPIO |=(1U<<5); GPIOF->DIR |= BLUE_LED;
GPIOF->DEN |= BLUE_LED;
GPIOA->PDR |= NO_Switch;
GPIOA->DEN |= NO_Switch;
 
while(1)
{
if((GPIOA -> DATA & NO_Switch) !=0)
GPIOF->DATA |=BLUE_LED;
else
GPIOF -> DATA &= ~BLUE_LED;
}
 
}

Add Comment

Your email address will not be published. Required fields are marked *