Shop OBEX P1 Docs P2 Docs Learn Events
Code Posting — Parallax Forums

Code Posting

edited 2012-10-08 15:41 in General Discussion
{{

  Operate 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

  • edited 2012-09-28 15:19
    The 392 ohm resistor is just what I had. I couldn't find any 160 ohm ones which is what I usually use to drive a switch circuit.

    This setup and code is guaranteed to work at my house on my propeller professional development board.
    {{
      Operate 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
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-06 15:01
    (Xandy) !

    . .

    Post Coding
    beeeeeep beep-beep
  • edited 2012-10-08 15:41
    [code]
    some code here
    
    [/code]
Sign In or Register to comment.