View previous topic :: View next topic |
Author |
Message |
nazoa Guest
|
Aborting function when RS232 data received |
Posted: Wed Aug 30, 2006 3:20 am |
|
|
Hello,
I have a number of complex functions which need to run as fast as possible. However, on receipt of an RS232 character, the function need to be aborted.
Now, what I am looking for are suggestions on the best way to do this without imposing any extra burden on the functions. Is it possible? I am using the PIC18F452 chip.
Thanks. |
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Wed Aug 30, 2006 4:10 am |
|
|
This is exactly what interrupts are invented for. |
|
|
nazoa Guest
|
|
Posted: Wed Aug 30, 2006 4:36 am |
|
|
Thanks Libor, yes, the problem is how to abort the current function. NOT how to service the interrupt. It would help if you can tell me how to write an interrupt service routine that will abort the current function. Thanks. |
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Wed Aug 30, 2006 4:53 am |
|
|
Every interrupt (if enabled) aborts the running code. Search for '#INT_RDA' on this forum or in the samples. You'll find many RS232 service routines implemented using interrupts. |
|
|
nazoa Guest
|
|
Posted: Wed Aug 30, 2006 5:42 am |
|
|
Hmm, I think I am not making myself too clear here..
I am not interested in how to service the interrupt. What I want is for the function to be ABORTED. You can think of it as wanting to put a jump to the end of the function when the interrupt occurs.
The problem with an interrupt is that when the interrupt is serviced, execution resumes at the point when the interrupt occurred. This is NOT what I need. |
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Wed Aug 30, 2006 5:55 am |
|
|
OK. now I got it. sorry.
Two ideas:
the conservative way: you set a flag in the interrupt service routine and periodically check it in your code, and act upon it.
the other one: you can modify the return program counter value stored in the return stack (it is software addressable in the new PICs), so the program execution after exiting the interrupt servicing will not continue where it left in the main code, but can jump to any place in the code. Need very careful programming. |
|
|
|