Alek Modi

Alek Modi
Follow You Heart!

Thursday, January 12, 2012

Embedded System - Button Flash in Spin Programming




Copy from here


CON

  _clkmode      = xtal1 + pll16x
  _xinfreq      = 5_000_000

  LEDs_START    = 0
  LEDs_END      = 15
  PUSHBUTTON    = 21

PUB ButtonBlinkSpeed | state, button

  dira[LEDs_START..LEDs_END]~~

  state := 0

  repeat

    button := ina[PUSHBUTTON]

    if state == 0
      waitcnt(clkfreq/4 + cnt) ' 1/4 second
     !outa[LEDs_START..LEDs_END]
     if button == 1
        state := 1
    else
      if state == 1
      waitcnt(clkfreq/30 + cnt) ' 1/20 second
     !outa[LEDs_START..LEDs_END]
     if button == 0
        state := 0

     

No comments:

Post a Comment