[RESOLVED] void pointer to interrupt function-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] void pointer to interrupt function

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    265

    Resolved [RESOLVED] void pointer to interrupt function

    Hi All

    I am working with Hi-Tech's HC51-Lite compiler...its a nightmare.

    I am trying to assign an ISR to run on a certain interrupt vector.
    The Hi-Tech manual recommends a couple techniques only one of which works in my version: using inline asm code. The asm code means I need obtain a pointer to the ISR so I can place this in the ACC and thus reference it in the asm section.
    My current C code to do this is:
    Code:
    // ISR name= interrupt void ext1isr (void)
    	void (*pisr)(void);
    	pisr = &ext1isr;  // Line 23
    	ACC = ((int*)pisr);  // Line 24
    But the compiler gives me errors:

    Error : 23 undefined identifier "ext1isr"
    Warning : 23 illegal conversion between pointer types
    Warning : 24 illegal conversion of pointer to integer

    Frankly void pointers and pointers to functions are outside my level of knowledge so any help much appreciated.
    Thanks

    EDIT: just tried: interrupt voide (*pisr) (void); but no change
    Last edited by wolf99; Jan 19th, 2012 at 05:23 AM.
    Thanks

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: void pointer to interrupt function

    I have never used that compiler but I'll try to assist the best I can.

    What is ext1isr in this context?
    ---My Flickr photo (mostly screenshots these days!) stream. Have a look!

    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    TCP client/server connection | Retrieving the EventHandler for any Event by code.
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Lively Member
    Join Date
    Mar 2010
    Posts
    123

    Re: void pointer to interrupt function

    You check ext1isr variable, it's not been declared in code scope.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    265

    Re: void pointer to interrupt function

    @Athiest
    Quote Originally Posted by wolf99 View Post
    Code:
    // ISR name= interrupt void ext1isr (void)
    ext1isr is the function. Im trying to make a pointer to a function.

    So I have the rest of the pointer manipulation working bar trying to assign the functions address to the pointer.
    In Keil C (and ANSI C AFAIK) the code would be this:
    Code:
    pIsr = &functionName;
    Which is what seems to be throwing the only error that functionName is an undefined identifier....
    I placed the ISR function above the main() in the file and the error leaves but is replaced by a warning: "redundant "&" applied to function" which makes me think that what is happening here is that the program is actually calling the function and expecting a variable to be returned that will then be placed in the variable pISR, some thing like if I had written:
    Code:
    int x = add(5,5) // expect x = 10
    *sigh*
    Thanks

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: void pointer to interrupt function

    Is the method defined in the same code file as the containing the code of your first post? Have you placed a function declaration at the top of your code?
    Code:
    void ext1isr(void);
    You probably already know this, but if you omit this declaration, the order of which the methods are written suddenly becomes important, because you can not refer to a method defined further down in your source code.

    Quote Originally Posted by wolf99 View Post
    I placed the ISR function above the main() in the file...
    With the ISR function being ext1isr, and main containing the code snippet from the first post? Have you tried simply removing the ampersand from your assignment? I just tried with gcc and it allows function pointer assignment to be done both with and without the ampersand. Perhaps your compiler only supports the latter.
    Code:
    pIsr = functionName;
    ---My Flickr photo (mostly screenshots these days!) stream. Have a look!

    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    TCP client/server connection | Retrieving the EventHandler for any Event by code.
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    265

    Re: void pointer to interrupt function

    Hi Athiest
    Thanks, I had neglected to declare the isr *facepalm*

    So Ive removed the & and the warning has gone...
    ... checking in memory view... and yes the right values are in the DPTR

    Many Thanks!

    (now I just need to get my LJUMP right..oh I see youve answered that t0o! coolio!)
    Last edited by wolf99; Jan 19th, 2012 at 08:53 AM.
    Thanks

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: void pointer to interrupt function

    Great!
    ---My Flickr photo (mostly screenshots these days!) stream. Have a look!

    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    TCP client/server connection | Retrieving the EventHandler for any Event by code.
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.