Connecting Switches to TM4C Tiva C

Share

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 


// Author : cortex-m.com
//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 


// Author : cortex-m.com
//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;
}

}

London, U.K
© 2019 BOHOBIOM LTD