Jump to content
43oh

How can I write Symbols into LCD with MSP430G2553?


Recommended Posts

Hello guys, 
I'm building a Holter ECG, and would like put one symbol on the LCD.

Need to inform the user the level of charge that the battery has.

And I would put the battery symbol so that information was given. But I am not getting, someone can give me an example of how I can put a symbol in a particular line of lcd
Link to post
Share on other sites

Your question is questionable. If you do not name your LCD or library, we cannot reasonably answer your question.

 

Most LCDs have a limited custom character memory, mostly the first 8 characters can be filled with bitmaps to your liking. One application might be to have icons for <10% 25% 50% 75% and 100% battery charge. This even leaves you with 3 unused symbols (you might use one for "charging" and "charging completed").

Link to post
Share on other sites
84 roadrunner, thank you for answering 

My intention is to have all the icons for <10% 25% 50% 75% and 100% battery charge. And every time the MCU read the battery to return the respective icon, for the respective charge.

My LCD is GDM1602K, and I send you my lcd.c file.

I already define the symbols you can see in custom part




#include "lcd.h"


/*****************************************************************/
/********* DEFINES *********/
/*****************************************************************/

#define P1orP2lcd 0x0200

#define EN (PP2 + BIT5)
#define RS (PP1 + BIT3)
#define D0 (PP2 + BIT1)
#define D1 (PP2 + BIT2)
#define D2 (PP2 + BIT3)
#define D3 (PP2 + BIT4)



//#define BACKLIGHT (PP1 + BIT0)

// Commands
#define CLEAR 0x01



/*****************************************************************/
/********* CUSTOM *********/
/*****************************************************************/

const unsigned char vazio[] = {0x0,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const unsigned char corazon[]= {0x00,0xa,0x1f,0x1f,0xe,0x4,0x00,0x00};
const unsigned char bat_100[]= {0x4,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_75[] = {0x4,0x1b,0x11,0x1f,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_50[] = {0x4,0x1b,0x11,0x11,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_25[] = {0x4,0x1b,0x11,0x11,0x11,0x11,0x1f,0x1f};
const unsigned char bat_0[] = {0x4,0x1b,0x11,0x11,0x11,0x11,0x11,0x1f};


/*****************************************************************/
/********* LOCAL FUNCTIONS *********/
/*****************************************************************/

void lcdDirPinout(unsigned int pin)
{
if(pin < P1orP2lcd){
P1DIR |= (pin & 0x00FF);
}else{
P2DIR |= (pin & 0x00FF);
}
}


/*
*
*/
void lcdSetPinout(unsigned int pin)
{
if(pin < P1orP2lcd){
P1OUT |= (pin & 0x00FF);
}else{
P2OUT |= (pin & 0x00FF);
}
}

void lcdClrPinout(unsigned int pin)
{
if(pin < P1orP2lcd){
P1OUT &= ~(pin & 0x00FF);
}else{
P2OUT &= ~(pin & 0x00FF);
}
}

void lcdSetValue(unsigned char value)
{
if(value & 0x08){
lcdSetPinout(D3);
}else{
lcdClrPinout(D3);
}

if(value & 0x04){
lcdSetPinout(D2);
}else{
lcdClrPinout(D2);
}

if(value & 0x02){
lcdSetPinout(D1);
}else{
lcdClrPinout(D1);
}

if(value & 0x01){
lcdSetPinout(D0);
}else{
lcdClrPinout(D0);
}

delay_us(10);
}


void lcdTriggerEN()
{
lcdSetPinout(EN);
delay_us(10);
lcdClrPinout(EN);
delay_us(10);
}

void lcdWriteData(unsigned char data)
{
lcdSetPinout(RS); // Set RS to Data
lcdSetValue(data >> 4); // Upper nibble
lcdTriggerEN();
lcdSetValue(data); // Lower nibble
lcdTriggerEN();
delay_us(50); // Delay > 47 us
}

void lcdWriteCmd(unsigned char cmd)
{
lcdClrPinout(RS); // Set RS to Cmd
lcdSetValue(cmd >> 4); // Upper nibble
lcdTriggerEN();
lcdSetValue(cmd); // Lower nibble
lcdTriggerEN();
delay_ms(5); // Delay > 1.5ms
}




/*****************************************************************/
/********* GLOBAL FUNCTIONS *********/
/*****************************************************************/

/*
*
*/
void LCD_PortConfig(void)
{
// Direction
lcdDirPinout(D0);
lcdDirPinout(D1);
lcdDirPinout(D2);
lcdDirPinout(D3);
lcdDirPinout(EN);
lcdDirPinout(RS);
}


/*
*
*/
void LCD_Initialize(void)
{
delay_ms(100);
P2OUT = 0x03; // Start LCD (send 0x03)
lcdTriggerEN(); // Send 0x03 3 times at 5ms then 100 us
delay_ms(5);
lcdTriggerEN();
delay_ms(5);
lcdTriggerEN();
delay_ms(5);

P2OUT = 0x02; // Switch to 4-bit mode
lcdTriggerEN();
delay_ms(5);

lcdWriteCmd(0x28); // 4-bit, 2 line, 5x8
lcdWriteCmd(0x08); // Instruction Flow
lcdWriteCmd(0x01); // Clear LCD
lcdWriteCmd(0x06); // Auto-Increment
lcdWriteCmd(0x0C); // Display On, No blink
}


void LCD_SetText(char* text, int x, int y){
unsigned int i;

if (x < 16) {
x |= 0x80; // Set LCD for first line write
switch (y){
case 1:
x |= 0x40; // Set LCD for second line write
break;
case 2:
x |= 0x60; // Set LCD for first line write reverse
break;
case 3:
x |= 0x20; // Set LCD for second line write reverse
break;
}
lcdWriteCmd(x);
}

i = 0;
while (text[i] != '\0') {
lcdWriteData(text[i]);
i++;
}
}

void LCD_SetInt(int val, int x, int y)
{
char number_string[16];

sprintf(number_string, "%d", val); // Convert the integer to character string
LCD_SetText(number_string, x, y);
}

void LCD_Clear()
{
lcdWriteCmd(CLEAR);
}






/*****************************************************************/
/********* END *********/
/*****************************************************************/


Link to post
Share on other sites

I wrote this method as an extension on Energia's LCD module. You can use it in here as well. Though the Energia interface is not available, I rewrote this code for your purpose:

void LCD_SetCharacter(unsigned char index, const unsigned char bitmap[8])
{
    unsigned short iter;
    
    lcdWriteCmd(0x38);
    lcdWriteCmd(0x40 | (index << 3) & 0x3f);
    for(iter = 0; iter != 8; ++iter)
    {
        lcdWriteData(bitmap[iter]);
    }
    lcdWriteCmd(0x02);
}

Usage would be as such:

LCD_SetCharacter(1, corazon);

This would load the heart symbol in character 1.

This is only needed during setup, after pin assignment and LCD reset.

Now you can write to the screen as before

LCD_SetText("I \x01 MSP430", 0, 0); // print "I [heart] MSP430"

Note that \x00, \x01, \x02... \x07 will corresond with the characters you loaded.

\x00 is also the end-of-string marker, so when writing to the display you should replace it with \x08, but not when writing to character memory!

Link to post
Share on other sites

roadrunner84, thanks for your support

So I don't understand a thing, when you write:

LCD_SetCharacter(1,corazon)

you give a position to each of the symbols?

this way can initially assign each of the positions in lcd.c, like this:

LCD_SetCharacter(1,vazio)LCD_SetCharacter(2,coraz
Link to post
Share on other sites

Well, then you made an error. Because corazon is definitely defined in your LCD control code above.

Maybe you did put corazon[] in your library while you call LCD_SetCharacter() from your application.

It would make sense to either "hardcode" your special characters in the library (not my preferred option), or to define the special characters in your application and configure your LCD from there.

Link to post
Share on other sites

So you tell me to do the following:

 

In lcd.c

void LCD_SetCharacter(unsigned char index, const unsigned char bitmap[8])
{
    unsigned short iter;
    
    lcdWriteCmd(0x38);
    lcdWriteCmd(0x40 | (index << 3) & 0x3f);
    for(iter = 0; iter != 8; ++iter)
    {
        lcdWriteData(bitmap[iter]);
    }
    lcdWriteCmd(0x02);
}

in lcd.h

/*****************************************************************/
/********* CUSTOM                                        *********/
/*****************************************************************/

const unsigned char vazio[]  = {0x0,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const unsigned char corazon[]= {0x00,0xa,0x1f,0x1f,0xe,0x4,0x00,0x00};
const unsigned char bat_100[]= {0x4,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_75[] = {0x4,0x1b,0x11,0x1f,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_50[] = {0x4,0x1b,0x11,0x11,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_25[] = {0x4,0x1b,0x11,0x11,0x11,0x11,0x1f,0x1f};
const unsigned char bat_0[]  = {0x4,0x1b,0x11,0x11,0x11,0x11,0x11,0x1f};
/*****************************************************************/
/********* FUNCTION                                      *********/
/*****************************************************************/

void LCD_SetCharacter();

And in main.c

...void main(){LCD_SetCharacter(1, coraz
Link to post
Share on other sites

main.c:

void main()
{
  LCD_PortConfig();
  LCD_Initialize();
  LCD_SetCharacter(1, corazon);
  LCD_SetText("I \x01 MSP430",0,0);
}

font.h:

/*****************************************************************/
/********* CUSTOM                                        *********/
/*****************************************************************/

const unsigned char vazio[]  = {0x0,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const unsigned char corazon[]= {0x00,0xa,0x1f,0x1f,0xe,0x4,0x00,0x00};
const unsigned char bat_100[]= {0x4,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_75[] = {0x4,0x1b,0x11,0x1f,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_50[] = {0x4,0x1b,0x11,0x11,0x1f,0x1f,0x1f,0x1f};
const unsigned char bat_25[] = {0x4,0x1b,0x11,0x11,0x11,0x11,0x1f,0x1f};
const unsigned char bat_0[]  = {0x4,0x1b,0x11,0x11,0x11,0x11,0x11,0x1f};

the character bitmaps are related to your application, not to the LCD library. Also, make sure to use corazon, not coraz

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...