How to use an Interrupt to drive a menu on 16f88


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    I'm still learning myself but i hope this works for your need or is a good pointer. This i have test and works on my development board. Each time you push the switch on the Interupt pin, the LEDs on PORTB light in sequence as you push the switch.

    Code:
    ' I/O definition
    '
    TRISB = %10000001   ' Set PORTB (0)INPUT (1-5)OUTPUTS
    
    ' Variable Definition
    '
    Switch              VAR PORTB.0
    PushHowManyTimes    VAR Byte
    
    ' register and interrupt definition
    '
    CMCON = 7          ' Disable analog comparator on PORTA... not needed as now
    OPTION_REG=0       ' enable pull-up resistor on PORTb
                       ' Interrupt on falling edge of RB0
    INTCON = %10010000 ' Enable RB0 interrupt
    
    On Interrupt Goto ProcedureSwitcher
    
    ' Variable initialisation
    '
    PORTB=0             ' Reset all outputs on PORTB
    PushHowManyTimes=0
    
    'Main Procedure
    '
    MainProcedure:
          Select Case PushHowManyTimes
                 case 1
                      Gosub Routine_1 
                 Case 2
                      Gosub Routine_2
                 Case 3
                      Gosub Routine_3
                 Case 4
                      Gosub Routine_4
                 Case 5
                      Gosub Routine_5
                 End Select
    Goto Mainprocedure
    
    Routine_1:
        High 1
    Return
    
    Routine_2:
        High 2
    Return
    
    Routine_3:
        High 3
    Return
    
    Routine_4:
        High 4
    Return
    
    Routine_5:
        High 5
    Return
    
    ' Interrupt handler stuff here
    '
    Disable                                     ' Disable interrupts in handler
    ProcedureSwitcher:
        PushHowManytimes=PushHowManytimes+1     ' Changing task
        If PushHowManytimes=6 Then PushHowManytimes=1
    Here:
        While SWITCH = 0                        ' waiting until
        wend                                    ' push-button is release
        pause 100                               ' debounce time
        If switch=0 then here
        INTCON.1=0                              ' reset RB0 interrupt flag
    Resume                                      ' Return to main program
    
    Enable                                      ' Enable interrupts after
                                                ' handler
    As i say, still learning myself, but willing to help where i can !!

    Regards,

    Steve

  2. #2
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Thumbs up

    This is EXACTLY what I was looking for.... I just need to know if I can use RB4 instead of RB0.. and where to find the % mapping for that!!!

    Tom

  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Tom,

    As far as i'm aware (without looking at the Data Sheet for your PIC), this PIC has only one inturrupt line, RB0. RB4 is used for MCLR which is a RESET line.

    To be sure go to Microchips WEB site and get the latest Datasheet.

    Why don't you want to use RB0?

    Hope this helps,

    Steve

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you probably have Interrupt on PORTB change just check the PORTB.4 status in the interrput handler and you should be in business.

    Just be careful when you program your PIC.. disable MCLR to make it RB4
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Default

    Ahhh! OK! I thought interrupts were things you could assign to any pin, that is all. I was looking to closely at this to notice that RB0 had an assigned function 'INT'..

    I have a proto board made up that runs rb4 and rb5 off to a post for easily attaching pins to - the reason I wanted to use RB4.. I can tie off to RB0 but it is a little soldering now, that's all. Btw, RB0 is pin #6 on the F88. Pin 4 is MCLR.

    One other thing - 'enable pull up resistor' - do I need to tie a 1K ohm resistor from VDD to the pin also, or is this a software switch?

    Tom

  6. #6
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Ah, now i have learnt something !!

    Steve, so in the example code i have posted, what part needs to be changed to reflect the different PORT for the Inturrupt.

    Cheers,

    Steve

  7. #7
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Question

    So.... Is there some way to listen for interrups on RB4? Or is the chip designed to have interrupts come in vai RB0?

    Thanks,
    Tom

Similar Threads

  1. 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
  2. 16f88 interrupt
    By tur_bot in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 2nd April 2008, 11:35
  3. 16F88 Interrupt
    By sskeet in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th January 2006, 15:51
  4. Interrupt Menu System Example and Help Needed
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st April 2005, 17:05
  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