Dear Sir De La Demon 
Everything is based on logical operation. you can use Decimal, Hex or binary... use the one you're confortable with
Boolean operation, short tutorial and truth table
Short example:
I have 4 push buttons attach to PORTB<3:0> (<3:0> mean on PORTB.0, PORTB.1, PORTB.2 AND PORTB.3) the other PORTB pins ae used for something else.
I want to read the status of those pushbutton and discard the other pins. In this case you have two choice. Read every single bit OR read the whole PORT and keep only PORTB<3:0>. I prefer the last one.
To keep only the 4 lower bits you can use bitwise AND
Code:
PushButton=PORTB & $0F
OR
Code:
PushButton=PORTB & 15
OR
Code:
PushButton=PORTB & %00001111
OR bitwise OR
Code:
PushButton=PORTB | $F0
OR
Code:
PushButton=PORTB | 240
OR
Code:
PushButton=PORTB | %11110000
Depending of your pushButton 'normal state' you'll read the result as follow. In my case 'normal state=0'
Code:
'
' Reading PushButtons on PORTB
' Using AND
'
start:
PushButton=PORTB & $0F ' or PORTB & %00001111
'
' Using select case to handle pushbutton and
' jump to specific Subroutines
'
Select case PushButton
case 1 ' %00000001 or $1
Gosub PORTB_0
case 2 ' %00000010 or $2
Gosub PORTB_1
case 4 ' %00000100 or $4
Gosub PORTB_2
case 8 ' %00001000 or $8
Gosub PORTB_3
end select
You can even use bitwise OR and change the results...
Code:
'
' Reading PushButtons on PORTB
' Using AND
'
start:
PushButton=PORTB | $F0 ' or PORTB | %11110000
'
' Using select case to handle pushbutton and
' jump to specific Subroutines
'
Select case PushButton
case 241 ' %11110001 or $F1
Gosub PORTB_0
case 242 ' %11110010 or $F2
Gosub PORTB_1
case 244 ' %11110100 or $F4
Gosub PORTB_2
case 248 ' %11111000 or $F8
Gosub PORTB_3
end select
Now let's say that i want to turn off a led on a specific PORTB pin.
Code:
LedOnPORTB var byte
LedOnPORTB=%11001111
PORTB=LedOnPORTB
'
' Let's turn off the LED on PORTB.7
'
LedOnPORTB=LedOnPORTB %01111111
PORTB=LedOnPORTB
that's just an example, read and understand the boolean operator, you'll find them handy... even if you just want to toglle a bit state..
Code:
PORTB=%11110001
start:
PORTB.0=PORTB.0 ^ 1
pause 500
goto start
this will blink led on PORTB.0
HTH
EDIT: DOH! just notice you found something... BAH, this could be handy for somebody here.. one day or another... i guess.

Originally Posted by
VieilleChose
The application I have right now is how to control bits within the address byte (A0, A1 and A2). I have 7 MCP23016 I/O expanders and I'd like to poll them in a loop.
You can even use an array to store their specific control byte then use it in a loop
Code:
IOExpander var byte[7]
IOExpander[0]=%11110000
IOExpander[1]=%11110001
IOExpander[2]=%11110010
IOExpander[3]=%11110011
IOExpander[4]=%11110100
IOExpander[5]=%11110101
IOExpander[6]=%11110110
For Loop = 0 to 6
I2cWRITE blah,blah2,IoExpander[Loop],[SteakBledindePatate]
pause 5
next
Bookmarks