• PicŪ Basic

  • Masking pins

    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.

    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.

    I found a thread which is very useful when it comes to mask pins of a PORT. Follow this link to see how masking can be done.


  • Recent Activity


    Mysterious PORTB problem

    Thread Starter: xldaedalus

    I'm using Proton+ to develop firmware for a product with switches. The MCU is an 18F26K22. Most of the switches reside on PORTB. I am NOT using a...

    See_Mos Today, 14:44 Go to last post

    Watchdog timer

    Thread Starter: joesaliba

    I have a code that basically looks for four input and four outputs, depends on various timing and input conditions. I use interrupt and some delays...

    Mellbreak Today, 11:30 Go to last post