Programming GPIO in MPC5668G

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

Programming GPIO in MPC5668G

跳至解决方案
1,814 次查看
ravikiranbhairu
Contributor II

Hello All,

 

i am new to using this MCU. How can i program a GPIO pin to act as an input and output? For ex to read value of led port and write the value into a led port?

Thank you in advance.

 

Regards,

Ravikiran    

标签 (1)
标记 (2)
1 解答
1,318 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

Please refer to the following posted example; https://community.freescale.com/docs/DOC-329563.

It gives you basic demo code. It also set one pin to GPIO output and toggle it within timer interrupt.

To set the pin as input you need to set the SIU.PCR[x].IBE bit and read the pad level from the respective SIU.GPDI[x] register.

For example like this

SIU.PCR[16].R = 0x0200;                                // set PB0 as GPIO output

SIU.PCR[17].R = 0x0103;                                // set PB1 as GPIO input, pull ups enabled

// if PB[0] pin is high then set PB[1] high, else put it low

if(SIU.GPDI[16].R) SIU.GPDO[17].R = 0x1;            

else SIU.GPDO[17].R = 0;

BR, Petr

在原帖中查看解决方案

1 回复
1,319 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

Please refer to the following posted example; https://community.freescale.com/docs/DOC-329563.

It gives you basic demo code. It also set one pin to GPIO output and toggle it within timer interrupt.

To set the pin as input you need to set the SIU.PCR[x].IBE bit and read the pad level from the respective SIU.GPDI[x] register.

For example like this

SIU.PCR[16].R = 0x0200;                                // set PB0 as GPIO output

SIU.PCR[17].R = 0x0103;                                // set PB1 as GPIO input, pull ups enabled

// if PB[0] pin is high then set PB[1] high, else put it low

if(SIU.GPDI[16].R) SIU.GPDO[17].R = 0x1;            

else SIU.GPDO[17].R = 0;

BR, Petr