Menu

interupt

Help
2008-11-15
2013-05-30
  • Nobody/Anonymous

    how do i make a pin change in state immediatly cause a change in  what sub routine is running?
    16f685

     
    • kent_twt4

      kent_twt4 - 2008-11-16

      To understand what would work best for you try downloading the Pickit 1 user's guide from Microchip.  Also grab the lessons code there, which has the assembly or C code.  You could try the finite state machine, watchdog timer, or interrupt examples.

      The state machine example is not exactly immediate, but easiest to implement, it would look something like:

      #define button PortA.0
      dir button in
      WPUA0 = 1 ;enable weak pullup
      ...
      ...
      counter = 0
      WatchButton:
      If button Off Then ;check for button press
      wait 10 ms ;debounce button
      If button On Then goto WatchButton ;glitch so start over
      counter += 1 ;this is an incrementing example, could be a variable, or?
      If counter = 3 Then counter = 1 ;check for last case+1 and start over
      End if

      Select Case counter
      Case 1
      (Do something)
      Case 2
      (Do something)
      End Select
      wait X ms ;determine necessary wait period
      goto WatchButton

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.