View previous topic :: View next topic |
Author |
Message |
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
Const struct |
Posted: Thu May 26, 2016 11:12 am |
|
|
Hi all
I use this kind of code with older CCS compiler (<5.50) without any issue.
But with latest version 5.59 I get no error but the code is not working any more.
I point out the default at this point Quote: | const struct TypeMenu MenuTest[ALL_MENU] |
The const struct is not working just struct is working with the last version of ccs.
Is this a compiler error or did I miss something?
Code: |
#include <18f46k20.h>
#use delay(clock=16000000)
#fuses INTRC_IO, NOWDT, PUT, NOPROTECT, NOBROWNOUT
#use fast_io(c)
#use fast_io(d)
#include "HDM64GS12.C" // driver GLCD
#include "GRAPHICS.C" // graphics
#define VAL_TRIS_C 0b00000000 // PORTC
#define VAL_TRIS_E 0b00000000
#define UP PIN_A1
#define DOWN PIN_A2
#define ENTER PIN_A3
#define POWER PIN_A4 //
#define CANCEL PIN_C0
#define BACKLIGHT PIN_E2 //
/**************************************************************************//**
* Def menu
******************************************************************************/
#define MENU 0 // defaut start
#define ALL_MENU 4
//-----------------------------------------------------------------------------
// Tree menu
//-----------------------------------------------------------------------------
enum ids{ _BEGIN,
_MAIN,
_MAIN1,
_MAIN11,
_MAIN12
};
struct TypeMenu {
int8 MenuID;
int8 SubMenu;
char MenuName[18];
};
int8 ContainMenu, STATE = _BEGIN, PAGE = 0, LEVEL[7], LevelPtr=0;
Boolean AccessENTER = TRUE, AccessCANCEL=TRUE;
//-------------------------------------------
//const struct TypeMenu MenuTest[ALL_MENU]
struct TypeMenu MenuTest[ALL_MENU]
={
{_MAIN, _BEGIN,"Menu1"},
{_MAIN1,_BEGIN,"Menu2"},
{_MAIN11,_MAIN1,"Menu2 sub1"},
{_MAIN12,_MAIN1,"Menu2 sub2"}
};
struct TypeMenu MenuPointer[2];
//---------------------------------------
unsigned char SelectFrom(int8 from) {
int8 i, NumMenu = 0,k=0, i0;
for(i=0; i<ALL_MENU; i++) {
if(MenuTest[i].SubMenu == STATE) {
if(NumMenu == 0) i0 = i;
NumMenu++;
if(NumMenu>from && k < 2 ) { // if(NumMenu>from && k < 2)
MenuPointer[k] = MenuTest[i];
k++;
}
if(k == 1) MenuPointer[1] = MenuTest[i0];
}
}
return NumMenu;
}
//----------------------------------------
int8 QueryLastMenu() {
int8 i;
for(i=0; i<ALL_MENU; i++) {
if(MenuTest[i].MenuID == MenuPointer[0].SubMenu)
return MenuTest[i].SubMenu;
}
return 0x00;
}
//----------------------------------------
short HasSubMenu() {
char i;
for(i=0; i<ALL_MENU; i++) {
if(STATE == MenuTest[i].SubMenu)
return TRUE;
}
return FALSE;
}
/**************************************************************************//**
* Init PIC
*****************************************************************************/
void PIC_init(void){
set_tris_c(VAL_TRIS_C); // graphic lcd control lines all output
set_tris_d(0x00); //Set PortD to output
set_tris_e(VAL_TRIS_E);
//---- PIC init ------------------------------------------------
setup_oscillator(OSC_16MHZ);
enable_interrupts(GLOBAL);
}
/**************************************************************************//**
* Fonction Menu
*****************************************************************************/
void ProcessMenu() {
if(PAGE > ContainMenu-1) PAGE = 0;
if(PAGE == 0xFF) PAGE = ContainMenu - 2;
ContainMenu = SelectFrom(PAGE);
glcd_fillScreen(OFF); //Display clear
glcd_text57(3, 40, MenuPointer[0].MenuName, 1, ON);
}
/**************************************************************************//**
* Fonction quit Menu
*****************************************************************************/
void Quit(){
if(!AccessCANCEL) break;
if(LevelPtr) LevelPtr--;
PAGE = LEVEL[LevelPtr];
if(!HasSubMenu()) {
AccessENTER = TRUE;
STATE = MenuPointer[0].SubMenu;
} else {
STATE = QueryLastMenu();
}
ContainMenu = SelectFrom(0);
ProcessMenu();
}
/**************************************************************************//**
* Fonction Action Menu
*****************************************************************************/
void ProcessAction(long Key) {
int1 faux;
faux = FALSE;
if(STATE == _BEGIN) AccessCANCEL = FALSE;
else AccessCANCEL = TRUE;
switch(Key) {
case ENTER:
if(!AccessENTER) break;
LEVEL[LevelPtr] = PAGE;
LevelPtr++;
STATE = MenuPointer[0].MenuID;
PAGE = 0;
ContainMenu = SelectFrom(0);
if(ContainMenu) {
ProcessMenu();
}else {
AccessENTER = FALSE;
switch(STATE){
case _MAIN: //Bat
glcd_fillScreen(OFF);
Delay_ms(1000);
Quit();
break;
case _MAIN1: //Backlight ON
output_toggle(BACKLIGHT);
Delay_ms(100);
Quit();
break;
}
}
break;
case UP:
if(!AccessENTER) break;
if(PAGE == 0) PAGE = ContainMenu;
PAGE --;
ProcessMenu();
break;
case DOWN:
if(!AccessENTER) break;
PAGE ++;
ProcessMenu();
break;
case CANCEL:
if(!AccessCANCEL) break;
if(LevelPtr) LevelPtr--;
PAGE = LEVEL[LevelPtr];
if(!HasSubMenu()) {
AccessENTER = TRUE;
STATE = MenuPointer[0].SubMenu;
} else {
STATE = QueryLastMenu();
}
ContainMenu = SelectFrom(0);
ProcessMenu();
break;
case MENU:
ContainMenu = SelectFrom(0);
ProcessMenu();
Break;
}
}
//Main
void main()
{
//Setup Pic
PIC_init();
//Setup LCD
glcd_init(ON);
glcd_fillScreen(OFF); // Display clear
STATE = _BEGIN;
processAction(MENU);
while(TRUE)
{
if(input(DOWN) == 1)
{
while(input(DOWN) == 1) {}; // wait for releasing Button1
processAction(DOWN);
}
if(input(UP) == 1)
{
while(input(UP) == 1) {}; // wait for releasing Button1
processAction(UP);
}
if(input(ENTER) == 0)
{
while(input(ENTER) == 0) {}; // wait for releasing Button1
processAction(ENTER);
}
if(input(CANCEL) == 1)
{
while(input(CANCEL) == 1) {}; // wait for releasing Button1
processAction(CANCEL);
}
}
} |
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu May 26, 2016 12:49 pm |
|
|
stuff like this is silly oddly-coded.
Code: |
case DOWN:
case CANCEL:
///..
|
that the argument driving the decisions is a pin number designator
is pretty unusual.
Last edited by asmboy on Thu May 26, 2016 3:32 pm; edited 1 time in total |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 26, 2016 6:58 pm |
|
|
Quote: | but the code is not working any more. |
What did your code do when it was working correctly, and what is it doing now ?
Example:
"My program used to scroll through the menu when the up/down keys
were pressed. But now it only shows the first menu. The up/down keys
do not cause it to scroll".
or
"My program used to display the menu text. Now it displays garbage".
(Then post the text that it should display, and post the garbage text that
it now displays).
Give us a detailed explanation of how it's failing. Tell us what you see. |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Fri May 27, 2016 5:52 am |
|
|
on a simple menu like on the example
My program used to scroll through the menu when the up/down keys
were pressed. But now it only shows the first menu. The up/down keys
do not cause it to scroll. It stays stuck at the first menu position. The first position menu is working when I press enter (clear screen and go back to menu after delay)
In more complicated menu key do not scroll and text is garbage.
working : Menu
default : ꟻꟻꟻꟻꟻꟻꟻꟻꟻꟻꟻꟻꟻꟻ
When I only declare Quote: | struct TypeMenu MenuTest[ALL_MENU] | instead of Quote: | const struct TypeMenu MenuTest[ALL_MENU] | it work but only with small menu. with big menu I get not enough ram size. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9250 Location: Greensville,Ontario
|
|
Posted: Fri May 27, 2016 6:14 am |
|
|
this..
Quote: | with big menu I get not enough ram size. |
.. should be a clue.
Look at the end of the listing and see what resources are used
ROM%
RAM%
STACK.
'not enough RAM' means there isn't enough RAM to run your program !
The fact you're using a GLCD means you probably ave a HUGE mount of RAM given to the driver's db of 'fonts'. This is not shown in the program you've given us.
Since your 'menu' system/functions worked before, simply go back xx versions, and see what you've done since then. THAT is probably why 'it doesn't work'.
Jay |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Fri May 27, 2016 6:19 am |
|
|
Hi Jay
I made no change, if a build a version with 5.50 it works if a build a version 5.59 it doesn't. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9250 Location: Greensville,Ontario
|
|
Posted: Fri May 27, 2016 8:53 am |
|
|
OK, I copied your program, remarked out the GLCD code and it compiles fine, NO errors. Uses 2% ROM, 3-4% RAM.
One glaring issue I just saw is that you have the interrupts enabled with NO ISRs ! That is very, very bad and will lead to unpredictable problems like crashes, 'funny' results, etc.
Jay |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Mon May 30, 2016 6:24 am |
|
|
Hi Jay
Your right living the interrupt enable is not a good idea for my sample prog but it's not the cause of the problem I get.
As I told you I have no build error so I suppose it's a buggy version of CCS |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 17, 2016 7:20 am |
|
|
It is a bug. I finally had time to investigate this thoroughly. There is
a problem with copying an array element from one array to another
when the source is a structure declared as 'const'. There are a few lines
of generated ASM code that are incorrect, starting with compiler vs. 5.057.
I did a complete write-up of the bug and sent it to CCS just now. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 17, 2016 10:54 am |
|
|
CCS quickly emailed me a new PCH.DLL file. I used it to replace the one
in the DLL\5.059\ subdirectory in the CCS folder. It fixed the problem.
When I ran the test program shown below in MPLAB vs. 8.92 simulator
it displayed the following results in the Output Window. This is the correct output:
Quote: |
> Menu1
> Menu2
> Menu2 sub1
> Menu2 sub2
|
Test program:
Code: | #include <18F46K20.h>
#fuses INTRC_IO, NOWDT, PUT, NOPROTECT, NOBROWNOUT
#use delay(clock=16M)
#use rs232(baud=9600, UART1, ERRORS)
#define ALL_MENU 4
enum ids{ _BEGIN,
_MAIN,
_MAIN1,
_MAIN11,
_MAIN12
};
struct TypeMenu {
int8 MenuID;
int8 SubMenu;
char MenuName[18];
};
//-------------------------------------------
const struct TypeMenu MenuTest[ALL_MENU]
={
{_MAIN, _BEGIN,"Menu1"},
{_MAIN1,_BEGIN,"Menu2"},
{_MAIN11,_MAIN1,"Menu2 sub1"},
{_MAIN12,_MAIN1,"Menu2 sub2"}
};
struct TypeMenu MenuPointer[2];
//==================================
void main()
{
int8 i;
int8 k;
k = 0;
for(i = 0; i < ALL_MENU; i++)
{
MenuPointer[k] = MenuTest[i];
printf("> %s \r", MenuPointer[0].MenuName);
}
while(TRUE);
} |
After installing the new PCH.DLL file, the compiler reports its version as
5.060. If you need this DLL file, contact CCS (if you own the compiler)
or wait for vs. 5.060 to be released. |
|
|
in_nursery
Joined: 25 Oct 2012 Posts: 51
|
|
Posted: Mon Jun 20, 2016 5:45 am |
|
|
thanks PCM programmer for your time and support.
I will contact ccs. |
|
|
younder
Joined: 24 Jan 2013 Posts: 53 Location: Brazil
|
|
Posted: Sun Oct 09, 2016 8:56 pm |
|
|
Hi in_nursery
I'm still facing the same problem as yours. With latest CCS Compiler version this menu code doesn't work! Were you able to found a solution for this other than compile the code with 5.50?
Thanks
Hugo _________________ Hugo Silva
Last edited by younder on Wed Oct 12, 2016 7:46 pm; edited 2 times in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Mon Oct 10, 2016 3:22 am |
|
|
I don't think you have the same problem.
The fix, is there in 5.061, 5.062, and 5.064 (just tested all of them, and they run fine). |
|
|
|