DEVICE 18F452 XTAL 20 DIM I AS BYTE ' simple counter! DIM BigI AS WORD Dim LoopCount AS BYTE Dim SwBuf1 AS BYTE Dim SwBuf2 AS BYTE Dim Pattern AS BYTE Dim PatIDX AS BYTE Dim RedBank AS BYTE Dim BlueBank AS BYTE Dim GreenBank AS BYTE BOOTLOADER = ON PORTB_PULLUPS = OFF ' disable PORTB's internal pullups ALL_DIGITAL = TRUE ' disable analog inputs Symbol LED = PORTA.0 ' Status LED Symbol SW1 = PORTA.1 Symbol SW2 = PORTA.2 Symbol DTA = PORTC.0 Symbol Clock = PORTC.1 Symbol Latch = PORTC.2 Symbol SClr = PORTC.3 Symbol Ena = PORTC.4 Symbol TheDelay = 70 TRISA = %00000110 TRISB = 0 TRISC = 0 TRISD = 0 Pattern = 0 PatIDX = 0 'setup some initial states High SCLR Low Latch Low Clock Low DTA Low Ena ' Gosub AllOff: DelayMS 1000 BigI = 0 LoopCount = 4 Repeat ' blue center out of black PatIDX = LoopCount: Gosub GetPat RedBank = Pattern GoSub DoShift: DelayMS TheDelay * 6 Inc LoopCount Until LoopCount > 6 GoSUB AllRed: DelayMS TheDelay * 6 Again: Repeat LoopCount = 4 Repeat ' blue/green center out of red PatIDX = LoopCount: Gosub GetPat BlueBank = Pattern I = LoopCount - 1 If I >= 4 then If I > 6 then I = 6 PatIDX = I: GoSub GetPat: GreenBank = Pattern BlueBank = $FF ^ GreenBank ^ BlueBank RedBank = BlueBank ^ GreenBank Else RedBank = $FF ^ BlueBank End If GoSub DoShift: DelayMS TheDelay Inc LoopCount Until LoopCount > 7 GoSub AllGreen: DelayMS TheDelay LoopCount = 4 Repeat ' red/blue center out of green PatIDX = LoopCount: Gosub GetPat RedBank = Pattern I = LoopCount - 1 If I >= 4 then If I > 6 then I = 6 PatIDX = I: GoSub GetPat: BlueBank = Pattern RedBank = $FF ^ BlueBank ^ RedBank GreenBank = BlueBank ^ RedBank Else GreenBank = $FF ^ RedBank End If GoSub DoShift: DelayMS TheDelay Inc LoopCount Until LoopCount > 7 GoSub AllBlue: DelayMS TheDelay LoopCount = 4 Repeat ' red/green center out of blue PatIDX = LoopCount: Gosub GetPat GreenBank = Pattern I = LoopCount - 1 If I >= 4 then If I > 6 then I = 6 PatIDX = I: GoSub GetPat: RedBank = Pattern GreenBank = $FF ^ RedBank ^ GreenBank BlueBank = GreenBank ^ RedBank Else BlueBank = $FF ^ GreenBank End If GoSub DoShift: DelayMS TheDelay Inc LoopCount Until LoopCount > 7 GoSub AllRed: DelayMS TheDelay Inc BigI Until BigI > 4 Goto Again LoopCount = 6 Repeat ' red to black PatIDX = LoopCount: Gosub GetPat RedBank = Pattern: GoSub DoShift: DelayMS TheDelay * 6 Dec LoopCount Until LoopCount < 4 GoSub AllOff: DelayMS TheDelay * 6 End AllGreen: RedBank = $FF: BlueBank = $FF: GreenBank = $0 ' all greens on Goto DoShift AllBlue: RedBank = $FF: BlueBank = $0: GreenBank = $FF ' all blues on Goto DoShift AllRed: RedBank = $0: BlueBank = $FF: GreenBank = $FF ' all reds on Goto DoShift AllOff: RedBank = $FF: BlueBank = $FF: GreenBank = $FF ' all off Goto DoShift GetPat: Pattern = LOOKUPL PatIdx, [24, 60, 126, 255, 231, 195, 129, 0] Return DoShift: ' shift data out to the registers SHOUT DTA, Clock, LSBFirst, [RedBank, BlueBank, GreenBank] PulsOut Latch, 1 ' pulse latch Return