Can you explain what bitmasking is, and how it works and what it's used for?

There are many instances where we simply want to know what the value of one port, or some particular bits in the status register are. Masking all other bits will essentially isolate this bit, regardless of the other values within the register by making all other bits equal to 0.For example, lets say PORTA has been set to that D0 D1 and D2 are inputs, and the other bits are outputs. The system needs know what the value is of D0 and D1 . To mask all the unnecessary bits we work out the binary value when D0 and D1 are both equal to 1 and all other bits are equal to 0. This gives us 0000 0011 (remembering the least significant bit goes on the right), which is equal to 21+ 20=> 2+1 =3. We move PORTA into the working register and then AND this with 0x03, and the two target bits will be isolated. Lets see an example of this (eg when PORTA has value 1001 1110): https://imgur.com/GzDpTmYAs you can see, D0 and D1 have kept their values whilst all other bits have been made 0. Essentially when you use the ANDW function, it compares every bit in the working register, with each corresponding bit declared with the ANDW function and ANDs them as per usual, for example looking at the bit D7 the program computes 1 AND 0 = 0, for D6 0 AND 0 = 0, and so on. Because you have kept the two least significant bits high (or whichever bits you are bitmasking for), their value will be unchanged (ie X AND 1 = X, whereas X AND 0 = 0). This technique might be used, for example, to turn on a water heater when a temperature sensor indicates the water temperature is below a certain value, by using the JPZ/JMP functions.

Related Electronics A Level answers

All answers ▸

Graph question Q1a in AQA 2016


Why a cable that transmit voltage increase its lengths?


Find the Thevenin equivalent circuit of the circuit shown here : https://imgur.com/9DtrDF2


Explain what 'selecivity' is in the context of a radio receiver, and describe how a superhet receiver is more selective than a standard radio receiver


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy