1. I am using WSD2811 to run led in series. I am using C-code for programming. My below code is working by carefully adjusting some of NOP instructions.
2. 100 leds are working fine on WSD2811, my code is in C, so no issues. Dont want to write in assembly.
3. Below is my code, in which I check each bit of red/green/blue by if/else, then make pin high/low
4. Want to know if there any other way I can optimize code in c language or better way to do that in C-language.
5. Please dont suggest to write in assembly or if code is already working why to change.
I want to write in C only, & check if there any way I can further optimize code in C language.
Again by current code, my leds are working fine
2. 100 leds are working fine on WSD2811, my code is in C, so no issues. Dont want to write in assembly.
3. Below is my code, in which I check each bit of red/green/blue by if/else, then make pin high/low
4. Want to know if there any other way I can optimize code in c language or better way to do that in C-language.
5. Please dont suggest to write in assembly or if code is already working why to change.
I want to write in C only, & check if there any way I can further optimize code in C language.
Again by current code, my leds are working fine
Code:
static void ws2811_rgb_write(uint8_t red, uint8_t green , uint8_t blue)
{
//R1
if(red & 0x80U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R2
if(red & 0x40U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R3
if(red & 0x20U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R4
if(red & 0x10U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R5
if(red & 0x08U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R6
if(red & 0x04U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R7
if(red & 0x02U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R8
if(red & 0x01U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R1
if(green & 0x80U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R2
if(green & 0x40U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R3
if(green & 0x20U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R4
if(green & 0x10U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R5
if(green & 0x08U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R6
if(green & 0x04U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R7
if(green & 0x02U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R8
if(green & 0x01U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R1
if(blue & 0x80U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R2
if(blue & 0x40U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R3
if(blue & 0x20U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R4
if(blue & 0x10U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R5
if(blue & 0x08U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R6
if(blue & 0x04U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R7
if(blue & 0x02U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
//R8
if(blue & 0x01U)
{
LED_PIN_HIGH();
}
else
{
LED_PIN_LOW();
}
///
}