interrupt on a port


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2006
    Posts
    27

    Default interrupt on a port

    HI
    i use 16F877A
    how use interrupt on a port B (other that rb0) with 3 button.
    for interrupt on RB4 to RB7 i must use intcon=00001000?
    and intcon.0=0 to reset flag?

    when i test this code . it dont work!

    code:
    ' On Interrupt - Interrupts in BASIC
    ' Turn LED off on RA1 if Interrupt on PORTB.4
    '
    led var PORTA.1
    trisa=1
    LED=1 'just to see if port RA.1 is ok
    pause 1000 '

    OPTION_REG = $7f ' Enable PORTB pullups

    On Interrupt Goto myint ' Define interrupt handler
    INTCON =%00001000
    loop: High led ' Turn LED on
    Goto loop

    ' Interrupt handler
    Disable ' No interrupts past this point
    myint:
    INTCON.0 = 0 ' Clear interrupt flag
    low led ' If we get here, turn LED off
    Pause 2000 ' Wait .5 seconds
    resume ' Return to main program
    Enable

    with this code : led low and an action on rb4 nop
    sample prog to use a port (other that RB0) and how use choice of different button?
    please thank

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Nick,

    In the Interrupt handler, you need to read PORTB to "end the mismatch".
    Code:
    Temp = PORTB
    Otherwise, as soon as you RESUME, it will interrupt again.
    <br>
    DT

  3. #3
    Join Date
    May 2006
    Posts
    27


    Did you find this post helpful? Yes | No

    Smile interrupt on port RB.4 to RB.7

    HI
    THANKS for your help

    this is my final code
    it s ok and works

    '***************************************
    ' On Interrupt RB4 to RB7 - Interrupts in BASIC
    ' Turn LED1 off on RA1 if Interrupt on PORTB.4
    ' Turn LED2 off on RA2 if Interrupt on PORTB.5
    '***************************************
    OPTION_REG = %1000000 ' Enable PORTB pull-ups
    ADCON1=6 ' port A = digital
    TRISA=%00000000
    TRISB=%11111111
    PORTA=%11111111
    PORTB=%11111111

    On Interrupt Goto myint ' Define interrupt handler
    INTCON =%00001000

    loop:
    @nop
    Goto loop

    '***************************************
    'interrupt handler
    myint:
    Disable ' No interrupts past this point
    IF PORTB.4=0 THEN goto LEDRTN
    IF PORTB.5=0 THEN GOTO LED1RTN
    resume ' Return to main program

    LEDRTN: ' port B.4=0
    PORTA.1=0 ' turn LED1 off
    PAUSE 500 ' pause
    PORTA.1=1 ' turn LED1 on
    INTCON.0=0 ' Clear the RB port change flag bit
    resume ' Return to main program

    LED1RTN: ' port B.5=0
    PORTA.2=0 ' turn LED2 off
    PAUSE 4000 ' pause
    PORTA.2=1 ' turn LED2 on
    INTCON.0=0 ' Clear the RB port change flag bit
    resume ' Return to main program
    Enable

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. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  3. How to set TMRO & TMR3 as Counter?.
    By NatureTech in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 18th May 2007, 08:52
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  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