Checking Pin State

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

Checking Pin State

845 次查看
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 回复

731 次查看
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 项奖励
回复