Hello, I'm adding an OG-4 decathron tube to my open source nixie clock project. It being run by separate PIC and own power supply. The tube has following pins, which are being driven by MPSA42 transistors, controlled via PIC12F683. These pins are


Z - reset pin,also lights up, let's call it "zero"
A,B,C - enable pins


So sequence is as follows:


do
pulse Z, then pulse A, B, C in repeating loop, 9 times, after that
pulse A and then pulse B, to lit up remaining dots
loop


This code provides the spinning in clockwise direction (there are also PAUSE statements, to adjust the speed). To reverse the direction, sequence after Z should be C, B, A


So what I want to achieve. It does 1 complete run and comes back to zero. Then starts at 1st dot at right to zero and again makes 1 complete run and comes back to 1st dot. After that, it starts from 2nd dot and makes turn till it reaches 2 again, then starts at 3 and goes to 3 and so on, including 29th dot. Then starts over


I've developed very crude and inefficient code for that, which runs on 12F683. I only have made animation till 10th dot and it already using 1k of available chip memory. Of course, I can switch to say 12F1840, but code is still not that good - any attempt to add say 2 times making the same rotation needs complete code rewrite. So is there a way that my code can be optimized? or I have another idea, Decathron tube can be considered as a kind of shift register, so maybe there is another, more efficient approach of doing the above task?

Here is my code

Code:
'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 15.05.2014                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
ANSEL = %00000000    
CMCON0 = 7 
TRISIO=%00001000
OSCCON = %01110111
'Include "Modedefs.bas"
Define	OSC	8		' Set Xtal Frequency


'	Clk     Var	GPIO.5		' Data is clocked on rising edge of this pin            kviteli
'	Dta  	Var	GPIO.4		' Bits are shifted out of this pin          stafilosferi


ZERO    var     GPIO.0
ONE     VAR     GPIO.4
TWO     VAR     GPIO.1
TRE   VAR      GPIO.2
cik var word  'loop variable
x   var word   'delay variable
increment var word 'incremental variable
lop var word  'also variable
increment=0  'temp
sub var word 'intracounter variable
sub=9
x=30


'INIT tube and reset to 0
inika:
LOW ONE
LOW TWO
LOW TRE
HIGH ZERO
PAUSE x
LOW ZERO


tavi:         


'stage 1______________________________________________
sub=9
gosub sub9
high one  'proper finish?  one and two
pause x
low one
high two
pause x
low two
high zero
pause 1000'delay for display
low zero




'stage 2 ______________________________________________


gosub sub9


gosub subzero
pause 1000
low one


'stage 3____________________________________________


gosub sub9


gosub subzero
pause x
high two
low one
pause 1000
high tre
low two
pause x
low tre


'stage 4____________________________________________
sub=8
gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause 1000
low tre


'stage 5____________________________________________


gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause 1000
low one


'stage 6____________________________________________


gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause x
high two
low one
pause 1000
high tre
low two


'stage 7____________________________________________
pause x
low tre
sub=7
gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
pause 1000
low tre


'stage 8____________________________________________
gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause 1000
low one


'stage 9____________________________________________
'X=100
gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause x
high two
low one
pause 1000
high tre
low two
pause x


'stage 10____________________________________________
low tre
sub=6
gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
pause 1000
low tre




goto tavi


sub9 'subroutine for spinning


for cik=1 to sub 'amount needed for full loop
high one
pause x
high two
low one
pause x
high tre
low two
pause x
low tre
next


return




subzero:


high one  'proper finish?  one and two
pause x
high two
low one
pause x
high zero
low two
pause x'delay for display
high one
low zero 'subzero here


return