Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 25th September 2003, 06:36 PM   (permalink)
Default Setting several output-pins at a time, but not all

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.
egh01 is offline   Reply With Quote
Old 25th September 2003, 07:09 PM   (permalink)
Exo
Default

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
Exo is offline   Reply With Quote
Old 25th September 2003, 07:22 PM   (permalink)
Default

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

Thanks!
egh01 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 05:43 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.