Shop OBEX P1 Docs P2 Docs Learn Events
Simple asm to turn on LED — Parallax Forums

Simple asm to turn on LED

RsadeikaRsadeika Posts: 3,837
edited 2008-06-16 15:22 in Propeller 1
Today I downloaded the ICC, just to see what the program was like. I looked at the example for turning on an LED, which looked like it was simple enough to understand, so I decide to give pasm a try, and code a simple LED program. Oh, BTW, I looked at the example that was in the manual, and I got stumped on the bitwise decode for the Pin declaration. So, my first attemp is a complete failure, the code below should turn the LED, by my understanding,·on, that is connected to pin 7, but it does not, what am I missing here?

CON
PUB Main
· cognew(@Toggle, 0)

DAT
····· org 0
Toggle
· mov dira, Pin·· 'Initialise the pin
· mov outa, 1··· 'Set the pin to high(turn the pin on)
·
Pin long 7·········'I guess this would be the pin declaration


Thanks
Ray

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-16 00:07
    Your "mov outa,1" moves the contents of location 1 to the OUTA register. You probably want to put "mov outa,#1".
  • kuronekokuroneko Posts: 3,623
    edited 2008-06-16 00:15
    If you want pin 7 then you should use something like:

    mov dira, Pin   'Initialise the pin
    mov outa, Pin   'Set the pin to high(turn the pin on)
      
    Pin long 1 << 7
    


    Declaring Pin as 7 would in fact set bits 0..2 and declare all three of them as outputs.
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-06-16 12:57
    The listing below is the simplest code that I can come up with to turn on an LED. I have some LEDs connected to pins 7,6,5,and 4; the problem that I have with the code below is, when I think the code should just turn on the LED on pin seven, it also turns on the LED on pin six. I can not understand why it is also turning on pin six, the code calls for it to be zero, or off.
    CON
    PUB Main
      cognew(@Toggle, 0)
    
    DAT
          org 0
    Toggle
      mov dira, #%1000000
      mov outa, #%1000000
    


    This code below also makes sense, but turns on pin six also:

    mov dira, Pin   'Initialise the pin
    mov outa, Pin   'Set the pin to high(turn the pin on)
      
    Pin long 1 << 7
    
    
  • kuronekokuroneko Posts: 3,623
    edited 2008-06-16 13:08
    Rsadeika said...
    I can not understand why it is also turning on pin six, the code calls for it to be zero, or off.
    What happens when you turn on pin 6, does the corresponding LED light up? Looks like mixed up wiring to me ...
  • hippyhippy Posts: 1,981
    edited 2008-06-16 13:34
    @ Rsadeika : Your first example ( mov outa, #%1000000 ) should turn on just P6 your second example ( Pin long 1 << 7 ) should turn on just P7, so if they are both turning on P6 and P7 it looks like you have a short between P6 and P7.
  • BaggersBaggers Posts: 3,019
    edited 2008-06-16 14:00
    You've also missed out quite an important part something to stop the cog going through random instructions, but keeping the cog alive, so as to not close the ports again for that cog [noparse]:)[/noparse]

    [noparse][[/noparse]code]
    CON
    PUB Main
    · cognew(@Toggle, 0)

    DAT
    ····· org 0
    Toggle
    · mov···· dira, Pin·· 'Initialise the pin
    · mov··· ·outa, Pin·· 'Set the pin to high(turn the pin on)

    backhere
    ··jmp··· ·#backhere
    ' you'll need something like this as·otherwise the cog will execute code after the mov outa,Pin
    ' don't know off hand without looking it up, what the 1<<7 would do, lol
    ' and not to mention if you add anything·after that,
    ' like·more data for other things and/or more code.
    ·
    Pin··· long··· 1 << 7
    [noparse][[/noparse]/code]


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • RsadeikaRsadeika Posts: 3,837
    edited 2008-06-16 14:02
    Thanks, you guys are good! As it turns out, it is two wires that were touching together. When I looked at it, it did not look like any of the wires were touching, which explains why pins five, and four were also turning on, when I just requested that pin five to turn on. I guess I have to be more carefull when I am wiring on the breadboard.

    My first lesson was quite good, I learned two different ways of using code to turn on an LED, I am sure that their are more ways. And I also learned about the hardware side, make sure you do not have any wires that could possibly touch, or are touching. Which also could explain why on some of my other breadboard projects, I had some weird stuff occuring.

    Now, that I have base of knowledge, I shall expand on this. Maybe some of my existing Spin code, in some of my other programs, can be tweaked by using some converting to pasm. I guess I will have to put ICC on the backburner while I explore pasm some more.

    ·
  • BaggersBaggers Posts: 3,019
    edited 2008-06-16 14:04
    glad you're having fun with it and learning [noparse];)[/noparse] keep it up, look forward to posts of your other projects [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • hippyhippy Posts: 1,981
    edited 2008-06-16 15:22
    Rsadeika said...
    My first lesson was quite good, I learned two different ways of using code to turn on an LED, I am sure that their are more ways.

    Without getting into convoluted code which is really only one of the following, I can only think of three ways ...

        mov  outa,#%1000_0000     ' or #1<<6 ( okay for P0 to P8 only )
    
        mov  outa,pin
        :
    pin long %1000_0000           ' or 1<<6 
    
        mov  tmp,#1
        shl  tmp,#6               ' pin number 0 to 31
        mov  outa,tmp
    
    
    
Sign In or Register to comment.