Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
void function1 (void) //declare two functions: function 1
{
//function 1 code
}
void function2 (void) //and 2
{
//function 2 code
}
void (*fp) (void); //declare function pointer. The pointed function must
//be void on both return value and arguments fields, like function1 and function2
void main (void)
{
uint8 status;
while(1)
{
status = pin_read(P0);
if (status) //depending on pin status
{
fp = function1; //fp points to function1
}
else
{
fp = function2; //or to function2
}
fp(); //run function (function1 or 2, depending on the pin status)
}
}
uint16 (*fp) (uint8, uint8);
uint16 function3 (uint8 x, uint8 y);
fp = function3;
uint16 z = fp(219,5);
; setup function pointer
movlw HIGH(func_a)
movwf FPTR_H ; high address of function
movlw LOW(func_a)
movwf FPTR_L ; low addr ...
; ------------------------------------------------------------------------
; call function pointer
; 1. push return value onto the call stack
push ; make room on stack
movlw HIGH(return_from_function_call)
movwf TOSH
movlw LOW(return_from_function_call)
movwf TOSL
clrf TOSU
; do the call / load function pointer into PC (PCL last, executes PC update)
clrf PCLATU
movf FPTR_H, W, ACCESS
movwf PCLATH
movf FPTR_L, W, ACCESS
movwf PCL ; call function
return_from_function_call