Is it a correct way to deal with an interrupt?


Closed Thread
Results 1 to 4 of 4
  1. #1

    Question Is it a correct way to deal with an interrupt?

    Hi, I am trying to learn about interrupts and have a few 12C671 PICs with me. I don’t want to waste them and then learn so I request few expert opinions before I burn this code into my PIC.
    I am trying to create an interrupt in such a way that when GP2 is made high -> PIC should wake up from sleep and execute the code until GP2 is held high and when it goes low – it should go back to having sweet dreams until GP2 is made high again. Following is my code:
    Code:
    'fuses setup
      TRISIO = %011111    '// Gpio =5-bit switch inputs - Gpio.5=Output
      OPTION_REG = %11000000    '// INTERRUPT ON RISING EDGE OF GP2 + Internal pull ups off
      	ADCON0.0=0
    	ADCON1=7
      ON INTERRUPT GOTO encode
    goto rest
    
    Send:
    Send the variables
    Goto rest
    
    rest:
    	while GPIO.2=1
    	gosub encode
    	wend
    	INTCON = %10010000 ' global ints enabled, Ext int on GP2 enabled
     	@ SLEEP            ' put PIC to sleep
    
    encode:
    	INTCON=0
    	Prepare the variables with values
        	GOTO Send
    Is the above way a correct one?

    Also, I want to ask very briefly about what excatly peripheral interrupts are for or if you can put a link where I can read about them in detail. Thanks
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Why not learn on a flash PIC? Then when the code is correct....
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Question

    Thanks Dave..........but this question will still be there in my mind if it is a correct way or not. I know there are many ways to do one thing so I wanted to have an opinion about if the way I choose above is a reliable one. I have never written any code having interrupts myself before.
    Last edited by financecatalyst; - 15th November 2009 at 20:53.
    ___________________
    WHY things get boring when they work just fine?

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Whichever chip you choose, I would never use the

    ON INTERRUPT GOTO structure.

    This statement not only adds to your code size, it makes it run more slowly
    as well, because it has to check (very often) if any of the interrupt flag bits are set. The interrupt response time can also be longer than you expect, since it can only jump to the interrupt routine at the points where it checks for the flags.

    On the other hand, Darrel Taylor's Instant Interrupts uses REAL interrupts. Check out that thread. MUCH better than O-I-G, and easy to use as well.
    Charles Linquist

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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