code interface for GPIO pin

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

code interface for GPIO pin

跳至解决方案
1,797 次查看
akhilranga
Contributor IV

Hello there,

Please help we with the following . 

#include "S32K144.h" /* include peripheral declarations S32K144 */

#define PTD16 16
#define PTC13 13

void WDOG_disable (void){
	WDOG->CNT = 0xD928C520;
	WDOG->TOVAL = 0x0000FFFF;
	WDOG->CS = 0x00002100;
}

int main(void){
	int counter = 0;
	WDOG_disable();

	//Enable clocks to peripherals (Port Modules)
	PCC->PCCn[PCC_PORTC_INDEX]=PCC_PCCn_CGC_MASK;
	PCC->PCCn[PCC_PORTD_INDEX]=PCC_PCCn_CGC_MASK;

	//Configure port C12 as GPIO input (BTN 0 [SW2] on EVB)
	PTC->PDDR &= ~(1<<PTC13);     /* Port C12: Data Direction= input (default) */
	PORTC->PCR[13] = 0x00000110;  /* Port C12: MUX = GPIO, input filter enabled */

	// Configure port D0 as GPIO output (LED on EVB)
	PTD->PDDR |= 1<<PTD16;         /* Port D0: Data Direction= output */
	PORTD->PCR[16] = 0x00000100;   /* Port D0: MUX = GPIO */

	for(;;) {
     if (PTC->PDIR & (1<<PTC13))/* If Pad Data Input = 1 (BTN0 [SW3] pushed) */

     {
       PTD-> PCOR |= 1<<PTD16; /* Clear Output on port D0 (LED on) */
     }
     else

     { /* If BTN0 was not pushed */
       PTD-> PSOR |= 1<<PTD16; /* Set Output on port D0 (LED off) */
     }
    counter++;
    }


}

 

from the above code in the if ststement

if (PTC->PDIR & (1<<PTC13))  /*If Pad Data Input = 1 (BTN0 [SW3] pushed) */

the above line represesnt that the button is pushed. how can i create a if condition if button is not pushed.

 

if (??????????????????) /* If Pad Data Input = 0 (BTN0[SW3] not pushed) */

 

please help me fill up that space

 

 

标记 (3)
0 项奖励
回复
1 解答
1,781 次查看
VaneB
NXP TechSupport
NXP TechSupport

Hi @akhilranga 

If the first if evaluates to false, it means that the button is not pressed and you can handle it with an else. But if you need to see the state of the pin you can do it with the following line:

if (!(PTC->PDIR & (1 << PTC13))) /* If Pad Data Input = 0 (BTN0[SW3] not pushed) */

 

B.R.

VaneB

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,782 次查看
VaneB
NXP TechSupport
NXP TechSupport

Hi @akhilranga 

If the first if evaluates to false, it means that the button is not pressed and you can handle it with an else. But if you need to see the state of the pin you can do it with the following line:

if (!(PTC->PDIR & (1 << PTC13))) /* If Pad Data Input = 0 (BTN0[SW3] not pushed) */

 

B.R.

VaneB

0 项奖励
回复