CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Help - Pointers and Structures in PIC16F1825

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

Help - Pointers and Structures in PIC16F1825
PostPosted: Fri Dec 12, 2014 9:22 pm     Reply with quote

I am trying to implement a menu system and would like to use structures and functions pointers to access it. I would like to know what is the best way to implement it in PIC16F1825. Thank you for all your comments and suggestions.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 12, 2014 11:21 pm     Reply with quote

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);
}
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Sat Dec 13, 2014 9:32 pm     Reply with quote

PCM programmer thanks so very much. I just compiled it with CCS PCM C Compiler, Version 5.026. And its working now. Thank you again your comments were very helpful. Happy Holidays.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group