====== BASCOM WS2812 Knightrider ======
===== rainbow_ws2812_Knightrider =====
'-------------------------------------------------------------------------------
' rainbow_ws2812_Knightrider.bas
'-------------------------------------------------------------------------------
$Regfile = "m88pdef.dat"
$Crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config RAINBOW=1, RB0_LEN=8, RB0_PORT=PORTB,rb0_pin=0
' ^ connected to pin 0
' ^------------ connected to portB
' ^-------------------------- 8 leds on stripe
' ^------------------------------------- 1 channel
'Global Color-variables
Dim Color(3) as Byte
R alias Color(_base) : G alias Color(_base + 1) : B alias Color(_base + 2)
'CONST
const numLeds=8
'----[MAIN]---------------------------------------------------------------------
Dim n as Byte
RB_SelectChannel 0 ' select first channel
R = 50 : G = 0 : B = 100 ' define a color
RB_SetColor 0 , color(1) ' update leds
RB_Send
Do
For n = 1 to Numleds-1
rb_Shiftright 0 , Numleds 'shift to the right all leds except the last one
Waitms 100
RB_Send
Next
For n = 1 to Numleds-1
rb_Shiftleft 0 , Numleds 'shift to the left all leds except the last one
Waitms 100
RB_Send
Next
waitms 500 'wait a bit
Loop
===== rainbow_ws2812_KnightriderDual-RGBW =====
'-------------------------------------------------------------------------------
' rainbow_ws2812_KnightriderDual-RGBW.bas
'-------------------------------------------------------------------------------
$Regfile = "m88pdef.dat"
$Crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config RAINBOW = 1 , rgb = 4 , RB0_LEN = 8 , RB0_PORT = PORTB , rb0_pin = 0
' ^-- using rgbW leds #### MUST BE FIRST PARAMETER when defined ###
' ^ connected to pin 0
' ^------------ connected to portB
' ^-------------------------- 8 leds on stripe
' ^------------------------------------- 1 channel
'Global Color-variables
Dim Color(4) as Byte
R alias Color(_base) : G alias Color(_base + 1) : B alias Color(_base + 2) : W alias color(_base + 3)
'CONST
const numLeds = 8
'----[MAIN]---------------------------------------------------------------------
Dim n as Byte
RB_SelectChannel 0 ' select first channel
R = 50 : G = 0 : B = 100 : w = 10 ' define a color
RB_SetColor 0 , color(_base) ' update led on the left
RB_SetColor numleds - 1 , color(_base) ' update led on the right
RB_Send
waitms 2000
Do
For n = 1 to Numleds / 2 - 1
rb_Shiftright 0 , Numleds / 2 'shift to the right
rb_Shiftleft Numleds / 2 , Numleds / 2 'shift to the left all leds except the last one
Waitms 1000
RB_Send
Next
For n = 1 to Numleds/2 - 1
rb_Shiftleft 0 , Numleds / 2 'shift to the left all leds except the last one
rb_Shiftright Numleds / 2 , Numleds / 2 'shift to the right
Waitms 1000
RB_Send
Next
waitms 500 'wait a bit
Loop
===== ATtiny13 =====
'( 1312-WS2812-T13, Test für max. 12 RGB-Led
BENUTZUNG AUF EIGENE GEFAHR
Achtung : Stromquelle Vor Oder Gleichzeitig Mit Der Datenleitung Anlegen!
Zur Sicherheit wird ein 10k in Reihe mit der Datenleitung Din geschaltet.
Das Rgbfeld wird mit Daten gefüllt,
T0H=250-550 + T0L=700-1000 / T1H=650-950 + T1L=300-600
bedingte Kompilierung für das Maschinensprache-Sub:
MHz= 8 8,0MHz -> 500ns+1000ns/ 875ns+500ns
9,6MHz -> 417ns+ 833ns/ 729ns+417ns
MHz=12 12 MHz -> 500ns+1000ns/ 916ns+500ns
16 MHz -> 375ns+ 750ns/ 688ns+375ns
################################################################################
')
Const Mhz = 8 ' 8-10,7MHz 4+ 8/ 7+4 Cyclen
'Const Mhz = 12 '12-16,9MHz 6+12/11+6 Cyclen
'$PROG &HFF,&H7A,&HFF,&H00' generated. Take care that the chip supports all fuse bytes.
$regfile = "attiny13.dat"
$crystal = 9600000
$hwstack = 8
$swstack = 4
$framesize = 8
Open "comb.4:9600,8,n,1,inverted" For Input As #2 'B.4 <- com-Daten
Ddrb = 1 'B.0 = &18 , 0
Declare Sub Send 'asm-Subroutine
Dim Rgbfeld(36) As Byte 'max.12Led -> r0
Dim Bytmax As Byte : Bytmax = 36 '3*rgb-led -> r17
Dim Inbyte As Byte 'vom com-Port
Dim Index As Byte 'wie der Name sagt
Do 'Main-Loop
'aus Dta1 lesen
' Restore Dta1 : For Index = 1 To Bytmax : Read Rgbfeld(index) : Next Index
'aus com-Port lesen
' Inbyte = Inkey(#2) : If Inbyte > 0 Then : Rgbfeld(index) = Inbyte : If Index >= Bytmax Then Index = 1 Else Incr Index : End If
'Zufallsmuser ausgeben
For Index = 1 To Bytmax : Rgbfeld(index) = Rnd(15) : Next Index : Send : Wait 1
'Ampel
' Restore Dta2 : For Index = 1 To Bytmax : Read Rgbfeld(index) : Next Index : Send : Wait 5 'grün
' Restore Dta3 : For Index = 1 To Bytmax : Read Rgbfeld(index) : Next Index : Send : Wait 2 'gelb
' Restore Dta4 : For Index = 1 To Bytmax : Read Rgbfeld(index) : Next Index : Send : Wait 5 'rot
' Restore Dta5 : For Index = 1 To Bytmax : Read Rgbfeld(index) : Next Index : Send : Wait 2 'rotgelb
Loop
'###############################################################################
Sub Send
push r17 '2
push r16 '2
push r0 '2
Loadadr Bytmax , X 'Bytmax holen
ld r17,x '1
Loadadr Rgbfeld(1) , X 'Feldadr holen
Nextbyte:
ld r0,x+ '2
ldi r16,8 '1
Nextbit:
' T0H=250-550 + T0L=700-1000 / T1H=650-950 + T1L=300-600
' 62,5-137,5 87,5-125 92,9-135,7 75-150
'4+8/7+4 -------------------------------------
#if Mhz = 8 '8 MHz-10,76 MHz
Sbi $18 , 0 '2 <- 2 2
lsl r0 '1 1 1
brcs Bit1 '1/2 1 2
Bit0:
cbi $18 , 0 '2 <- 2
Bit1:
Nop '1 1 1 * ggf. für M8/8M entfernen
dec r16 '1 1 1
cbi $18 , 0 '2 <- 2 2
brne Nextbit '1/2 2 2
#endif
' 41,7-91,7 58,3-83,3 59,1-86,4 50-100
'6+12/11+6 -------------------------------------
#if Mhz <> 8 '12 MHz-16,92 MHz
Sbi $18 , 0 '2 <- 2 2
nop '1 1 1
Nop '1 1 1
lsl r0 '1 1 1
brcs Bit1 '1/2 1 2
Bit0:
cbi $18 , 0 '2 <- 2
Bit1:
Nop '1 1 1
Nop '1 1 1
Nop '1 1 1
dec r16 '1 1 1
cbi $18 , 0 '2 <- 2 2
Nop '1 1 1
nop '1 1 1
brne Nextbit '1/2 2 2
#endif
'-------------------------------------------------------------------------------
Waitus 5
dec r17 '1
cpi r17,0 '1
brne Nextbyte '1/2
'---
pop r0 '2
pop r16 '2
pop r17 '2
End Sub
'################################################################################
Dta1:
' grün rot blau
Data &H0F , &H00 , &H00 'grün
Data &H00 , &H0F , &H00 'rot
Data &H00 , &H00 , &H0F 'blau
Data &H0F , &H0F , &H00 'gelb
Data &H0F , &H00 , &H0F 'cyan
Data &H00 , &H0F , &H0F 'magenta
Data &H0F , &H0F , &H0F 'weiss
Data &H00 , &H00 , &H00 'schwarz
Data &H0F , &H00 , &H00 'grün
Data &H00 , &H0F , &H00 'rot
Data &H00 , &H00 , &H0F 'blau
Data &H0F , &H0F , &H00 'gelb
Data &H0F , &H00 , &H0F 'cyan
Data &H00 , &H0F , &H0F 'magenta
Data &H0F , &H0F , &H0F 'weiss
Data &H00 , &H00 , &H00 'schwarz
Dta2:
' grün rot blau
Data &H0F , &H00 , &H00 'grün
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H0F , &H00 'rot
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H0F , &H00 'rot
Dta3:
' grün rot blau
Data &H00 , &H00 , &H00
Data &H0F , &H0F , &H00 'gelb
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H0F , &H00 'rot
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H0F , &H0F , &H00 'gelb
Data &H00 , &H0F , &H00 'rot
Dta4:
' grün rot blau
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H0F , &H00 'rot
Data &H00 , &H00 , &H00
Data &H0F , &H00 , &H00 'grün
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H0F , &H00 , &H00 'grün
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Dta5:
' grün rot blau
Data &H00 , &H00 , &H00
Data &H0F , &H0F , &H00 'gelb
Data &H00 , &H0F , &H00 'rot
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H00 , &H0F , &H00 'rot
Data &H00 , &H00 , &H00
Data &H00 , &H00 , &H00
Data &H0F , &H0F , &H00 'gelb
Data &H00 , &H00 , &H00
'ENDE