Microchip PIC 16F787X: Is it possible to set fields with variables?

Tag: assembly , pic Author: fordyu Date: 2012-02-21
bsf PORTC, count

This is what I mean, when I do this it uses the value of the relative position of count in memory.(in this case its 2) However what I desire is to use the value that in count to turn on a particular led.

I.E count is 7 so bsf PORTC, count should turn led 7 on.

Best Answer

There is no such single instruction under PIC16 assembler.

But you can do this with multiple instructions something like:

;//count is byte value from 0..7
movf     count, w
btfsc    Zero
bsf      PORTC, 0

decf     WREG
btfsc    Zero
bsf      PORTC, 1

decf     WREG
btfsc    Zero
bsf      PORTC, 2


decf     WREG
btfsc    Zero
bsf      PORTC, 7


I see, I have to explicitly test for it.