code interface for GPIO pin

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

code interface for GPIO pin

ソリューションへジャンプ
1,778件の閲覧回数
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,762件の閲覧回数
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,763件の閲覧回数
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 件の賞賛
返信