We are trying to set up a button interrupt on port Ra.5 on the 16f688 chip to light a led, this is the first time that we have worked with the innterrupt command, any suggestions? Will post the program that we have so far if necessary.
We are trying to set up a button interrupt on port Ra.5 on the 16f688 chip to light a led, this is the first time that we have worked with the innterrupt command, any suggestions? Will post the program that we have so far if necessary.
Here is the code, If i will help at all.Code:Trisa = 32 Trisc = 0 ioca=%10000000 a Var porta c var portc t1 var word t1=200 start: on interrupt goto buttonpressed INTCON = %10000000 one: gosub left: goto one: buttonpressed: gosub All_on: goto buttonpressed: resume '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'SUBROUTINES left: a=4:c=36 pause t1 a=0: c=0 pause t1 return all_on: a=7:c=63 pause t1 return
Last edited by RHS_electronics; - 9th March 2009 at 18:06.
Got a few problems there ...
For Interrupt on change with RA5, you need to set bit 5 of the IOCA register. You have bit 7 set.Then the PortA change interrupt needs to be enabled (RAIE)...Code:ioca=%00100000In the interrupt handler (buttonpressed), you MUST read PORTA to end the mismatch condition, and clear the interrupt flag before exiting the handler. And it must exit the handler. You have a continuous loop in there, remove the goto.Code:INTCON = %10001000Keep in mind that you will get an interrupt on both the Press and Release of the button. You will eventually need to change the interrupt handler to determine which Edge occurred.Code:buttonpressed: gosub All_on: dummy = PORTA ; clear mismatch condition INTCON.0 = 0 ; reset interrupt flag resume
RA5 is also a main oscillator pin. I assume you are using the internal oscillator .. just checking.
You should turn off the Analog functions when using Digital signals.And disable the comparators.Code:ANSEL = 0Code:CMCON0 = 7
DT
What do you mean by this?dummy = PORTA
Also we are trying to make the button, when pressesd, toggle between two subroutines, Exe: one press is the first one, then when you press it again it will go to the next program.
ps: yes we are using the internal oscillator
You'll need to have a BYTE variableAt this point the variable isn't used for anything.Code:dummy VAR BYTE
But by simply reading PORTA, it resets the Latches used to detect the change on the Port.
Without clearing the "Mismatch" condition, there's no way to reset the interrupt flag.
So as soon as you RESUME from the interrupt handler, it would jump right back into the interrupt again.
<br>
DT
This is the code we have now and it still isn't working, the only thing it is doing is stopping the program where it is, What is wrong?Code:Trisa = 32 Trisc = 0 a Var porta:c var portc x var word:t1 var word dummy var byte x=0 t1=200 ANSEL = 0 ioca=%00100000 CMCON0 = 7 start: on interrupt goto buttonpressed INTCON = %10001000 one: gosub left goto one buttonpressed: gosub All_on dummy=porta ; clear mismatch condition INTCON.0 = 0 ; reset interrupt flag resume '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'SUBROUTINES left: a=4:c=36 pause t1 a=0: c=0 pause t1 return all_on: a=7:c=63 pause t1 return
Bookmarks