SHARE
TWEET

Untitled

a guest May 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // pointer to store the callback
  5. void (*pUARTHandler)();
  6.  
  7. void UARTEvent()
  8. {
  9.     (*pUARTHandler)();
  10. }
  11.  
  12. // register the callback
  13. void registerUARTHandler(void (*ptr)())
  14. {
  15.     pUARTHandler = ptr;
  16. }
  17.  
  18. void myUARTHandler()
  19. {
  20.     cout << "This is handler 1" << endl;
  21. }
  22.  
  23. void yourUARTHandler()
  24. {
  25.     cout << "This is handler 2" << endl;
  26. }
  27.  
  28. int main()
  29. {
  30.     registerUARTHandler(&myUARTHandler);
  31.     UARTEvent();
  32.     UARTEvent();
  33.     UARTEvent();
  34.     registerUARTHandler(&yourUARTHandler);
  35.     UARTEvent();
  36.     return 0;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top