I need to print a list of items of a menu in a 16x4 LCD using a PIC18F4550. I already did it using MPLABX and XC8 compiler and it worked fine, however, I need to migrate it to mikroC environment. But, It is not working. The characters are messy in the display. Although the indicator of line works fine, the text on the lines is unreadable characters, pieces of words in the wrong place and without meaning.
I put here a slice of code because the code is big to put it here. But, can someone find a mistake in this code that I wrote here? Sorry for the lack of comments in the code, but it was in the other language and the variables too, I translated the variables to make the code more readable here.
EDITED:
The code works in the following way: I have a stack to store the menus, the menu structure has a field that points to a list of items that has the line text.
I guess the problem is in the pointer of the menu to list Of Items. This way as below
stackMenus->stack[stackMenus->top]->itens[0]->text
It is in the function of menu_draw(Tstack *stackMenus). If I put a string directly, the line will be written correctly. But, if I use the code above, it doesn't. I didn't put the entire code because it is too big. I used a lot of pointers in this passage, so I'm afraid that this is causing the problem, so I put the code related to this passage here. Sorry for the incomplete information.
Here is the code:
(...)
Tstack stackMenus;
stackMenus.top = 0;
error = menu_stack(&stackMenus, &mainMenu);
changeMenu = TRUE;
typeActualMenu = eSubmenu;
menu_handleMenus(&stackMenus);
(...)
Terro menu_stack( Tstack *s, PTmenu iten ){
Terro error = SUCCESS;
if(s->top == SIZE_MAX_STACK_MENUS - 1){
return ERROR_STACK_MENUS_FULL;
}
s->stack[++s->top] = iten;
return error;
}
(...)
Terro menu_handleMenus(Tstack *stackMenus){
(...)
menu_draw(stackMenus);
(...)
}
(...)
void menu_draw(Tpilha * pilhaMenus){
(...)
Lcd_16x4_Out(1,1, stackMenus->stack[stackMenus->top]->title);
Lcd_16x4_Out(2,2, stackMenus->stack[stackMenus->top]->itens[0]->text);
Lcd_16x4_Out(3,2, stackMenus->stack[stackMenus->top]->itens[1]->text);
Lcd_16x4_Out(4,2, stackMenus->stack[stackMenus->top]->itens[2]->text);
(...)
}
//This is a 16X4 LCD adequacy code of the original library of MicroC
void Lcd_16x4_Out(char row, char column, char *text){
switch(row){
case 0x01:
LCD_CMD(128 + column - 1);
break;
case 0x02:
LCD_CMD(192 + column - 1);
break;
case 0x03:
LCD_CMD(144 + column - 1);
break;
case 0x04:
LCD_CMD(208 + column - 1);
break;
}
Lcd_Out_Cp(text);
}
These are the List of Items:
const TitenMenu listaItensMenuPrincipal[] = {
{0, eSubmenu, "Iten1", NULL},
{1, eSubmenu, "Iten2", NULL},
{2, eSubmenu, "Iten3", NULL},
{3, eSubmenu, "Iten4", NULL},
};
Tmenu mainMenu = {
menu_numberOfItens(mainMenuItensList),
"Main Menu",
(PTitenMenu)mainMenuItensList,
NULL
};
These are the structures and types:
struct Sstack {
PTmenu stack[SIZE_MAX_STACK_MENUS];
Tint8 top;
};
typedef struct Sstack Tstack;
typedef Tuint8 TidMenu;
typedef TidMenu *PTidMenu;
typedef unsigned char TmodoItenMenu;
struct SitenMenu {
TidMenu id;
TmodoItenMenu type;
char *text;
void *submenu;
};
typedef struct SitenMenu TitenMenu;
typedef TitenMenu *PTitenMenu;
struct Shandlers{
Terror (* create)(void);
Terror (* selection)(TidMenu);
void (* destroy)(void);
};
typedef struct Shandlers Thandlers;
typedef Thandlers * PThandlers;
struct Smenu {
unsigned char numberOfItens;
// Title
char *title;
PTitenMenu itens;
PThandlers handlers;
};
typedef struct Smenu Tmenu;
typedef Tmenu *PTmenu;[/code]
I solve the problem !! At least until now... When I did
const TitenMenu listaItensMenuPrincipal[]
Is was not working , So, I did:
TitenMenu listaItensMenuPrincipal[]
And it works fine. I don't know why it happened, but, I will keep it this way. Does someone have any idea of why it happens ?