How to detect GPIO 0 or 1?

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

How to detect GPIO 0 or 1?

1,496 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Spencer on Thu Sep 29 06:04:07 MST 2011
Dear sir:

In LPC1114, for example:
I want to use a two pin switch change GPIO status.
How to detect GPIO 0 or 1?

Thanks a lot.
0 项奖励
回复
6 回复数

1,485 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Fri Sep 30 03:29:21 MST 2011

Quote: Spencer
Dear Zero sir:

What is the following means?

#define READ_PIN (1<5)

Thanks



That 1 is less than 5. :p

What you probably want to know is (1<<5), which shifts a hexadecimal 0x01 five positions to the left. You can search for "bitwise operators" or "bitwise shift" on Google which will explain what this means, but you will also need to understand hexadecimal numbers for this to make much sense so you may want to do some reading on that as well.

Update: Here is a tutorial I wrote a long time ago that may help:
http://www.microbuilder.eu/Tutorials/Fundamentals/Bitwise.aspx
0 项奖励
回复

1,485 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Spencer on Fri Sep 30 02:45:18 MST 2011
Dear Zero sir:

What is the following means?

#define READ_PIN    (1<5)

Thanks
0 项奖励
回复

1,485 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Wenzu on Thu Sep 29 10:32:48 MST 2011
!!lol!!  I love your replies ....Zero :)
0 项奖励
回复

1,485 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Sep 29 07:09:49 MST 2011
You might also find this thread of use...

http://knowledgebase.nxp.com/showpost.php?p=1276&postcount=2

Regards,
CodeRedSupport
0 项奖励
回复

1,485 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Sep 29 06:32:10 MST 2011
Set your pin to input and read data register:

//Reading bit 5 of P0
#define READ_PIN    (1<<5)    //shift to select bit 5

LPC_GPIO0->DIR &= ~(READ_PIN);        //input

if(LPC_GPIO0->DATA & READ_PIN)        //read it
 {
//wow, my pin is high
 }
 else
 {
//damned, my pin is low
 }
0 项奖励
回复

1,485 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Luis Digital on Thu Sep 29 06:27:11 MST 2011
Using interrupts (PIOINT0_IRQHandler or PIOINT1_IRQHandler).
0 项奖励
回复