main:
PORTB = writeport(LATB, 3, 1)
PORTC = writeport(LATC, 2, 0)
PORTB = writeport(LATB, 6, 1)
PORTC = writeport(LATC, 1, 0)
Goto main
End
Function writeport(port As Byte, pin As Byte, condition As Byte) As Byte
Dim idx As Byte
Dim buf As Byte
idx = LookUp(1, 2, 4, 8, 16, 32, 64, 128), pin 'POWER OF 2
buf = port 'READ PORT ( LATCH )
idx = Not idx 'INVERT ALL BUT PIN
buf = buf And idx 'AND TO CLEAR BIT
If condition = 0 Then 'IF PIN NEEDS CLEARING FIN HERE
writeport = buf 'RETURN WITH ONLY THAT PIN CLEARED
Exit
Endif
idx = Not idx 'OTHERWISE WE NEED TO
buf = buf Or idx 'SET JUST THAT PIN
writeport = buf ' ALL DONE
End Function