| Purpose: | Toggle one or more PORT output BITs with the method and timing specified by the WorldSemi® WS2812 LED protocol. | |||
| Assumes: | Each output used should be restored to its incoming state
upon exit. Register R1 might not have its customary value of zero (0). The MCU is being clocked at 8 MHz. |
|||
| Passed: | R25:R24 | BYTE * | bPtrData | pointer to start of the SRAM buffer to transmit, with three (3) BYTEs per pixel |
| R23:R22 | INT | iCount | positive: number of BYTEs (not pixels) to be transmitted OR negative: number of BYTEs (not pixels) to send the WS2812 OFF command |
|
| R20 | BYTE | bPORT | PORT to toggle: 5 (PORTB), 8 (PORTC) or 11 (PORTD) for a 328P | |
| R18 | BYTE | bBitMask | which BIT or BITs are to be modulated with the WS2812 timing protocol | |
| Returns: | Nothing. | |||
| Alters: | R18 through R27, R30, R31, and the FLAGs (SREG) | |||
WS2812_Cmd_PortSet | ||||
| Notes: | Everything (Purpose, Assumes, Passed, Returns, Alters) is the same as WS2812_Cmd above, except: | |||
| Passed: | R21:R20 | WORD | wPORTasSRAM | SRAM address of the PORT in which to toggle the BITs: PORTB = 0x0025, PORTC = 0x0028, PORTD = 0x002B, PORTE = 0x002E, etc. |
| Example: |
|
| Setup: |
|
| Test it: | Attach an 8x8 WS2812 GRB LED array to one of the outputs and power it in order to view the example shown below. |
| An example of that device is the Adafruit® NeoPixel NeoMatrix, Product ID 1487 or 2612. | |
| |
| Notes: | The WS2812_Command System Function validates the PORT BYTE passed. |
| WS2812_Cmd_PortSet does not check the PORT SRAM address WORD passed to it. | |
| Neither function uses any Register below R18, which means that they can be used for small, temporary buffers. | |
| Dropin: (setup code) |
; Setup for the WS2812_Command() call: ; Passed: R25:R24 BYTE * pointer to the first SRAM buffered BYTE to transmit ; R23:R22 INT the number of BYTES to be transmitted ; Note 1: negative value sends OFF to ABS (value) ; Note 2: ATmega memory limits the pixel count ; R20 BYTE the ATmega PORT on which BIT(s) will be toggled ; may only be 5 (PORTB), 8 (PORTC) or 11 (PORTD) ; R18 BYTE bitmask for that PORT's BIT(s) to change ; Returns: Nothing. ; Alters: R18 through R27, R30, R31, and the FLAGs (SREG) ; Setup for the WS2812_Cmd_PortSet() call ; Passed: R25:R24 BYTE * pointer to the first SRAM buffered BYTE to transmit ; R23:R22 INT the number of BYTES to be transmitted ; Note 1: negative value sends OFF to ABS (value) ; Note 2: ATmega memory limits the pixel count ; R21:R20 WORD the SRAM address of the PORT to use (PORTC = 0x28) ; R18 BYTE bitmask for that PORT's BIT(s) to change ; Returns: Nothing. ; Alters: R18 through R27, R30, R31, and the FLAGs (SREG) |
| Also see: | The COM receive and COM transmit buffer status System Functions, the system time and task list configuration and concept web pages, as well as the EEbSystemMode configuration variable and EEfptrWS2812Exts WS2812 extension pointer in EEPROM. |