Shop OBEX P1 Docs P2 Docs Learn Events
Make a LED light up when switch is pushed - assembly language — Parallax Forums

Make a LED light up when switch is pushed - assembly language

WossnameWossname Posts: 174
edited 2011-07-10 06:30 in Propeller 1
I'm starting out learning the basics of Propeller Assembly and I'm having some difficulty with testing a pin's input state.

I'm trying to make an LED (pin "P1") light up when I connect P0 to 3.3v and then go off again when P0 is connected to GND.

My code below seems to ignore the high/low state of P0 and simply turns the LED on anyway regardless.

Clearly I'm doing something wrong but I can't seem to figure it out.
{{ AssemblyToggle.spin }} 
 
CON 
  _clkmode = RCFAST  
 
PUB Main 
 
  cognew(@Toggle, 0)
 
   
DAT 
 
                   org     0                
Toggle             mov     dira, #3           
                   mov     Time, cnt       
                   add     Time, #15
                          
:loop              waitcnt Time, Delay        
                   xor outa, #1
                   
                   test 1, ina wz            
            if_z   jmp #:off                  

                   or      outa, #2           
                   jmp     #:loop     
:off               andn    outa, #2
                   jmp     #:loop
         
 
Delay   long      1_000_000
Time              res  1                 



     

I have verified that the loop works by having a separate LED flashing all the time, so I think I'm doing the test wrong in some way.

Comments

  • WossnameWossname Posts: 174
    edited 2011-07-10 01:35
    Sorry, I just figured it out.

    It was the literal 1 in the test operation.

    I changed that to be a defined constant ("Switch") and now it works fine.

    {{ AssemblyToggle.spin }} 
     
    CON 
      _clkmode = RCFAST  
     
    PUB Main 
     
      cognew(@Toggle, 0)
     
       
    DAT 
     
                       org     0                
    Toggle             mov     dira, #3           
                       mov     Time, cnt       
                       add     Time, #15
                              
    :loop              waitcnt Time, Delay        
                       xor outa, #1
                       
                       test Switch, ina wz            
                if_z   jmp #:off                  
    
                       or      outa, #2           
                       jmp     #:loop     
    :off               andn    outa, #2
                       jmp     #:loop
             
     
    Delay   long      1_000_000
    Switch  long      |< 2          
    Time              res  1                 
    
    
    
    

    Ain't it typical? I spend hours trying to figure this out and within 2 minutes of posting on a forum as a last resort I find the answer myself :D D'oh!
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-07-10 06:30
    Hi Wossname,
    Ain't it typical? I spend hours trying to figure this out and within 2 minutes of posting on a forum as a last resort I find the answer myself :lol: D'oh!

    So the most interesting thing is what are you doing DIFFERENT when you write a posting?
    I guess if you find out what it is you can do it much earlier and even without writing a posting

    best regards

    Stefan
Sign In or Register to comment.