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

another struct problem

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



Joined: 31 Oct 2016
Posts: 452
Location: Montenegro

View user's profile Send private message

another struct problem
PostPosted: Sun Jun 23, 2019 10:02 am     Reply with quote

Dear All,

I'm trying to implement an LCD menu structure, translating to CCS this tutorial: https://www.youtube.com/watch?v=PFzNBtnfJ6Y

Up until I hit upon this error, everything compiled OK. I have a structure defined like this:

Code:

typedef rom struct MenuStructure{ 
   rom char  *text;
   unsigned char num_menupoints;
   unsigned char up;
   unsigned char down;
   unsigned char enter;
   void (*fp)(void);
   }             
   MenuEntry;


and then MenuEntry like this:

Code:


void start(void);

rom char menu_000[] = "  [MAIN SCREEN]";  // 0
rom char menu_001[] = "  Option1";        // 1
rom char menu_002[] = "  Option2";        // 2
rom char menu_003[] = "  Option3";        // 3                                             
rom char menu_004[] = "  START";          // 4                           

rom char menu_100[] = "  Sub Menu";       // 5                                                   
rom char menu_101[] = "  SubOption1";     // 6                                 
rom char menu_102[] = "  SubOption2";     // 7                                                                                             
rom char menu_103[] = "  RETURN";         // 8                         
                                                                                                 
unsigned int8 selected = 1;               // indicates selected menu item                                 
                                                                                                                     
// every element of the array must have all elements defined in the prototype: number of elements, up, down, enter and function (can be null)                                                                                                                       
MenuEntry Menu[] = {
   (menu_000, 5, 0, 0, 0, 0),             // 0; main menu 0, 5 options, up button menu_000, down button menu_000, enter menu_000, no function attached - non browsable
   (menu_001, 5, 1, 2, 5, 0),             // 1; main menu 1, 5 options, up button menu_001, down button menu_002, enter menu_101, no function attached
   (menu_002, 5, 1, 3, 2, 0),             // 2; main menu 2, 5 options, up button menu_001, down button menu_003, enter menu_002, no function attached
   (menu_003, 5, 2, 4, 3, 0),             // 3; main menu 3, 5 options, up button menu_002, down button menu_004, enter menu_003, no function attached
  (menu_004, 5, 3, 4, 4, [b]start[/b]),         // 5; main menu 4, 5 options, up button menu_003, down button menu_004 (no roll-over), enter menu_004, start function attached
//   (menu_004, 5, 3, 4, 4, 0),
                                                                                                                                   
                                                                                                                                   
// sub-menu for menu_001                                             
   (menu_100, 4, 0, 0, 0, 0),             // 6; main menu, 5 options, up button menu_001, down button menu_002, enter menu_101, no function attached           
   (menu_101, 4, 7, 8, 7, 0),             // 7; main menu, 5 options, up button menu_001, down button menu_002, enter menu_101, no function attached
   (menu_102, 4, 7, 9, 8, 0),             // 8; main menu, 5 options, up button menu_001, down button menu_002, enter menu_101, no function attached
   (menu_103, 4, 8, 9, 1, 0)              // 9; main menu, 5 options, up button menu_001, down button menu_002, enter menu_101, no function attached

};


When I add this to my code, the compiler throws me "Element is not a member" error on this line for fp:



Code:

         if(menu[selected].fp != 0){
            menu[selected].fp();
         }


This is my first time trying to do anything with structures, so at this point I don't know what is causing this error. Maybe the function in the structure is defined wrong.

Right now it is a theoretical code (didn't assemble the hardware yet and debounce routine is missing), but I'm compiling it for 18f4550, compiler version 5.078.

Regards,
Samo
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 23, 2019 6:53 pm     Reply with quote

I was able to make the following program work in MPLAB vs. 8.92
simulator, with CCS vs. 5.085. I didn't test any other compiler versions.
It compiles with no errors or warnings.
The program below displays the following in the MPLAB output window:
Quote:

Hello World
menu[0].fp = 0000
menu[1].fp = 0068


ROM Allocation from .SYM file, showing the program picks up
the correct address for the dummy() function:
Quote:

000004 @const735.call
000012 @GOTOPTR
000020 @const758.call
000032 @const764.call
000044 @PSTRINGC_9600_31766_31767
000068 dummy
000074 @PSTRINGCN_9600_31766_31767
000094 @PRINTF_X_9600_31766_31767
0000D6 MAIN
0000D6 @cinit1
00010C @cinit2


Test program:
Code:
#include <18F46K22.h>
#use delay(internal=4M)
#use rs232(baud=9600, UART1, ERRORS)

void dummy(void)
{
printf("Hello World\n\r");
}

typedef void(*_fptr)(void);



typedef struct MenuStructure

 rom char  *text;
 unsigned char num_menupoints;
 unsigned char up;
 unsigned char down;
 unsigned char enter;
 _fptr fp;
}MenuEntry;
 
rom char menu_000[] = "  [MAIN SCREEN]"; 
rom char menu_001[] = "  Option1";     
                                                                                                 
unsigned int8 selected = 1;
                                                                                                                     
MenuEntry Menu[] =
{
{menu_000, 5, 0, 0, 0, 0},
{menu_001, 5, 1, 2, 5, dummy} 
};
 

//=============================
void main()
{

if(menu[selected].fp != 0)
  {
   (*menu[selected].fp)();
  }

selected = 0;
printf("menu[0].fp = %lx\r", menu[selected].fp);

selected = 1;
printf("menu[1].fp = %lx\r", menu[selected].fp);

while(TRUE);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jun 24, 2019 12:34 am     Reply with quote

The error honestly suggests you may have something else declared
at this point in the code called 'menu'...
I tested PCM_programmers's example in 5.078, just to make sure this
isn't the problem, and it runs fine.
PrinceNai



Joined: 31 Oct 2016
Posts: 452
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Jun 24, 2019 5:32 am     Reply with quote

First I tested the program that PCM programmer kindly attached. It works. Then I implemented it on mine and it didn't compile, but with a different error. After half an hour of looking in my monitor I saw what was wrong. I used normal brackets instead of curly ones when I wrote the array. Now it compiles OK.

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jun 24, 2019 6:25 am     Reply with quote

Aaargh!... Sad

Been there. Got the 'T'-shirt.

Glad you have found the issue....
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