• 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.

Assembly question..

Status
Not open for further replies.

rewguy

New Member
Is there a way in PIC assembler to set all bits of a register to 1 without using the W register? Basically, I want to do this:

Code:
movlw    0xFF
moxwf    PORTB
Except I want to preserve what was in the w register. It would simply be a reversal of

Code:
CLRF     PORTB
The reason I want to do this is in displaying a 4 digit number on 7 seg LEDs with common Anode. I want to turn on a number and call the delay. Then after the delay, I want to call the lookup table for the next number, Set PortA to all 1s (turn off the display), do RLF to get to the next digit, then finally put the contents of w back on PortB. The code looks like this:

Code:
<Some digits is being displayed> ;when both PortA and PortB are low, digit is displayed

         call           Delay

         movlw          h'06'          ;Put some number (6) in the W register
         call           LUTable        ;Call the lookup Table with 6
        __?__         PORTB          ;Turn off all LEDS momentarily
         RLF            PORTA          ;Move to the next digit
                                       ;NOTE: W is still value of 6 in LED format
         movwf          PORTB          ;Load PORTB with new number
                                             ;digit is displayed
I know that people normally just use the lookup table afterthey have turned off the LED, but doesn't this mean you have to make your delay faster to reduce flicker? Wouldn't it be much clearer if the lookup table was called while the LED was on?
 

Exo

Active Member
There isn't such a instruction...
Save your W register to RAM temporarily or just call the table while leds are off. Even at 4Mhz pic does this so fast you won't even notice
 

motion

New Member
Code:
    MOVWF    PORTB       ; Set some of the bits
    XORLW    H'FF'          ; Invert W reg
    IORWF    PORTB,F    ;Set the rest of the bits
    XORLW    H'FF'          ; Reverse inversion
 

Exo

Active Member
motion said:
Code:
    MOVWF    PORTB       ; Set some of the bits
    XORLW    H'FF'          ; Invert W reg
    IORWF    PORTB,F    ;Set the rest of the bits
    XORLW    H'FF'          ; Reverse inversion
problem is all the bits won't be set at once... if the loop is reapeated fast enough it might be visible :?
 

motion

New Member
Get real! Even you said that the the PIC is fast enough that the difference would not be noticable. A 2usec difference in timing even for a delay loop of 1msec would not be detected even if you have eyes of a fly. Besides, setting the bits turns off the LEDs.

You would be getting greater variations in timing through the delay loop.
 

Exo

Active Member
i said turning it off - loading the lookup table - turning it on. will almost not be visible. (maybe a little bit dimmer)

because you have nothing - a value - nothing -... you won't see anything mixed

But displaying a certain value for a time. Another for a shorter time in a tight loop (he might be running that loop 50000 times a second for all we know) i think it's possible the other value shimmers trough a little.

I'm not saying it is so. I'm just saying such things are ofthen much diffirent in practice then in theory. The only way to know for sure is to test it :)
 

motion

New Member
In practical applications you don't multiplex displays at such a tight loop. Even a 1 msec loop is very tight. So in the real world, the kind of problems you are suggesting is non-existent.

Another thing, this code segment is normally part of a bigger program where other tasks are being performed. So the delay through the loop will vary far greater than 2usec.

Thirdly, each LED is current limited by a resistor of up to 5% tolerance. That should produce a much wider variation in light intensity.

I suggest you try it in the real world and see for yourself.

BTW, the code needs a slight change.

Code:
    IORWF    PORTB,F       ; Set some of the bits 
    XORLW    H'FF'          ; Invert W reg 
    IORWF    PORTB,F    ;Set the rest of the bits 
    XORLW    H'FF'          ; Reverse inversion
This will prevent LED segments that are already turned off from being turned ON momentarily.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top