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
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