16f886 interrupt on portB problem


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Read your PORTB in the ISR

    Hi,

    If I remember correct then you need to read the portb to end the mismatch condition.
    This has to be done inside the ISR.


    Code:
    TEMP = PORTB   ' temp is some variable
    This should end your interrupt condition.
    Regards

    Sougata

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Also - set each IOCB bit instead of clearing them. 1= int enabled. 0= int disabled.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Oct 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Smile It working !! Thanks

    It seems to have been the wrong setting on IOCB register
    I cleared the bits and was not setting them.
    Here is a copy off the working program.
    I was compiled with PBP ASM


    '************************************************* ***************
    INCLUDE "MODEDEFS.BAS" '
    @ DEVICE PIC16F886
    @ DEVICE HS_OSC
    define LOADER_USED 1 ' using a loader, OK to leave in if a loader is not used
    define OSC 20 ' this example uses a 20MHz clock
    DEFINE HSER_RCSTA 90h 'rx enable
    DEFINE HSER_TXSTA 20h 'tx enable
    'DEFINE HSER_SPBRG 25h

    DEFINE HSER_BAUD 9600 ' set baud rate to 19200
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error
    TRISC = %10000000 ' PORTC.7 is the RX input, PORTC.6 is the TX output

    Old_Bits VAR BYTE
    New_Bits VAR BYTE
    Minute var byte ' Define minute variable
    Second var byte ' Define second variable
    Ticks var byte ' Define pieces of seconds variable
    DoUpdate var byte ' Define variable to indicate update
    intPortb var BYTE 'THE PORTB REGISTER STORE

    clear ' clear all RAM (sets all VAR declarations to zero)
    DoUpdate = 1 ' Force first display
    'OPTION_REG RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0
    OPTION_REG = %01010111
    ADCON1 = 7 ' 00000111
    CM1CON0 = 0 'DISABLE COMPARITORS
    CM2CON0 = 0 'DISABLE COMPARITORS
    ANSELH = %00000000 '0= DIGITAL 1= ANALOG PORTB -,-,ANS13,ANS12,ANS11,ANS10,ANS9,ANS8
    ANSEL = %00000000 '0= DIGITAL 1= ANALOG PORTB -,-,ANS13,ANS12,ANS11,ANS10,ANS9,ANS8
    'Addr Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
    '0Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF
    INTCON = %10001000 '%10001000 port b int on change and global interrupt enable
    'bit 7 = GIE: Global Interrupt Enable bit
    'bit 6 = PEIE: Peripheral Interrupt Enable bit
    'bit 5 = T0IE: Timer0 Overflow Interrupt Enable bit
    'bit 4 = INTE: INT External Interrupt Enable bit
    'bit 3 = RBIE: PORTB Change Interrupt Enable bit(1)
    'bit 2 = T0IF: Timer0 Overflow Interrupt Flag bit(2)
    'bit 1 = INTF: INT External Interrupt Flag bit
    'bit 0 = RBIF: PORTB Change Interrupt Flag bit
    IOCB.0=1 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (W3) <<<<fix
    IOCB.4=1 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (W1) <<<<fix
    IOCB.5=1 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E3) <<<<fix
    IOCB.6=1 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E2) <<<<fix
    IOCB.7=1 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E1) <<<<fix
    TRISB = %11111001 'PORT B INPUT OUTPUT SETTINGS 1=INPUT 0=OUTPUT
    CM1CON0 = 0
    CM2CON0 = 0
    WPUB = %111110001 '1=PULL UP O=PULL UP DISABLE PORTB WEAK PULL-UP
    LOW PORTC.4 'BATTERY CHARGE ON
    'Interrupt Source Enabled by Completion Status
    'RB4–RB7 state change RBIE = 1 RBIF =1
    B0 VAR BYTE
    B0 =PORTB
    intPortb = PORTB

    On Interrupt Goto TickInterrupt

    ' Main program loop
    MainLoop:
    B0=PORTB
    HSEROUT ["PORTB ",#B0,13,10]

    pause 500
    if DoUpdate then
    B0=PORTB
    HSEROUT ["PORTB INTERUPT ",#PORTB ,13,10]
    TOGGLE PORTC.0

    DoUpdate = 0
    endif
    Goto MainLoop

    ' Interrupt routine to handle each timer tick
    ' Disable interrupts during interrupt handler
    disable
    TickInterrupt:

    DoUpdate = 1 ' Set update
    b0 = PORTB ' temp is some variable
    ExitInterrupt:
    INTCON.2 = 0 ' TOIF Reset timer interrupt flag
    INTCON.0 = 0 ' RBIF Clear interrupt flag portb
    Resume
    '*************************************************

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 19:52
  2. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  3. Problem with Interrupt on PIC18F4620 PORTB
    By rookie in forum Off Topic
    Replies: 1
    Last Post: - 22nd March 2007, 01:34
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10

Members who have read this thread : 1

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