I need help to understand "User Code"

General discussion on Visual GLCD Software.
Post Reply
Author
Message
Ls2
Posts: 50
Joined: 17 Jun 2014 14:08

I need help to understand "User Code"

#1 Post by Ls2 » 12 Jun 2019 02:03

Hello.

After a long time, I decided to take my SmartGLCD from the drawer. But I can not go much further...

How should I use the User Code correctly? Well, I have this piece of code:

//--------------------- User code ---------------------//

//----------------- End of User code ------------------//


but when I put a code inside that, something like
char name;
name = 'x';


I have compilation errors :( I was able to execute code according to actions (eg pressing X button), but how could I do, for example, to get a data via USART and update a label? How to use interrupts?

I apologize for so many questions...


Best regards,
Leo

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: I need help to understand "User Code"

#2 Post by jovana.medakovic » 12 Jun 2019 10:27

Hello,

Here is the link to the SmartGLCD page:
https://www.mikroe.com/smartglcd
There is a link to the examples for SmartGLCD, on the bottom of this page in the Downloads section, which can help you to write your project.

Regarding the error which you get, in this section, you can write:
char name = 'x';
After that, you can use name = 'x', but only inside some function.

Kind regards,
Jovana

Ls2
Posts: 50
Joined: 17 Jun 2014 14:08

Re: I need help to understand "User Code"

#3 Post by Ls2 » 13 Jun 2019 01:40

Hello jovana.medakovic,

Thank you! I did the download of the examples files. However, I still have some doubts. I'm trying to update a Label with the data coming from UART. Looks very simple, but didn't work.

main():

Code: Select all

Start_TP();
  UART1_Init(9600);

  while (1) {
    Check_TP();
    
    if(UART1_Data_Ready()){
                           rx_buffer = UART1_Read();
                           velocityShow(rx_buffer);
    }
  }

}
events_code:

Code: Select all

void velocityShow(char string){
     strcpy(VelLabel_Caption, string);
     DrawLabel(&VelLabel);
}
Well, VelLabel is a string on screen. When I update its content and run DrawLavel, the VelLabel doesn't update correctly (shows a mix of other strings on screen).
How can I update a string with UART data? I'm going mad :lol:

Best regards,
Leo

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: I need help to understand "User Code"

#4 Post by jovana.medakovic » 13 Jun 2019 14:16

Hello,

If you want to update a string on the label, you have to "delete" old text and then write a new.
Also, rx_buffer = UART1_Read() read only one byte. However, if you want to write some text on the label, you have to save it in some buffer, for example unsigned char message[20] = "";
I recommend you to look at UART1_Read_Text function in our help file.

Code: Select all

void velocityShow(char string){
     strcpy(Label1_Caption, "                   ");   //char Label1_Caption[19]  -> 19 space
     DrawLabel(&Label1);
     message[0] = string;
     strcpy(Label1_Caption, message);
     DrawLabel(&Label1);
}
Kind regards,
Jovana

Ls2
Posts: 50
Joined: 17 Jun 2014 14:08

Re: I need help to understand "User Code"

#5 Post by Ls2 » 14 Jun 2019 00:18

Hello Jovana,

Thank you again :D But I can't erase the old string. I set the string in Visual GLCD as "40 km/h". So, I call this function:

Code: Select all

void atualizaVelocidade(char string){
     strcpy(displayLabel_Caption, "       ");
     DrawLabel(&displayLabel);
     strcpy(displayLabel_Caption,"30 km/h");
     DrawLabel(&displayLabel);
}
In Smart GLCD, the "3" of "30 km/h" is written on top of the "4", showing an incorrect character. Works well only if I call DrawScreen(&Screen1), but calling DrawScreen is impractical slow :(

How can I fix it?

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: I need help to understand "User Code"

#6 Post by jovana.medakovic » 18 Jun 2019 15:19

Hello,

In the attachment, you can find the SmartGLCD Demo example.
After calibration, you will get this text on the display:
Smart GLCD 240x128
by MikroElektronika

When you send some characters from UART, instead of Smart GLCD 240x128 you will get 30 km/h.

Kind regards,
Jovana
Attachments
SmartGLCD Demo.zip
(415.73 KiB) Downloaded 93 times

Post Reply

Return to “Visual GLCD General”