PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 12, 2014 11:21 pm |
|
|
I think your post here is a continuation of this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=53192
You should keep it all in one thread and not make multiple threads.
Anyway, I made a sample program shown below, that I think does what
you want. I tested it with compiler vs. 5.033. This program demonstrates
putting a function pointer in a structure. It shows an array of structures
stored in Flash memory and initialized. It shows that the structure
elements can be displayed and that the function pointer works.
Here is the output of the program in MPLAB simulator:
Quote: |
Option1
05
01
02
00
011f
01
Running testfun() function
|
Test program:
Code: | #include <16F1825.h>
#fuses INTRC_IO, NOWDT, BROWNOUT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
void testfun(void)
{
printf("Running testfun() function\r");
}
typedef char* (*_fptr)(int8);
typedef struct {
char text[14];
char num_menu;
char UP;
char DOWN;
char ENTER;
_fptr funct_ptr;
int default_value;
}MenuEntry;
const MenuEntry menu[10]= {
{"[Main] ",5,0,0,0,0,0},
{"Option1 ",5,1,2,0,testfun,1},
{"Option2 ",5,0,0,0,0,2},
{"Option3 ",5,0,0,0,0,3},
{"Option4 ",5,0,0,0,0,4},
{"[Sub] ",5,0,0,0,0,5},
{"Option1 ",5,0,0,0,0,6},
{"Option2 ",5,0,0,0,0,7},
{"Option3 ",5,0,0,0,0,8},
{"Option4 ",5,0,0,0,0,9}
};
//===================================
void main()
{
printf("%s \r", menu[1].text);
printf("%x \r", menu[1].num_menu);
printf("%x \r", menu[1].UP);
printf("%x \r", menu[1].DOWN);
printf("%x \r", menu[1].ENTER);
printf("%lx \r",menu[1].funct_ptr);
printf("%x \r", menu[1].default_value);
printf("\r");
(*menu[1].funct_ptr)();
while(TRUE);
} |
|
|