在线时间3 小时
UID1240313
注册时间2008-4-1
NXP金币0
该用户从未签到
新手上路

- 积分
- 31
- 最后登录
- 2019-6-16
|

楼主 |
发表于 2017-4-10 15:32:02
|
显示全部楼层
本帖最后由 lijian758-1240313 于 2017-4-11 08:05 编辑
把AN5413SW里面的hello工程里的hello.c定义的蓝色LED输出端口PTD0改为PTE8是可以的,但是把SW2按键输入端口PTC12改为PTD15就不行,改为PTB2或者PTB3也不行,但是只要改回到PORTC的端口上就行,不知为什么?
下面的代码是我把按键改到PTD15,蓝色LED改到PTE8的代码:
/*
* hello.c Copyright NXP 2016
* Description: Simple program to exercise GPIO
* 2015 Mar 31 S Mihalik/ O Romero - initial version
*
*/
#include "S32K144.h" /* include peripheral declarations S32K144 */
#define PTE8 8 /* Port PTE8, bit 8: FRDM EVB output to blue LED */
#define PTD15 15 /* Port PTD15, bit 15: FRDM EVB input from BTN0 [SW2] */
void WDOG_disable (void){
WDOG->CNT=0xD928C520; /*Unlock watchdog*/
WDOG->TOVAL=0x0000FFFF; /*Maximum timeout value*/
WDOG->CS = 0x00002100; /*Disable watchdog*/
}
int main(void) {
int counter = 0;
WDOG_disable(); /* Disable Watchdog in case it is not done in startup code */
/* Enable clocks to peripherals (PORT modules) */
PCC-> PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT D */
PCC-> PCCn[PCC_PORTE_INDEX] = PCC_PCCn_CGC_MASK; /* Enable clock to PORT E */
/* Configure port D15 as GPIO input (BTN 0 [SW2] on EVB) */
PTD->PDDR &= ~(1<<PTD15); /* Port D15: Data Direction= input */
PORTD->PCR[15] = 0x00000112; /* Port D15: MUX = GPIO, input filter enabled,pulldown enable */
/* Configure port E8 as GPIO output (LED on EVB) */
PTE->PDDR |= 1<<PTE8; /* Port E8: Data Direction= output */
PORTE->PCR[8] = 0x00000100; /* Port E8: MUX = GPIO */
for(;;) {
if (PTD->PDIR & (1<<PTD15)) { /* If Pad Data Input = 1 (BTN0 [SW2] pushed) */
PTE-> PSOR |= 1<<PTE8; /* Set Output on port D0 (LED on) */
}
else { /* If BTN0 was not pushed */
PTE-> PCOR |= 1<<PTE8; /* Clear Output on port E8 (LED off) */
}
counter++;
}
}
|
|