Checking Pin State

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

Checking Pin State

839件の閲覧回数
rayhall
Contributor V

How do I check if a input pin (PAD07) is low or high. I have a 10k pullup on the pin. This is what I have tried,

 

unsigned char pinstate;

 

pinstate = PT0AD0;

 

and

 

pinstate = PT0AD0 & 0x80;

 

and

 

pinstate = PT0AD0_PT0AD07;

 

and

 

pinstate = PT0AD0 & PT0AD0_PT0AD07;

 

 

None of them give me a value that makes sense.

 

Ray.

ラベル(1)
0 件の賞賛
返信
1 返信

725件の閲覧回数
Martin35804
NXP Employee
NXP Employee

Hi,

try to read out the proper port 8 bit value. Just like when you set it.

For instance:

PT0AD |=  1 << PT0AD2;     // sets the bit for the PT0AD2 high = 0b0000 0100 = 0x04

int pinState = PT0AD;          // read the 8bit value of the port to pinState variable that can be visualized in selected from, e.g. hex, bin, dec...

When you want to read pin state you have to read out the whole port register.

0 件の賞賛
返信