A Simple IOC Routine (Interrupt On Change)


+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2010
    Posts
    15

    Talking A Simple IOC Routine (Interrupt On Change)

    Hi,

    here is a simple Interrupt On Change program, that turns on a led on portC for pic16f684, it cost me a week to find this answer, I only hope that this help to solve problems easier for others...

    [code]'configuración

    ANSEL = 0 'I/O digitals
    OPTION_REG = 7 'Enable pullups
    IOCA.0 = 1 'Enable Interrupt on Change for RA0
    WPUA.0 = 1 'Enable pull up RA0
    TRISC = 0 'portC output
    TRISA = 7 'portA <2:0> input <5:3> output

    INTCON.0 = 0 'clear IOC flag
    INTCON.3 = 1 'Enable IOC interrupt
    INTCON.7 = 1 'Enagle GIE
    'variables
    I var byte 'missmatch variable for IOC
    inicio:
    if INTCON.0 = 1 THEN 'Change on portA ocurred?
    PORTC.5 = 1 'turn On led
    pause 500 'wait half second
    PORTC.5 = 0 'turn On led
    I = PORTA 'end missmatch
    INTCON.0 = 0 'clear IOC flag for next interrupt
    ELSE 'if no change is ocurred
    PORTC.5 = 0 'led continues off
    ENDIF '

    GOTO inicio 'loop[\code]

    PS. Sorry for my English. I can't make my code seccion work

    Regards,
    Luis Lugo
    Last edited by lugo.p; - 8th March 2010 at 16:28. Reason: Corrections

  2. #2
    Join Date
    May 2007
    Posts
    604

    Default

    Change the "[\code]" to a forward "[/code]".

    Code:
    'configuración
    
    ANSEL = 0 'I/O digitals
    OPTION_REG = 7 'Enable pullups
    IOCA.0 = 1 'Enable Interrupt on Change for RA0
    WPUA.0 = 1 'Enable pull up RA0
    TRISC = 0 'portC output
    TRISA = 7 'portA <2:0> input <5:3> output
    
    INTCON.0 = 0 'clear IOC flag
    INTCON.3 = 1 'Enable IOC interrupt
    INTCON.7 = 1 'Enagle GIE
    'variables
    I var byte 'missmatch variable for IOC
    inicio:
    if INTCON.0 = 1 THEN 'Change on portA ocurred?
    PORTC.5 = 1 'turn On led
    pause 500 'wait half second
    PORTC.5 = 0 'turn On led
    I = PORTA 'end missmatch
    INTCON.0 = 0 'clear IOC flag for next interrupt
    ELSE 'if no change is ocurred
    PORTC.5 = 0 'led continues off
    ENDIF '
    
    GOTO inicio 'loop

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,549

    Wink Program of the year award !!!

    Hi, Luis

    But ... Where's your interrupt stubb gone ???

    you should turn INTCON.7 to OFF ... as an interrupt occuring sends you to PAUSE asm routine library ... @ Prog mem location 4 !!!


    here you do not use the interrupt system but just flag the Change in I/Os ... and further test the flag.

    it would really be a miracle if your program shows you what you were looking for ...

    Alain
    Last edited by Acetronics2; - 8th March 2010 at 17:14.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Feb 2010
    Posts
    15

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Luis

    But ... Where's your interrupt stubb gone ???

    you should turn INTCON.7 to OFF ... as an interrupt occuring sends you to PAUSE asm routine library ... @ Prog mem location 4 !!!


    here you do not use the interrupt system but just flag the Change in I/Os ... and further test the flag.

    it would really be a miracle if your program shows you what you were looking for ...

    Alain
    The trick here is that i'm not using normal interrupt, all I do for this is, if a change occurs on RA0 turn on RC5 half second and then turn it off. the GIE turn off when a change on RA0 happen and GIE = 1 again when the missmatch ends.

    Only simulate and you'll see

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,549

    Default

    Hi, Luis

    I 've already made much worse than that ...

    Darrel can confirm !!!

    But your code goes straight to the pBp libraries @ location 4 , if you enable GIE ... ( I verified it with MPSIM !!! )

    Program pointer passes over ALL the PAUSE library ... luckily it's the only routine here...

    DANGER !!!

    Alain
    Last edited by Acetronics2; - 8th March 2010 at 18:16.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    May 2007
    Posts
    604

    Default

    Sitting in a loop while waiting for something to happen (in this case, polling the RAIF flag) isn't really what interrupts are about.

    To be really useful, it should actually interrupt whatever your program is currently doing when RA0 changes state. For example, let's say you have a routine the is blinking PORTC.5 at a slow rate of 500mS ON and 500mS OFF continuously in a loop. If the state of RA0 changes (eg. by using a switch or sensor), then you want the blink rate to go faster rate, say 100ms ON and 100ms OFF.

  7. #7
    Join Date
    Feb 2010
    Posts
    15

    Default

    Acetronics, i dunno understand, i'm newbie and my english is not excellent, but since i'm going to use IOC for a button and external INT over RA2 for measure a pulse, when i get there, i think i'll see the problem.

    Meanwhile if i'm going to use INT over RA2 to measure pulse width, i do need to send first a dummy pulse before the pulse to measure?

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. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  4. Simple Interrupt Program
    By eoasap in forum General
    Replies: 5
    Last Post: - 28th October 2005, 16:22
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Tags for this Thread

Posting Permissions

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