Help with interupts


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    39

    Default Help with interupts

    I am just starting to mess with interupts. Just to get a feel for how they work, I have the following code.

    Code:
    LED   VAR PORTD.0
    PB   VAR PORTB.0
    TONE  VAR PORTC.3
    CTONESET VAR BIT
    loop1  Var BYTE
    TRISD = %00000000
    TRISB = %00000001
    INTCON = %10010000
    
    DEFINE OSC 10
    ON INTERRUPT Goto MyInt
    INTCON = $90
    mainloop:
     if PB = 1 then
      IF CTONESET=1 then
       FOR loop1 = 0 to 500
        pause 1
       Next loop1
       gosub CTone
       LED = 0
       
       For loop1 = 0 to 1000
       pause 1
       next loop1
      endif
     endif
     goto mainloop
    
    CTONE:
     Sound Tone,[88,7,91,7,99,7]
     CToneSet=0
     return 
    disable
    Myint:
      led = 1
      CToneSet = 1
      INTCON.1=0
      resume
    
    end
    What I expected to happen was when I push the button on RB0, the led would light. when I let it go I wanted it to play a tone and then turn off the led. What I get is I push the button, and the LED is off. I release the button, the LED lights, the tone plays, and the LED turns off. What am I doing wrong. I know it is something simple.

    Thanks!

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


    Did you find this post helpful? Yes | No

    Default Re: Help with interupts

    Not knowing what chip you are using... Look for "Interrupt on rising edge", it might be in INTCON2 .
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Aug 2008
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: Help with interupts

    It is a PIC18f8722

  4. #4
    Join Date
    Aug 2008
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: Help with interupts

    OK INTCON2 fixed the problem. Thanks.

    NowI think really need to impliment an interupt on a timer. I need to do several things at ones.

    1) Check condition on a multiple pins(Buttons) and do something on other pins(LED) based on what the button status is.
    2) Keep a count of how long since an action occured. (I.E. I wnat to run a sub routine every X Minutes

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


    Did you find this post helpful? Yes | No

    Default Re: Help with interupts

    ON INTERRUPT works fine if you do not care if the event is not acted upon instantly. ON INTERRUPT is pretty easy to use.

    If a interrupt is time sensitive you will want to use ASM interrupts, there is an example in the manual, but ASM interrupts can be tricky.

    The best of both, easy and fast are brought together here.
    http://darreltaylor.com/DT_INTS-18/home.html

    You will still need to have your data sheet open...
    Dave
    Always wear safety glasses while programming.

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