1

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 ?

SamGibson
  • 17,231
  • 5
  • 37
  • 58
Daniel
  • 897
  • 9
  • 31
  • 2
    please describe the problem that you are having ... `not working` and `messy` are useless descriptions – jsotola Jul 23 '19 at 18:20
  • @jsotola, Although the indicator of line works fine. The text on the lines are unreadable characters, pieces of words in wrong place and without meaning – Daniel Jul 23 '19 at 21:11
  • 1
    Messy lcd display happens for 2 reasons. (A) you are sending non-ascii characters, (B) your baud rate/ data rate is incorrect. Only YOU can verify these. How are you connected to this display? Is it parallel bus or Uart. If uart, then maybe your Tx is inverted. – Kripacharys Jul 24 '19 at 12:21
  • @Kripacharya , it is uart, but it is not a display problem, the display works. I put more information below the word "EDITED" (in bold) at the beginning of the post. – Daniel Jul 24 '19 at 12:53
  • I never said it's a display problem. I pointed out 3 other possible sources where problem might lie. – Kripacharys Jul 24 '19 at 12:58
  • @Kripacharya I understood, thank you. But, when I said display problem, I meant that the problem is not in the conections with display, and the additional information I put in the post's edited area – Daniel Jul 24 '19 at 13:07

0 Answers0