Shop OBEX P1 Docs P2 Docs Learn Events
How to set two leds ON in ASM — Parallax Forums

How to set two leds ON in ASM

peterzpeterz Posts: 59
edited 2007-01-07 19:19 in Propeller 1
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 ?
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-07 16:32
    The shift instructions need a "#" since they're using the source as an immediate value (shift count).
  • peterzpeterz Posts: 59
    edited 2007-01-07 16:57
    So, when I write it as 16 or 17, without #, do I mean 'address' instead of 'immediate value' ?
  • Jasper_MJasper_M Posts: 222
    edited 2007-01-07 17:15
    peterz said...
    So, when I write it as 16 or 17, without #, do I mean 'address' instead of 'immediate value' ?

    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.
  • peterzpeterz Posts: 59
    edited 2007-01-07 18:53
    Hmmm...
    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 !!!
  • Jasper_MJasper_M Posts: 222
    edited 2007-01-07 19:03
    peterz said...
    Hmmm...
    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
  • peterzpeterz Posts: 59
    edited 2007-01-07 19:13
    Thanks, it works when I place the variables after the code!
    Interesting behavior. I thought it·would not matter where·VARS were located.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-07 19:14
    Just as a suggestion for good programming style ...

    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:
       or outa,mask_led16_ON
       or dira,mask_led16_ON
       or outa,mask_led17_ON
       or dira,mask_led17_ON
    :here jmp #:here
    
    


    Note: ":here" is an example of a local label.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-07 19:19
    Or you define them like this:

    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
Sign In or Register to comment.