#picaxe 28X2
#no_data
#no_table
'#terminal 76800
symbol xx = b0
symbol xxx = b1
symbol xxxx = b2
symbol xxxxx = b3
symbol ticked = b4
symbol timerLED = b5
symbol timediv = b6
symbol LED_0 = b7
symbol LED_1 = b8
symbol LED_2 = b9
symbol LED_3 = b10
symbol LED_4 = b11
symbol LED_5 = b12
symbol LED_6 = b13
symbol LED_7 = b14
symbol LED_8 = b15
symbol LED_9 = b16
symbol LED_10 = b17
symbol LED_11 = b18
symbol LED_12 = b19
symbol LED_13 = b20
symbol G = b21
symbol H = b22
symbol K = b23
symbol LEDdelay = w25
symbol oldtime = w26
symbol newtime = w27
symbol timedivrate = 3
#Macro macShowLed(var)
ptr = var << 1
dirsB = 0
dirsC = 0
Low @ptrInc
High @ptr
Pause LEDdelay
#EndMacro
' ************************************************** ************************
' Code starts here
' ************************************************** ************************
setfreq em64
pause 1000
LEDdelay = 5
timediv = timedivrate
tmr3setup %00110011 ' 1:8 prescaler, the slowest it will go !
' Copy LED data from LOOKUP to scratchpad RAM
ptr = 0
for b2 = 0 to 125
gosub look_up
@ptrinc = b0 : @ptrinc = b1
next
b0 = 0 ' Reset b0, needed later
' Preset LED positions
LED_0 = 0
LED_1 = 10
LED_2 = 20
LED_3 = 30
LED_4 = 40
LED_5 = 50
LED_6 = 58
LED_7 = 66
LED_8 = 56
LED_9 = 46
LED_10 = 38
LED_11 = 104
LED_12 = 112
LED_13 = 120
' Main loop
' ---------
do
' Light the LEDs
macShowLED(LED_0)
macShowLED(LED_1)
' macShowLED(LED_2)
macShowLED(LED_3)
macShowLED(LED_4)
macShowLED(LED_5)
macShowLED(LED_6)
macShowLED(LED_7)
macShowLED(LED_8)
macShowLED(LED_9)
macShowLED(LED_10)
' macShowLED(LED_11)
' macShowLED(LED_12)
' macShowLED(LED_13)
' Flash activity LED on each clock tick
if ticked = 1 then
macShowLED(125)
Endif
' Detect time change
newtime = timer3
if newtime <> oldtime then
oldtime = newtime
dec timediv
if timediv = 0 then
timediv = timedivrate ' Reset time divider
gosub clockticked ' Go do stuff
endif
endif
loop ' End of main loop
' ************************************************** ***************************
' Subroutines
' ************************************************** ***************************
look_up: 'lookup LED pins into b0, b1
lookup b2, ($205, $206, $207, $208, $209, $20A, $20D, $20C, $20B,_
$502, $602, $702, $802, $902, $A02, $D02, $C02, $B02,_
$005, $006, $007, $008, $009, $00A, $00D, $00C, $00B,_
$500, $600, $700, $800, $900, $A00, $D00, $C00, $B00,_
$105, $106, $107, $108, $109, $10A, $10D, $10C, $10B,_
$501, $601, $701, $801, $901, $A01, $D01, $C01, $B01,_
$50B, $60B, $70B, $80B, $90B, $A0B, $D0B, $C0B, $B0C,_
$50C, $60C, $70C, $80C, $90C, $A0C, $D0C, $C0D, $B0D,_
$50D, $60D, $70D, $80D, $90D, $A0D, $D0A, $C0A, $B0A,_
$50A, $60A, $70A, $80A, $90A, $A09, $D09, $C09, $B09,_
$509, $609, $709, $809, $908, $A08, $D08, $C08, $B08,_
$508, $608, $708, $807, $907, $A07, $D07, $C07, $B07,_
$507, $607, $706, $806, $906, $A06, $D06, $C06, $B06,_
$506, $605, $705, $805, $905, $A05, $D05, $C05, $B05 _
),w0
return
clockticked:
ticked = ticked xor 1 ' Toggle activity LED
' inc H : if H > 11 then : H = 0 : endif
' lookup H, (88, 70, 52, 51, 49, 47, 46, 64, 82, 83, 85, 87), H_LED
inc K : if K > 41 then : K = 0 : endif
lookup K, (117, 108, 99, 90, 81, 72, 63, 54, 45, 36, 27, 18, 9, 0,_
1,2,3,4,5,6,7,8,_
17,26,35,44,53,62,71,80,89,98,107,116,125,_
124,123,122,121,120,119,118), LED_0
xxx=41-K
lookup xxx,(117, 108, 99, 90, 81, 72, 63, 54, 45, 36, 27, 18, 9, 0,_
1,2,3,4,5,6,7,8,_
17,26,35,44,53,62,71,80,89,98,107,116,125,_
124,123,122,121,120,119,118) , LED_1
inc G : if G > 11 then : G = 0 : endif
lookup G,(1,1,1,9,9,9,255,255,255,247,247,247),H
' LED_0 = LED_0 + H
' LED_1 = LED_1 - 10
' LED_2 = LED_2 - 10
LED_3 = LED_3 + H
LED_4 = LED_4 + H
LED_5 = LED_5 + H
LED_6 = LED_6 + H
LED_7 = LED_7 + H
LED_8 = LED_8 + H
LED_9 = LED_9 + H
LED_10 = LED_10 + H
' LED_11 = LED_11 - 10
' LED_12 = LED_12 - 10
' LED_13 = LED_13 - 10
return