Use of PASM res statement
David Betz
Posts: 14,516
Will the following code work? I have a feeling that someone once told me that I had to put all of my "res" statements at the end of my PASM code. Should I change all of the "res 1" statements to "long 0"?
'' Modified for use with PropGCC by David Betz '' Derived from: '' File....... jm_ws2812.spin '' Purpose.... 800kHz driver for WS2812 LEDs '' Author..... Jon "JonnyMac" McPhalen '' Copyright (c) 2013 Jon McPhalen pub driver return @ws2812 dat org 0 ws2812 jmp #ws2812_cont txpin res 1 ' tx pin # ledcount res 1 ' # of rgb leds in chain resettix res 1 ' frame reset timing bit0hi res 1 ' bit0 high timing bit0lo res 1 ' bit0 low timing bit1hi res 1 ' bit1 high timing bit1lo res 1 ' bit1 low timing hubpntr res 1 ' pointer to rgb array ws2812_cont mov txmask, #1 ' create mask for tx shl txmask, txpin andn outa, txmask ' set to output low or dira, txmask
Comments
Dunno if I'd ever use it simply due to how unreadable / unmaintainable it could make the code if used for anything more complicated.
Having all RES at the end is the simplest to make it always work.
But if you know what you do, then you can use it for some tricks like in the code snippet you posted. Here the RES is used to give CogReg1 ..8 alternative names, to use it later as variables that overlay the Init code, which is only used once at startup of the cog.
( I think thats the case here, but without seeing the whole code I can't tell for sure).
Andy
Edit: Looking again at the code, this only would work if there is another ORG 1 before the Init code.
By the way, thanks JonnyMac for your elegant code!
BTW, and it's noted in the code, I got a great assist from TonyP12 with rearranging the RGB long to GRB.
Just last night a friend pointed out that Adafruit has a link to my WS2812 object in ObEx. As a community, we could probably do more to show them that the Arduino, while the most popular kid in school right now, isn't necessarily the smartest. With the popularity of WS2812 LED strips and modules, your project in C could well be an invitation for those struggling to get more performance out of their Arduinos.