Using interrupts?

242 views
Skip to first unread message

John in WI

unread,
Mar 5, 2012, 7:26:30 AM3/5/12
to jal...@googlegroups.com
Hi,
I've been searching for a good explanation of how the JAL interrupts work. Every explanation I have found has left me more confused than when I started. I have looked at everything my internet searches bring up & the user manuals.

My goal is to have a switch that will stop anything that is currently occurring. For instance, an LED is blinking. I push the button(at any time) and it will stop.
I would also like to use interrupts to read a simple wheel encoder.

A beginner lever example of using interrupts would be very helpful to me.

Thanks very much! this group is great.

Sunish Issac

unread,
Mar 5, 2012, 8:16:58 AM3/5/12
to jal...@googlegroups.com
The following program blinks an LED and stops when an RB0/INT interrupt occurs.

This can be simulated by a push to on switch connected RB0 to Vcc and 10K resistor from RB0 to ground.


-- ------------------------------------------------------
-- Title: Blink-a-led with stop on INT demo
--
-- Author: Sunish Issac, Copyright (c) 2008..2012, all rights reserved.
--
-- Adapted-by:
--
--
-- Compiler: 2.4o
--
-- This file is part of jallib  (http://jallib.googlecode.com)
-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php)
--
-- Description:
-- This program blinks an led on pin a0 and stops the blink on a high pulse on interrupt
-- pin 6 with is RB0/INT on 16f88
--
include 16f88                    -- target PICmicro
--
pragma target clock 8_000_000     -- oscillator frequency
-- configuration memory settings (fuses)
pragma target OSC    INTOSC_NOCLKOUT -- internal osc
pragma target WDT      disabled     -- no watchdog
pragma target DEBUG    disabled     -- no debugging
pragma target LVP      disabled     -- no Low Voltage Programming
pragma target MCLR     Internal     -- reset internal

OSCCON_IRCF = 0b111                -- use 8 MHz internal oscillator

enable_digital_io()                -- make all pins digital I/O
--
--
alias   led      is pin_A0
pin_A0_direction =  output
--
var bit stopblink = false

procedure int_on_change_isr() is
   pragma interrupt
if  INTCON_INTF then
 stopblink = true     ; can be true only in isr
 INTCON_INTF = false
end if

end procedure


INTCON_GIE  = TRUE        -- Enables all unmasked interrupts
INTCON_INTE = TRUE        -- enable INT0 PIN for interrupts
OPTION_REG_INTEDG = 1     -- rising edge

forever loop
  if ! stopblink then ;make led on only while stopblink bit is false
     led = on
  end if
   _usec_delay(250_000)
   led = off
   _usec_delay(250_000)

end loop

Sunish


--
You received this message because you are subscribed to the Google Groups "jallib" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jallib/-/n4eE86_dF6oJ.
To post to this group, send email to jal...@googlegroups.com.
To unsubscribe from this group, send email to jallib+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jallib?hl=en.

mattschinkel

unread,
Mar 5, 2012, 11:02:40 AM3/5/12
to jallib
There is a interrupt on change library (supports up to 8 interrupt on
change pins), and there are already some samples:

18f4620_interrupt_on_change.jal
16f1827_interrupt_on_change.jal

Matt.

Sunish Issac

unread,
Mar 5, 2012, 11:18:00 AM3/5/12
to jal...@googlegroups.com
Looked like he wanted a small simple example of interrupts.

Sunish

John in WI

unread,
Mar 5, 2012, 7:38:43 PM3/5/12
to jal...@googlegroups.com
Sunish & Matt,
Thanks for the replies.... this will get me started. I was unaware of the interrupt on change library and it might offer me a simple solution.
Thanks again. Having lot of fun with JAL!
-John

> > For more options, visit this group at
> >http://groups.google.com/group/jallib?hl=en.

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To post to this group, send email to jal...@googlegroups.com.
To unsubscribe from this group, send email to jallib+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages