16f886 interrupt on portB problem


Results 1 to 6 of 6

Threaded View

  1. #2
    Join Date
    Oct 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Post Here is my code

    '******************************
    'Portb 4-7 as inputs for interrupt
    'using hserout to do debug
    'using portc for output to see if there is anything happening
    'I can read the port and send the values to hserout and works ok
    'But interrupt don't work ??
    '******************************
    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_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
    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 Value on POR, BOR Page
    '0Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF(1) 0000 000x 31,217
    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=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (W3)
    IOCB.4=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (W1)
    IOCB.5=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E3)
    IOCB.6=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E2)
    IOCB.7=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E1)
    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
    TOGGLE PORTC.0

    ExitInterrupt:
    INTCON.2 = 0 ' TOIF Reset timer interrupt flag
    INTCON.0 = 0 ' RBIF Clear interrupt flag portb
    Resume
    Last edited by antonjan; - 8th October 2008 at 12:01. Reason: added comment

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