This line
PortB = LO_nibble & %00001111, for WRITING LSB data to PortB (output pins)
Will set bits 4-7 to 0. So it will corrupt high nibble.
You can use this
PORTB=(PORTB & %11110000) | (LO_nibble & %00001111)
But this will cause RMW issue if there is any capacitive load on pins or if slew rate is limited.
There is workaround that, your port is set to output. So there is no need to read state from PORTB.
If you are using 18F then use LATB register.
Or for all PIC declare another variable eg PortBState.
And change state of individual bits in PortBState, and after then write that value to PORTB.
PortBState var byte
PortBState =(PortBState & %11110000) | (LO_nibble & %00001111)
PORTB=PortBState
For high nibble
PortBState =(PortBState & %00001111) | (HI_nibble & %11110000)
PORTB=PortBState
But from your example HI_nibble=11 won't do anything. Because hi nibble of port is reference to high nibble of variable.
If you want to reference hi nibble of port to low nibble of byte then shift value to left.
PortBState =(PortBState & %00001111) | ((HI_nibble<<4) & %11110000)
PORTB=PortBState
Bookmarks