On Sat, Aug 16, 2014 at 8:41 PM, peter green wrote: > Bob Ammerman wrote: >> I think Peter's response to this will get you going. However, it is wort= h >> noting that a shift is likely to be _much_ faster than a multiply (unles= s of >> course the compiler is smart enough to see that this multiply can be >> implemented by a shift): Actually, I tried this as a shift first...when that wasn't working, I switched to the multiply approach! Now I have a better idea of why it wasn't working... > I would hope the compiler for an 8-bit microcontroller would be smart > enough to turn either shifts or multiplys into byte copies. > > Interestingly C18 will sometimes turn a shift into a multiply. The PIC18 > is actually better at multiplication than it is at shifting since it has > a multiplier but not a barrel shifter. As a test, I looked at the list output of both options...and they are identical. Here's an example: 535 ;ws2812_lib.c: 81: redtemp =3D red * 0x100= 00; 536 000284 C03E F041 movff set_LED@red,??_set_LED 537 000288 6A42 clrf (??_set_LED+1)& (0+255),c 538 00028A 6A43 clrf (??_set_LED+2)& (0+255),c 539 00028C 6A44 clrf (??_set_LED+3)& (0+255),c 540 00028E C042 F044 movff ??_set_LED+1,??_set_LED+3 541 000292 C041 F043 movff ??_set_LED,??_set_LED+2 542 000296 6A42 clrf ??_set_LED+1,c 543 000298 6A41 clrf ??_set_LED,c 544 00029A C041 F04D movff ??_set_LED,set_LED@redtemp 545 00029E C042 F04E movff ??_set_LED+1,set_LED@redtem= p+1 546 0002A2 C043 F04F movff ??_set_LED+2,set_LED@redtem= p+2 547 0002A6 C044 F050 movff ??_set_LED+3,set_LED@redtem= p+3 Doing a << 16 produces the same code as above. > greentemp =3D (uint32_t)green << 16; > redtemp =3D (uint32_t)red << 8; > bluetemp =3D blue; Yup! that works! Thank you very much for the help guys! Josh --=20 A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. -Douglas Adams --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .