How to set two leds ON in ASM
peterz
Posts: 59
I am trying to do something really simple·in Propeller ASM: set to ON two leds in the demo board. Leds P16 and P17.
Here is my code. It does not work at all. I mean, the leds stay OFF :-(
···············mov···· mask_led16_ON, #1
······················· shl···· mask_led16_ON, 16
······················· or····· dira,mask_led16_ON
·······················
······················· mov···· mask_led17_ON, #1
······················· shl···· mask_led17_ON, 17
······················· or····· dira,mask_led17_ON
······················· or····· outa,mask_led16_ON
······················· or····· outa,mask_led17_ON
What is wrong ?
·
Here is my code. It does not work at all. I mean, the leds stay OFF :-(
···············mov···· mask_led16_ON, #1
······················· shl···· mask_led16_ON, 16
······················· or····· dira,mask_led16_ON
·······················
······················· mov···· mask_led17_ON, #1
······················· shl···· mask_led17_ON, 17
······················· or····· dira,mask_led17_ON
······················· or····· outa,mask_led16_ON
······················· or····· outa,mask_led17_ON
What is wrong ?
·
Comments
Yes. It reads the contents of the cog register (long) at cog address 16 or 17 and shifts by the number in that register.
Also, I suggest writing the LED masks in code directly. You probably have there something like "mask_led16_on long 0". You can give it initially a value other than 0, like "mask_led_16_on long 1<<16". This way you don't need any movs or shls. You can or the registers directly with it.
now I do the following:
mask_led16_ON LONG 1 << 16
mask_led17_ON LONG 1 << 17
or dira,mask_led16_ON
or dira,mask_led17_ON
or outa,mask_led16_ON
or outa,mask_led17_ON
But I get all leds ON, except leds 16 and 17 !!!
The masks should go after the code. The assembly will get executed in the order you write it - it will not automatically skip the data. Besides that I don't see anything wrong with the code.
Have you tried your old code with shl mask_led16_ON, #16 and so on? With the #s. Does it work? and are you sure that there is no other code in your assembly code that might alter the values of mask_led16_ON and mask_led_17_ON? And maybe you should put an eternal loop after your code, so that when it stops executing, it won't begin executing the data. eg.:
or dira,mask_led16_ON
or dira,mask_led17_ON
or outa,mask_led16_ON
or outa,mask_led17_ON
end_loop jmp #end_loop
mask_led16_ON LONG 1 << 16
mask_led17_ON LONG 1 << 17
Interesting behavior. I thought it·would not matter where·VARS were located.
When you set the direction registers to make a pin an output, set the initial output register state before you change the direction register. This avoids a brief "glitch" on the output pin if the original output register bit happened to be something other than what you plan to set it to. In other words, do:
Note: ":here" is an example of a local label.
long mask_led16_on |< 16
The |<16 sets bit 16 high, this is done on compilation.
One other thing about cog variables, any that are just defined an not initialized, e.g:
somevariable res 1
Have to come right at the end after those that are initialized.
Graham