Please note that this algorithm is designed to accommodate this hardware configuration, but by no means am I advocating it is the most practical method, especially considering all 8 LED's lit would gobble 50% of the boards potential. It is simply to address a temporary need, but efficient code design in any context is of interest. To the discerning eye, you may have noticed some pins are reversed biased. I know I was surprised that it worked. Don't know if this is characteristic of other bar graph displays, but haven't been able to find a datasheet for this particular model.
Of particular interest is the need to re-write the state of an input pin (pulled high or not). In the simulator I had set PORTB7, but because it wasn't for output masked it out with DDRB. This changed the state of PORTB7 which I hadn't expected.
00 930f push TMP ; Preserve callers value 02 934f push R20 ; Scratch register ; Isolate low nibble and write new value to pins 3:0 on port "B". 04 b145 in R20, PORTB ; Get current state of pins 06 7f40 cbr R20, 15 ; Strip 3:0 will become low nibble of TMP 08 930f push TMP ; We're going to need high nibble later 0a 700f cbr TMP, 0xF0 ; Strip high nibble 0c 2b04 or TMP, R20 ; and replace with existing pin states ; in R20, DDRB ; and TMP, R20 0e b905 out PORTB, TMP ; Write updated register to port 10 910f pop TMP ; Retrieve original value ; Isolate high nibble and update value to pins 7:4 on Port "D" 12 b14b in R20, PORTD ; Get current state 14 704f cbr R20, 0xF0 ; Strip 7:4 replaced by high nibble of TMP 16 7f00 cbr TMP, 15 18 2b04 or TMP, R20 ; Combine high nibble with low nibble "D" ; in R20, DDRD ; and TMP, R20 1a b90b out PORTD, TMP ; Write updated value 1c 914f pop R20 1e 910f pop TMP ; Restore callers value 20 9508 ret
NOTE: The solution has a minor change to it that can be seen in #24