Shop OBEX P1 Docs P2 Docs Learn Events
Input and output in PASM — Parallax Forums

Input and output in PASM

edited 2012-09-28 17:21 in Propeller 1
I've been trying to learn assembly and was trying to figure out how to set the output of a pin based on the input of another pin. The output part came fairly easily but it took a while to figure out the input part. The following is the code I finally put together.

This code and setup is guaranteed to work at my house on my PPDB.
{{
  Operate an LED based on switch position
  Demonstrates input and output in assembly
          392
  +3.3─────┳─────┐
              │    ┫SW1  
         100k │     │
  pin 2────┘     

               470
  pin 3────────┐
                    │
                    
}}
              
con
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
        
var

pub Main

  'Launch assembly code into cog 1
  coginit(1, @switch, 0)
  

dat
          org 0

switch    mov     mask1, #1
          shl     mask1, #2
          andn    outa, mask1    'make pin 2 an input
          mov     mask2, #1
          shl     mask2, #3
          or      dira, mask2    'make pin 3 an output
          or      outa, mask2

:start    test    mask1, ina  wc 'set carry flag if bit set
    if_c  andn    outa, mask2    'button up - LED off
    if_nc or      outa, mask2    'button down - LED on
          jmp     #:start

mask1      res 1
mask2      res 1

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-09-28 17:21
    Sandy,

    Check out the muxc and muxnc instructions. They can be used to set/clear bits of outa based the state of the carry flag with one instruction instead of two conditional instructions.

    -Phil
Sign In or Register to comment.