Shop OBEX P1 Docs P2 Docs Learn Events
Assembly pushbutton? — Parallax Forums

Assembly pushbutton?

electric550electric550 Posts: 122
edited 2009-04-10 01:17 in Propeller 1
Hello can somebody post some assembly code to mirror a pushbutton to an LED(Pushbutton positive when pressed)? Or even better seven pushbuttons to seven leds and record the lengths of the button presses to variables? I was thinking maybe using the counters or something but I am just starting in parallax assembly and really need to learn how to use the IO more efficiently. Is there a way to address single pins in assembly? I am surprised that all I have found for pin IO requires bit masking the entire port. I have been using assembly for phillips and si labs chips, (in which case I know how to do this), but it seems complicated to me right now on the propeller. Anyways thanks for your help.

Comments

  • TreeLabTreeLab Posts: 138
    edited 2009-04-09 15:36
    I would recommend that you first code it up in spin, which shouldn't take more than 1/2 hour. Then if you need the speed advantage, redo it in PASM (or C). My guess is that spin will be more than fast enough for you. Get the logic right, then move it to pasm.

    You should also consider the needs of software/hardware debouncing of the signal. Usually this introduces enough of a delay that the timing becomes spin compatible anyway. Search the forum, there have been some threads recently on this.

    Cheers!
    Paul Rowntree
  • TJHJTJHJ Posts: 243
    edited 2009-04-09 16:27
    Short summation this is what you will need.
    Asm has no individual bit adressing, so you must use masks.
    To set a pin use
    or REGISTER, Mask
    To clear a pin use

    andn REGISTER, Mask

    EDIT : Hey it works. Here is the full version
    Con
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    InputPinNum = 0
    LedPinNumber = 1
    Var
    Long AsmVar
     
     
    Pub Run
    Cognew(@Start, @AsmVar)
    repeat 'Repeat forever
    Dat
    org
     
    Start
      andn DIRA, InputMask ' Make sure InputPin is an input
      Or   DIRA, LedPinMask   ' Set led to output
      andn OUTA, LedPinMask   ' Make output Low
     
     
    Main
      mov  State, INA     'Get the current pin state set
      shr  State, inputPin  wc ' Move it to the right to place in D[noparse][[/noparse]0] and write in C flag field. 
     
     if_c or OUTA, LedPinMask ' If input == 1 then c flag was set so make ledpin high
    if_nc andn OUTA, LedPinMask' Turn off the pin if input == 0
          jmp #main             'Jump back and do it all over again
     
     
    InputPin long InputPinNum 
    InputMask Long  |< InputPinNum
    LedPinMask Long  |< LedPinNumber
     
     
    state res 1 'A long for state of input
    
    

    This should get you·started on the right track.

    TJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I owe everyone here a bunch, So thanks again for answering my dumb questions.
    Projects. RG500 ECU system. PropCopter. Prop CanSat. Prop Paste Gun.
    Suzuki RG500 in a RGV 250 frame.
    Bimota V-Due (Running on the fuel injection system)
    Aprilia RS250

    Post Edited (TJHJ) : 4/9/2009 4:36:16 PM GMT
  • electric550electric550 Posts: 122
    edited 2009-04-10 01:17
    This assembly is much more roundabout than the assembly I am used to. Thanks for the help.
Sign In or Register to comment.