Hola a todos, es la primera vez que posteo algo en un foro, por lo que espero darme a entender de buena manera.
Estoy realizando un proyecto con el PIC12F1840 (CPU a 32MHz) para el control de tiras de leds NeoPixel (concretamente con el chip WS2812b) todo esto hasta el momento usando únicamente ensamblador. Me dí cuenta que la tarea es demasiado tediosa para realizarse únicamente en ensamblador, ya que el plan inicial es poder controlar el color y las animaciones de los leds mediante una aplicación en android (planeo usar los conocidos módulos ESP8266 para poder hacer una red y poder controlar los leds desde Internet).
Debido a esto decidí intentar usar XC8 para poder realizar las animaciones, el problema es que el chip WS2812b pide tiempos específicos de estado alto y bajo para poder reconocer los bits que se quieren enviar. Con el CPU a 32MHz es difícil implementar esos tiempos ya que el tiempo total de envío de cada bit debe ser de 1.25uS.
Investigando al respecto encontré que es posible usar el compilador XC8 con código embebido en asm, lo que quiero hacer entonces es implementar la rutina de envío de bits ya que en asm se consiguen los tiempos exactos.
Leí al respecto en el manual del compilador pero no logro hacer que funcione, siempre al momento de compilar me tirar muchos errores y hay varios conceptos que no entiendo.
Adjunto el código que quiero implementar (espero que también le sirva a alguien que quiera usar PIC para controlar estas tiras de leds) esperando que alguien me pueda dar una pista de si es posible o no que esto funcione.
==============================================================================
;Variables usadas para enviar los bits RGB.
;==============================================================================
CBLOCK
ByteR
ByteG
ByteB
ENDC
;===============================================================================
; Rutina para generar los bits necesarios para la comunicación del integrado
; WS2812B.
; La documentación pide un tiempo de 1.25uS +/- 600nS en total para el envío
; del bit .
; Para el bit 0 se requiere un tiempo alto de 0.4 uS +/- 150nS y para el timepo
; bajo 0.85uS +/- 150 ns
; Para el bit 1 se requiere un tiempo alto de 0.8 uS +/- 150 ns y para el tiempo
; bajo 0.45 uS +/- 150nS
; El WS2812B requiere de un tiempo de reset en bajo cuando se ha terminado de
; enviar los 24 bits, tiene que ser al menos de 50uS. Esta rutina se incluye
; en el programa principal.
;================================================================================
NeoBit1
;2 ciclos del call
bsf LATA,RA2 ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
;Tiempo en alto de 750nS
bcf LATA,RA2 ;1 ciclo
return ;2 ciclos
;Tiempo bajo de 250nS, hay que tener en cuenta que al
;salir de la rutina se ejecutan otras instrucciones que
;toman tiempo en realizarse, por lo que consumen tiempo
;de la señal en bajo
;Tiempo total de la rutina 1.166667uS
NeoBit0
;2 ciclos del call
bsf LATA,RA2 ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
;Tiempo en alto de 333.3nS
bcf LATA,RA2 ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
nop ;1 ciclo
return ;2 ciclos
;Tiempo en bajo de 583.31 nS
;Tiempo total de la rutina 1.083333uS
;===============================================================================
; Subrutina para el envio de los bits.
; Se envían individualmente los bits por medio de la rutina que pide el WS2812B
; se evalua cada bit del byte previamente cargado, es importante notar que
; cada goto consume tiempo bajo de la rutina, por ese motivo se redujeron los
; ciclos de la rutina.
;===============================================================================
Enviar_Bits
Enviar_Bit23
btfsc ByteG, 7
goto Enviar_Bit23_1
Enviar_Bit23_0
call NeoBit0
goto Enviar_Bit22
Enviar_Bit23_1
call NeoBit1
Enviar_Bit22
btfsc ByteG, 6
goto Enviar_Bit22_1
Enviar_Bit22_0
call NeoBit0
goto Enviar_Bit21
Enviar_Bit22_1
call NeoBit1
Enviar_Bit21
btfsc ByteG,5
goto Enviar_Bit21_1
Enviar_Bit21_0
call NeoBit0
goto Enviar_Bit20
Enviar_Bit21_1
call NeoBit1
Enviar_Bit20
btfsc ByteG,4
goto Enviar_Bit20_1
Enviar_Bit20_0
call NeoBit0
goto Enviar_Bit19
Enviar_Bit20_1
call NeoBit1
Enviar_Bit19
btfsc ByteG,3
goto Enviar_Bit19_1
Enviar_Bit19_0
call NeoBit0
goto Enviar_Bit18
Enviar_Bit19_1
call NeoBit1
Enviar_Bit18
btfsc ByteG,2
goto Enviar_Bit18_1
Enviar_Bit18_0
call NeoBit0
goto Enviar_Bit17
Enviar_Bit18_1
call NeoBit1
Enviar_Bit17
btfsc ByteG,1
goto Enviar_Bit17_1
Enviar_Bit17_0
call NeoBit0
goto Enviar_Bit16
Enviar_Bit17_1
call NeoBit1
Enviar_Bit16
btfsc ByteG,0
goto Enviar_Bit16_1
Enviar_Bit16_0
call NeoBit0
goto Enviar_Bit15
Enviar_Bit16_1
call NeoBit1
Enviar_Bit15
btfsc ByteR,7
goto Enviar_Bit15_1
Enviar_Bit15_0
call NeoBit0
goto Enviar_Bit14
Enviar_Bit15_1
call NeoBit1
Enviar_Bit14
btfsc ByteR,6
goto Enviar_Bit14_1
Enviar_Bit14_0
call NeoBit0
goto Enviar_Bit13
Enviar_Bit14_1
call NeoBit1
Enviar_Bit13
btfsc ByteR,5
goto Enviar_Bit13_1
Enviar_Bit13_0
call NeoBit0
goto Enviar_Bit12
Enviar_Bit13_1
call NeoBit1
Enviar_Bit12
btfsc ByteR,4
goto Enviar_Bit12_1
Enviar_Bit12_0
call NeoBit0
goto Enviar_Bit11
Enviar_Bit12_1
call NeoBit1
Enviar_Bit11
btfsc ByteR,3
goto Enviar_Bit11_1
Enviar_Bit11_0
call NeoBit0
goto Enviar_Bit10
Enviar_Bit11_1
call NeoBit1
Enviar_Bit10
btfsc ByteR,2
goto Enviar_Bit10_1
Enviar_Bit10_0
call NeoBit0
goto Enviar_Bit9
Enviar_Bit10_1
call NeoBit1
Enviar_Bit9
btfsc ByteR,1
goto Enviar_Bit9_1
Enviar_Bit9_0
call NeoBit0
goto Enviar_Bit8
Enviar_Bit9_1
call NeoBit1
Enviar_Bit8
btfsc ByteR,0
goto Enviar_Bit8_1
Enviar_Bit8_0
call NeoBit0
goto Enviar_Bit7
Enviar_Bit8_1
call NeoBit1
Enviar_Bit7
btfsc ByteB,7
goto Enviar_Bit7_1
Enviar_Bit7_0
call NeoBit0
goto Enviar_Bit6
Enviar_Bit7_1
call NeoBit1
Enviar_Bit6
btfsc ByteB,6
goto Enviar_Bit6_1
Enviar_Bit6_0
call NeoBit0
goto Enviar_Bit5
Enviar_Bit6_1
call NeoBit1
Enviar_Bit5
btfsc ByteB,5
goto Enviar_Bit5_1
Enviar_Bit5_0
call NeoBit0
goto Enviar_Bit4
Enviar_Bit5_1
call NeoBit1
Enviar_Bit4
btfsc ByteB,4
goto Enviar_Bit4_1
Enviar_Bit4_0
call NeoBit0
goto Enviar_Bit3
Enviar_Bit4_1
call NeoBit1
Enviar_Bit3
btfsc ByteB,3
goto Enviar_Bit3_1
Enviar_Bit3_0
call NeoBit0
goto Enviar_Bit2
Enviar_Bit3_1
call NeoBit1
Enviar_Bit2
btfsc ByteB,2
goto Enviar_Bit2_1
Enviar_Bit2_0
call NeoBit0
goto Enviar_Bit1
Enviar_Bit2_1
call NeoBit1
Enviar_Bit1
btfsc ByteB,1
goto Enviar_Bit1_1
Enviar_Bit1_0
call NeoBit0
goto Enviar_Bit0
Enviar_Bit1_1
call NeoBit1
Enviar_Bit0
btfsc ByteB,0
goto Enviar_Bit0_1
Enviar_Bit0_0
call NeoBit0
return
Enviar_Bit0_1
call NeoBit1
return
Muchas gracias por la ayuda!