Checking Pin State

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Checking Pin State

426 Views
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.

Labels (1)
0 Kudos
1 Reply

312 Views
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 Kudos