- This topic has 3 replies, 4 voices, and was last updated 11 years, 9 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
|
Microcontroller › AVR › what is bit masking?????
iam using atmega16 microcontroller
some one told me that if we want to
check for a single input pin
we need bit masking.
what is bit masking???????????
hello..
A bit mask is a variable used with logical operators.
Assuming you want to read the 5th pin of Portb (actually any port)
variable=PINB&(1<<PB5) // where pb5 refers to the 5th pin…PINB is used to read the values of a port
This is your mask.. it stores the value at the 5th pin into the variable
Hi,
It is nothing but any logic which you’ve applied to change the value of any one of the required port bits keeping the values of other bits unchanged.
Bit masking is used to ignore the status of particular bit.
you can check input status by using ‘&’ operater like “PINC&(1<<PC2)” if you want to read status of PC2 similarly for oter pins.
use ‘|’ or operator for writing a single bit like PORTC |= (1<<PC4) to write logic high at PC4.