Normal Close Switches

Normal-Close basically means in the normal state of the switch i.e non-pressed state, the switch is a closed circuit.The circuit  breaks when the switch is pressed.

Assuming we connect a normally closed switch to an LED the way we usually connect our switches i.e.   one leg of the switch to the GND and the other leg of the switch to the to the output device, we will realize that the LED light will turn on when the switch is idle and turn off when the switch is pressed. This is the behavior of  Normal-Close switch. See the circuit diagram and example source code’s link below.

Connecting a Normal Close switch to a microcontroller

  1. Enable the clock of the GPIO pin
  2. Set GPIO pin as input
  3. Enable internal Pull-up 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 *

Phone: +447491265055
W12 7JN, London, United Kingdom
34A Frithville Gardens
Style switcher RESET
Body styles
Color settings
Link color
Menu color
User color
Background pattern
Background image