• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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

Not open for further replies.


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.


Active Member
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
Not open for further replies.

Latest threads

EE World Online Articles