pic16f886 / mplab help with bsf PORTC

Thread Starter

DMCCOY

Joined Mar 8, 2009
1
Hello, I have searched here and elsewhere for the answer to my question but I cannot seem to find it. :confused: I am tyrying to make an 8 bit LED bar graph scroll to the left. But, it only is to shift one time left before returning to main. LED_Location is a variable I have set to keep track of my LED position. Once the count in LED_Location gets to d'8' I have it reseting the count to zero since my leds are 0-7.

It currently is working like a counter, my LED output on PORTC is from what I understand taking the number from LED_Location and representing it in binary dislpay.

What I am trying to accomplish is only one LED is on at a time, and if my value from LED_Location is 1, then I need only PORTC bit1 on, if my value from LED_Location is 3, I need only PORTC bit 3. Right now if LED_Location is 3, im getting PORTC bit1 and bit2 lit up for the b'3' value....

Heres what I have

Left
; Shifts LEDs left one position, to scroll left led location output shifts from 'd' value
; 0 and shifts upward, ie 0,1,2....7, then resets to 0

clrf PORTC ; Clears previous LED
incf LED_Location,f ; adds 1 to previous LED value to scroll left
btfsc LED_Location,3 ; tests if decimal value is 8,there is no led8
clrf LED_Location ; if decimal value is 8 Led location is reset to zero
movf LED_Location,W
movwf PORTC ; led is now lit up depending on value
return

My problem is the movwf PORTC, I need to bsf PORTC (what ever bit is represented by the value of LED_Location)

Any suggestions???
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
Work with it in binary, using the rollleft instruction.

movlw 1
movwf PORTC
Roll:
Call Delay
rlf PORTC, 1 ; Roll PORTC Left 1 Position, from w through carry
goto Roll

Port C would proceed like this:
00000001
00000010
00000100
00001000
00010000
00100000
01000000
10000000
00000000
00000000
00000001
.........


Is that the desired result?

Substituting just the rlf in where you need it will roll the contents of the register left the number of positions you specify, wrapping around through w and carry, so the 0/all off would be when the single bit above is in the carry bit.

In an application that does more than just the above, save w, save carry, set to w PORTC, roll 1 position, restore w and carry. Otherwise w contents will be rolled and odd stuff will happen to both what w was supposed to be, and the display (PORTC). :)
 
Top