Simpler way of coding?

Andrew Cowan

Senior Member
I'm using an 08M to drive 16 LEDs, via two 74HC595 shift registers.

I have them doing certain patterns in a circle. To generate the patterns, I am generating lookup routines. As I am using an 08M, I am pretty tight on codespace, so a simpler way of doing the following would be nice.

Code:
double:
 for b1=0 to 6
   for b6=0 to 15
     lookup 6,(1,32770,16388,8200,4112,2080,1088,640,256,640,1088,2080,4112,8200,16388,32770),w1
     gosub shift_data_out
     pause 8
   next b6
 next b1
goto main
The lookup data is symmetrical around the 256, although there is a 1 at the left.

In other words, I want b6 to go from 0 to 15 then back to 1, but passing through that lookup each time. Is it possible to do?

A
 

hippy

Ex-Staff (retired)
This saves about 15%, 9 bytes ...

Code:
double:
 for b1=0 to 6
   for b6=0 to 15
     b7 = 16-b6 Max b6
     lookup b7,(1,32770,16388,8200,4112,2080,1088,640,256),w1
     gosub shift_data_out
     pause 8
   next b6
 next b1
goto main
Squeezing another byte out ( not sure if that "90" is right ) ...

Code:
double:
  for b1=0 to 90
   b6 = b1 % 16 
   b7 = 16-b6 Max b6
   lookup b7,(1,32770,16388,8200,4112,2080,1088,640,256),w1
   gosub shift_data_out
   pause 8
  next b1
goto main
If you can change "PAUSE 8" to "PAUSE 7" that saves a little more.
 

womai

Senior Member
Assuming you use the shift_data_out routine only once in your program, you could put the routine's code directly inside the loop and thus save the gosub; should reduce code size a bit more.

Wolfgang
 

westaust55

Moderator
While this is a little irrelevant to the topic since the REV command will only work on X1 and X2 parts,

Here is a routine that saves some space and has no lookup table. Just trying to demonstrate what can be achieved with maths on many occassions.
It takes the same space as hippys first example even with two FOR...NEXT loops and two GOSUB calls.
Just trying to demonstrate what can be achieved with maths on many occassions.

Code:
double:
        b0 = $01

        FOR b6 = 1 TO 9
          b1 = b0 REV 8  * 2   
          IF b0 = 0 THEN : b1 = 1 : ENDIF
          GOSUB shift_data_out
          b0 = b0 * 2
        NEXT b6

        FOR b6 = 1 TO 7
          b1 = b1 * 2
          b0 = b1 REV 8  * 2   
          GOSUB shift_data_out
        NEXT b6

        GOTO main
EDIT:

should mention that having used b0 and b1 above, the word variable is w0 not w1
 
Last edited:
Top