I am trying to make the PTC3(Switch1)pin as pull-down but it is not working.The code is as follows:
#include "MKL46Z4.h" // Device header
void InitLED(void)
{
SIM->SCGC5=SIM_SCGC5_PORTD_MASK;//Clock to PortD
PORTD->PCR[5]=256;//PIN 5 of portd as GPIO
PTD->PDDR=(1u<<5);//PIN 5 of portd as OUTPUT
}
void InitSW1(void)
{
SIM->SCGC5=SIM_SCGC5_PORTC_MASK;//Clock to PortC
PORTC->PCR[3]=256|2;//PIN 3 of portc as GPIO and pullup/pulldown+pulldown
PTC->PDDR=(0u<<3);//PIN 5 of portd as INPUT
}
int main()
{
while(1)
{
InitLED();
InitSW1();
if(PTC->PDIR==(0u<<3))//Read 0 switch pressed
{
PTD->PCOR=(1u<<5);//LED turns on
}
else if(PTC->PDIR==(1u<<3))//Read 1 switch not pressed
{
PTD->PSOR=(1u<<5);//Led turns off
}
}
}
When I download the above code to the board the led switches on but when i press the switch it does not switch off.The schematic says that the switch is of pull-up type ,can i really use it as a pull-down?