read portb

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi
This one is silly but I am not able to figure out this bitwise operation.

I connect four sensors to lower nibble of portb pb0:3 on atmega32.

I am able to read each bit, I am able to read pinb to get the entire byte ...

How can I read just the lower nibble ? I mean with least number of lines.
I tried to AND PINB value to 0x0f but that overwrites the higher nibble pb4:7.

Thanks
K

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I tried to AND PINB value to 0x0f but that overwrites the higher nibble pb4:7.

But surely that's what you want?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"You" use an auxilliary unsigned int8 , copy Portb contents into it -not to interfere with the real port- , then "and" it with 0x0F

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was writing to PINB value after anding.

PINB &=PINB&0x0F
Send=PINB

That was actually silly of me ... I think I need sleep... Thanks guys