# Setting several output-pins at a time, but not all

Status
Not open for further replies.

#### egh01

##### New Member
Lets say I use 4 pins on PORTB (we're talking 16f84a here) connected as data lines to a LCD display in 4-bit mode. If I want to send something to the LCD I would to something like this:
-movlw 'H'
-swap the nibbles
-AND with 0x0f to clear out the upper bits
-movwf PORTB

But this would make all ouput use of the other 4 pins on PORTB impossible wouldn't it? I mean this would set those pins to zero no matter if I want to or not. How are input pins affected? How would you solve this?
I guess there is a simple solution for this that I have missed. I don't want to check all the bits of the swaped byte and then manually set or clear all the pins, that feels like a pretty cycle-consuming method.

#### Exo

##### Active Member
Code:
MOVLW    'H'
MOVWF    TempVar            ;save the value
SWAPF    TempVar, W         ;and swap its nibbles, save to W
ANDLW    b'00001111'        ;AND with 0x0f to clear out the upper bits
MOVWF    TempVar            ;save it temporary

MOVF     PORTB, W           ;copy portb value to W
ANDLW    b'11110000'        ;'And' it so only the upper 4 bits remain
IORWF    TempVar, W         ;OR the value with W; save to W
MOVWF    PORTB              ;save to portb

#### egh01

##### New Member
Oh so thats how you do, that was smart and simple.

Thanks!

Status
Not open for further replies.