Using a pointer to a function

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can I use a pointer to a function in AVR. I've heard of it, but never used it. how is it done?

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void (*fn_ptr) (void);

fn_ptr = 0x0307;

(*fn_ptr)();

would define a variable 'fn_ptr' that points to a function that takes void parms and has a void return. If you were to set it to the 0x0307 value and then vector to it the CPU would execute from address 0x0307 onwards. You'd probably actually want to set it to a named function and then it would vector to that function (but omitting this simplifies the code above).

Cliff

Last Edited: Thu. Sep 8, 2005 - 12:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PS Hey - how cool - Google says there's actually a http://www.function-pointer.org/ !!

Cliff