Electric rain.
This is an example of the timing you will be trapping (links to source)... not perfect, because this code sometimes skips an LED due to inexact timing...
sketch.s
;------------------------
; Assembly Code
;------------------------
#define __SFR_OFFSET 0x00
#include "avr/io.h"
;------------------------
.global WS2812B
;===============================================================
WS2812B:
;-------
SBI DDRD, 4 ;PD4 o/p (connected to DI of WS2812B)
;---------------------------------------------------------------
again:
;-----------------------------------------------------------
RCALL clr_display ;turn OFF all pixels & reset to pixel 1
;-----------------------------------------------------------
LDI R18, 16 ; 16 x WS2812B
MOV R19, R18
a1: RCALL black ; black
DEC R18
BRNE a1
RCALL red ; red
RCALL delay_ms
DEC R19
MOV R18, R19
CPI R18, 0
BRNE a1
RCALL red ; red
RCALL delay_ms
;-----------------------------------------------------------
RCALL clr_display
;-----------------------------------------------------------
LDI R18, 0
MOV R19, R18
a2: RCALL black ; black
DEC R18
BRNE a2
RCALL blue ; blue
RCALL delay_ms
INC R19
MOV R18, R19
CPI R18, 15
BRNE a2
;-----------------------------------------------------------
RJMP again
;===============================================================
green:
;-----
LDI R17, 8 ;counter for 1st 8 bits
;----------------------------------------------------------
;logic 1 code
;----------------------------------------------------------
l0: SBI PORTD, 4 ;0.80us high pulse
NOP ;NOP = 1 CLK cycle = 0.0625us
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.45us low pulse
NOP
NOP
NOP
NOP
DEC R17
BRNE l0
;----------------------------------------------------------
LDI R17, 16 ;counter for remaining 16 bits
;----------------------------------------------------------
;logic 0 code
;----------------------------------------------------------
l1: SBI PORTD, 4 ;0.40us high pulse
NOP
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.85us low pulse
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DEC R17
BRNE l1
RET
;===============================================================
red:
;---
LDI R17, 8 ;counter for 8 bits
;----------------------------------------------------------
;logic 0 code
;----------------------------------------------------------
l2: SBI PORTD, 4 ;0.40us high pulse
NOP ;NOP = 1 CLK cycle = 0.0625us
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.85us low pulse
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DEC R17
BRNE l2
;----------------------------------------------------------
LDI R17, 8 ;counter for 8 bits
;----------------------------------------------------------
;logic 1 code
;----------------------------------------------------------
l3: SBI PORTD, 4 ;0.80us high pulse
NOP ;NOP = 1 CLK cycle = 0.0625us
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.45us low pulse
NOP
NOP
NOP
NOP
DEC R17
BRNE l3
;----------------------------------------------------------
LDI R17, 8 ;counter for 8 bits
;----------------------------------------------------------
;logic 0 code
;----------------------------------------------------------
l4: SBI PORTD, 4 ;0.40us high pulse
NOP
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.85us low pulse
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DEC R17
BRNE l4
RET
;===============================================================
blue:
;----
LDI R17, 16 ;counter for 16 bits
;----------------------------------------------------------
;logic 0 code
;------------
l5: SBI PORTD, 4 ;0.40us high pulse
NOP
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.85us low pulse
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DEC R17
BRNE l5
;----------------------------------------------------------
LDI R17, 8 ;counter for 8 bits
;----------------------------------------------------------
;logic 1 code
;----------------------------------------------------------
l6: SBI PORTD, 4 ;0.80us high pulse
NOP ;NOP = 1 CLK cycle = 0.0625us
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.45us low pulse
NOP
NOP
NOP
NOP
DEC R17
BRNE l6
RET
;===============================================================
black:
;-----
LDI R17, 24 ;counter for 24 bits
;----------------------------------------------------------
;logic 0 code
;------------
l7: SBI PORTD, 4 ;0.40us high pulse
NOP ;NOP = 1 CLK cycle = 0.0625us
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.85us low pulse
NOP ;we need 14 CLK cycle
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP ;12 NOP = 12 CLK cycles
DEC R17 ;1 CLK cycle
BRNE l7 ;1 CLK cycle
RET
;===============================================================
white:
;-----
LDI R17, 24 ;counter for 24 bits
;----------------------------------------------------------
;logic 1 code
;------------
l8: SBI PORTD, 4 ;0.80us high pulse
NOP ;NOP = 1 CLK cycle = 0.0625us
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
CBI PORTD, 4 ;0.45us low pulse
NOP
NOP
NOP
NOP
DEC R17
BRNE l8
RET
;===============================================================
clr_display:
;-----------
LDI R18, 16 ; number of pixels
agn:RCALL black
DEC R18
BRNE agn
RCALL delay_ms
RET
;===============================================================
delay_ms:
LDI R21, 255
ll0: LDI R22, 255
ll1: LDI R23, 40
ll2: DEC R23
BRNE ll2
DEC R22
BRNE ll1
DEC R21
BRNE ll0
RET
sketch.ino
// Anas Kuzechie
// Assembly via Arduino - Programming WS2812B @ 8m01s
// https://www.youtube.com/watch?v=GA3VnWGf4S4
// https://akuzechie.blogspot.com/2022/01/assembly-via-arduino-programming-ws2812b.html
// Creating Arduino Library for WS2812 - Code 2
// https://www.youtube.com/watch?v=QXlNZXMwl30
//--------------------------------------------
// Assembly via Arduino - Programming WS2812B
//--------------------------------------------
extern "C" {
void WS2812B();
}
void setup() {
WS2812B();
}
void loop(){}