Interrupt on Change with 16F886


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230

    Default Interrupt on Change with 16F886

    Hi. I got a problem with DT-INTS14 on a 16F886 chip.

    I can't seem to make it work. It is a simple test code on port b change, to trigger interrupts with DT-INTS14.

    Code:
    #config
    Line1 = _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF
    Line2 = _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
        __CONFIG _CONFIG1, Line1 & Line2
        __CONFIG _CONFIG2, _WRT_HALF & _BOR40V
    #endconfig
    
    OSCCON = %01110001 '8MHz Clock
    
    DEFINE OSC 8
    
    
    DEFINE LCD_DREG PORTC
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 3
    DEFINE LCD_EREG PORTA
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 100
    
    OPTION_REG.0=1		'PSA0 PRESCALER SELECT 1:1 TO 1:256
    OPTION_REG.1=1		'PSA1
    OPTION_REG.2=1		'PSA2
    OPTION_REG.3=1		'PRESCALER TO: 1->WDT, 0->TMR0
    OPTION_REG.4=0		'T0SE SOURCE EDGE 1->H TO L, 0->L TO H
    OPTION_REG.5=0		'T0CS 1->FROM RA4, 0->FROM INT. CLOCK
    OPTION_REG.6=0		'INT EDGE SELECT 0->H TO L, 1->L TO H
    OPTION_REG.7=0		'PULL UP 1->DISABLE, 0->ENABLE
    
    adcon0=%11000001   
    adcon1=%10000000
    ansel=$01
    anselh=$00
    
    DEFINE ADC_BITS 10          ; Set-up ADC for fast 10-bit results
    DEFINE ADC_SAMPLEUS 5
    
    ccp1con=0
    
    PORTA=%00000001
    PORTB=%01110000			'RB0-RB3 row outputs to 3x4 keyboard
    						'RB4-RB6 col inputs from 3x4 keyboard
    
    PORTC=0'%10000001
    
    TRISC=0'$80:'TRISD=0:TRISE=0
    
    TRISA = %00010001
    
    TRISB = %01110000			'PB0: row 1
    						'PB1: row 2
    						'PB2: row 3
    						'PB3: row 4
    						'PB4: column 1
    						'PB5: column 2
    						'PB6: column 3
    						'PB7: No Con.
    
    IOCB = %01110000			'interupt on change enable on RB4-RB6
    INTCON = %10001000		'Enable global and Int. on change
    RBIF var INTCON.0			'alias to RBIF bit of INTCON
    wsave    var byte $70 system
    wsave1   var byte $a0 system
    wsave2   var byte $120 system
    wsave3   var byte $1a0 system
    
    adc_t     var word
    
    temp    var word
    i       var byte
    a       var byte
    pressed var byte
    
    
    clear
    
    Lcdout $fe,1,"IOC test"
    
    INCLUDE "D:\Dropbox\Projects\PICDEM2\Interrupt\DT_INTS-14.bas"
    INCLUDE "D:\Dropbox\Projects\PICDEM2\Interrupt\ReEnterPBP.bas"
    
    
    '-------------   INTERRUPTS SETUP   ---------------------
    ASM
    INT_LIST  macro;    IntSource,  Label,      Type,  ResetFlag?
        INT_Handler     RBC_INT,    _IOC2,      PBP,    yes
        endm
        INT_CREATE            ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE  RBC_INT      ; Enable Port B on change
    
    '-------------   INTERRUPTS SETUP   ---------------------
    
    portb=$7F
    goto main
    
    '***********************************************************************
    '*
    '*             Interrupt on Change
    '*
    '***********************************************************************
    
    IOC2:
        pressed=1
        lcdout $fe,$80,"interrupt"
        i=portb
        RBIF=0
    @ INT_RETURN
    
    
    main:
    
    while 1
    if pressed then
        lcdout $fe,$c0,#i,"    "
        pressed=0
        portb=$0f
    endif
    wend
    
    End
    It must be something stupid but do not see it...
    Thanks,

    Ioannis

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: Interrupt on Change with 16F886

    what makes the pins change state ?
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: Interrupt on Change with 16F886

    You are right. I forgot to note that col and rows are connected to a keyboard matrix 3x4.

    Ioannis

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,087


    Did you find this post helpful? Yes | No

    Default Re: Interrupt on Change with 16F886

    You are right. I forgot to note that col and rows are connected to a keyboard matrix 3x4.
    but how is it wired , what will make the columns change state the rows are set to all 1's the initial col port pins are set to all 1's
    where can a o come from ?

    usually a zero or a one is walked down a row or col
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,230


    Did you find this post helpful? Yes | No

    Default Re: Interrupt on Change with 16F886

    Well, I have to work the project on the morning and not late at night...

    I missed that portb=0 obviously and just focused on the Interrupt itself and the settings...

    Ioannis

Similar Threads

  1. RB Change Interrupt understanding
    By PickyBiker in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th April 2010, 14:48
  2. Interrupt-on-Change-pin!
    By PICante in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th February 2009, 20:22
  3. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  4. 16f886 interrupt on portB problem
    By antonjan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th October 2008, 20:06
  5. Interrupt On Change - question
    By kevj in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th July 2008, 23:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts