Interruption


Results 1 to 15 of 15

Thread: Interruption

Threaded View

  1. #12
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I'll give it a shot with a simple ON INTERRUPT version.
    Code:
      x var BYTE
      Switch VAR BIT
      
      TRISA = $FF
      TRISC = 0
    
      ANSEL = 0            ' A/D disabled (all digital)
      ANSELH = 0
      IOCA.3 = 1           ' int-on-change enabled for RA3
      INTCON = %10001000   ' enable global & int-on-change interrupts
    
      Switch = 1
    
      ON INTERRUPT GOTO MyISR
      
    mainloop:
      x = 1
      
    loops:
      PORTC = x
      pause 500
      if switch = 1 then
         if x == 8 then 
            goto mainloop
         else
            x = x << 1
            goto loops
         endif
      else
        if x == 1 then
           x = 8
           goto loops
        else
           x = x >> 1
          goto loops
        endif
      endif
      GOTO mainloop ' just in case
    
      DISABLE
    MyISR:
      WHILE PORTA.3=0  ' wait for button release (so we can clear the int flag & be
      WEND             ' sure it interrupts on a high-to-low transition)
    
      Switch = ~Switch ' toggle Switch
      INTCON.0 = 0     ' clear interrupt flag bit
      RESUME
      
      END
    There must be ten gozillion ways to do something like this, even without an interrupt, but
    it's still handy to at least learn about interrupts.

    Note that you could also do something similar by just monitoring the interrupt flag-bit with
    global interrupts disabled. You just need to get a tad more creative...;o}

    Tap & release the button as fast as you can to see how quickly it reacts.
    Last edited by Bruce; - 31st December 2009 at 01:00. Reason: Tap & release fast
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts