• ### PicŪ Basic

A PORT usually have 8 output / input pins. Sometimes we need to `scan' a PORT to check which pins are high and which pins are low.

Code:
```Dim Temp as Byte

Temp = PORTB   'Temp will include full picture of PORTB
Temp = PORTB & 000011 'Temp will have the value of bits 1 and 0
Temp = PORTB & 000000 'Temp will have the value of bit 6
Temp = PORTB & 001111 'Temp will have the value of the least 4 bits```
In the examples above you could have written:
Temp = PORTB & 3 instead of PORTB & 000011
Temp = PORTB & 64 instead of PORTB & 000000
Temp = PORTB & 15 instead of PORTB & 001111
but by using binary it is easier to see which bits of the port you are masking.

Temp will return a decimal value according to the logic binary of that PORT. What happens when we need to `scan' only the first 4 pins of a PORT or whatever pins on a PORT depending on the wiring and you need to use the rest as input or outputs?

If the required pins are not masked, then all the PORT will be read, and a wrong value will be read depending on what state the `not scaned' pins are. If you mask a part of a PORT, then you only read the pins you have masked.

http://www.protonbasic.co.uk/showthr...011#post454011

Joseph