Hello all,
here is, if someone interested my simple one (or more) neopixel driver. In demo it fades through basic RGB colours. Code is simply modifiable to lit up any kind of colour. Only changing the NeoRed, NeoGreen, NeoBlue variables.
Code:
'****************************************************************
'* Name : One_Neopixel_driver *
'* Author : Louis *
'* Notice : Copyright (c) 2019 *
'* : All Rights Reserved *
'* Date : 1. 12. 2019 *
'* Version : 1.0 *
'* Notes : *
'* : 12F1840 *
'****************************************************************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
__config _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_ON & _BORV_19 & _LVP_OFF
#ENDCONFIG
DEFINE OSC 32 ; Use internal clock 32MHz
OSCCON = %11110000 ; 8 MHz internal x 4
OSCTUNE = %00000000 ; Internal osc tunning
WHILE !OSCSTAT.3 ; Wait for stable OSC
WEND
TRISA = 0
ANSELA = 0
OPTION_REG.7=1 ; disable internal pull-ups
ADCON0 = 0
ADCON1 = 0
;------------ Variables ---------------------
NeoGreen VAR BYTe
NeoBlue VAR BYTE
NeoRed VAR BYTE
NeoPixel VAR BYTE
BitCount VAR BYTE
DataBit VAR byte
Cnt var byte
n var byte
Flag var bit
;------------ ALIAS -------------------------
NeoPin VAR porta.2
;----------- Initialization ----------------
Clear ; Clear All
;------------ Main program ------------------
Main:
pause 10
if flag = 0 then
n=n+1
else
n=n-1
if n=0 then
flag = 0
cnt = cnt + 1
endif
endif
if n = 254 then flag = 1
if cnt > 2 then cnt = 0
if cnt = 0 then
NeoGreen = n ; value 0-254 for green color
else
NeoGreen = 0
endif
if cnt = 1 then
Neoblue = n ; value 0-254 for blue color
else
Neoblue = 0
endif
if cnt = 2 then
Neored = n ; value 0-254 for red color
else
Neored = 0
endif
gosub NeoDraw
GOTO Main
END
;------------ Extract bites ---------------
NeoDraw:
FOR BitCount = 7 TO 0 step -1
DataBit = NeoGreen.0[bitcount]
GOSUB NeoBit
NEXT
FOR BitCount = 7 TO 0 step -1
DataBit = NeoRed.0[bitcount]
GOSUB NeoBit
NEXT
FOR BitCount = 7 TO 0 step -1
DataBit = NeoBlue.0[bitcount]
GOSUB NeoBit
NEXT
RETURN
;------------ Pulse generator ---------------
NeoBit:
IF DataBit = 1 THEN
;generate 800ns pulse
NeoPin = 1
ASM
nop
nop
nop
nop
nop
ENDASM
NeoPin = 0
ELSE
;generate 400ns pulse
NeoPin = 1
ASM
nop
nop
ENDASM
NeoPin = 0
ENDIF
RETURN
Bookmarks