Connect with us


Discussion in '8bit Microcontrollers' started by Craig, Jan 23, 2005.

Scroll to continue with content
  1. Craig

    Craig Guest

    When programming in c(HiTech PICC Lite), is there any way to call functions
    that are used in the main part of the program, from the interrupt routine. I
    have tried to do this on many occasions to ensure my code is as modular as
    possible and avoid code repetition. I realise that on most occasions this is
    not desirable but speed all I am attempting to do with the interrupt is use
    a couple of functions already defined and used in the main finction, then
    either exit from the program or hold it in an infinite loop so it cannot do
    anything else.

    Calls of this type seem to work as long as the called function doesn\'t have
    any parameters, however, if it does I get an error message telling me that
    the function is called in two roots, _main and _btn(my interrupt routine).

    I would be grateful for any advice you could give.


  2. Well, in general, re-entrant code on the PIC is not really practical,
    due to the architecture of the chip, and the PICC compiler does not
    support it. RTFM, but I believe there's a way to tell the
    compiler/linker to go for it anyway and *you* must guarantee that it
    doesn't ever get called from two places at once.

    Perhaps duplicating the code (using a macro?) is the best solution for

    However, I question the necessity of doing this in the first place. If
    you're using the same code in both places you may be doing things in
    the interrupt routine that really should be done elsewhere.

    Best regards,
    Spehro Pefhany
  3. Dan Henry

    Dan Henry Guest

  4. Alexander

    Alexander Guest

    Het volgende bericht werd op ons ingehakt door Spehro Pefhany
    Disable interrupts at the beginning of the re-entrant code may do the trick.
    Although this way the re-entrant code may not be long and you MUST take into
    account that there might be some time lack with an intterupt generated
    during execution of the re-entrant code.
    Sometimes you must, I had the same problem.
    The best solution was a workaround since the real problem was only on one
    place I checked where it was called from eg interrupt and if so the needed
    file-registers (pointed access) where increased by the amound needed.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day