Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC Interrupt - INTEDG

Status
Not open for further replies.

Hippogriff

Member
Hi,

I've never used interrupts on a PIC before, so I just started today with a 16F676 as I am thinking this could be useful for when I get further with my remote control investigations.

At the moment, I've got a switch hooked into pin RA2 and I've set the 16F676 up so that the INTCON INTE (External Interrupt Enable bit) is 1. Also, I set it so the OPTION_REG INTEDG (Interrupt Edge Select bit) is 1. When an interrupt occurs I then simply toggle the state of a LED and I clear INTCON INTF.

This works OK - but only on the rising edge - which is exactly what I've told it to do. My question is more about what I should be doing if I would like the interrupt to occur when the switch attached to RA2 changes state.

At the moment, in the very simple interrupt code, I'm actually toggling the setting of OPTION_REG INTEDG so that the interrupt is executed on the falling edge, then the rising edge, ad infinitum.

Code:
procedure ReceiveInterrupt is
  pragma interrupt
  LED = !LED
  INTCON_INTF = 0
  OPTION_REG_INTEDG = !OPTION_REG_INTEDG
end procedure

For some reason, this doesn't feel right to me and I'm wondering if I should be doing this another way, maybe using the interrupt-on-change facility - but (I'll admit) I'm not exactly sure about how to go setting that up - I've only just got this external interrupt on RA2 working. I'm not exactly sure why "external interrupt" is differentiated from other kinds of interrupts in the documentation, but - then - I'm just starting - maybe someone could help me understand that if you have the time?

Is this way of receiving an interrupt when the switch toggles state OK to work with?
 
Status
Not open for further replies.

Latest threads

Back
Top