int i=0;
DDRD = 0xff;
PORTC = 0xff;
while (1)
{
if(PINC5 == 1)
{...}
I have been trying to figure out why the comparison of PC5 pin of PORTC with 1 yields False everytime. I have activated the "pull up" resistor for every pins of Port C. But still, when I compare the PC5 to 1, I don't get the expected result.
I know the proper way is to do the comparison using the bit-masking.
if((PORTC &(1<<PORTC5))==0).
But I can't figure out why the code presented above doesn't work.
I feel like I am missing some fundamentals in bit-wise operators but can't figure out what exactly. Thank you!!
The datasheet of Atmega 328P says the following:
All registers and bit references in this section are written in general form. A lower case “x” represents the numbering letter for the port, and a lower case “n” represents the bit number. However, when using the register or bit defines in a program, the precise form must be used. For example, PORTB3 for bit no. 3 in Port B, here documented generally as PORTxn.