Displaying bitmaps on MSP-EXP430F5438

I have been planning to implement some games on the MSP430F5438 Experimenters Board that i have. So my first stop is to learn what the library has to provide. In this post i will tell you how to display bitmaps.After that i will probably implement Conway’s game of life and then i might start writing code for a game.
Video demo –
For starters you will have to download the msp430 graphics library from Ti’s website.
We need to understand that we can display only black and white images . I have a feeling that grey-scale images can also be displayed but as of now i have not tried that.
To display images either you can use the “image-reformer” tool that comes with the library or write a function in which you mention the state of each and every pixel.

Number of colors Bits needed
2 color bitmap 1 bit
4 color bitmap 2 bit
16 color bitmap 4 bit
256 color bitmap 8 bit

But you must understand that although the image-reformer tool is capable of generating proper files for colored images too but the LCD is capable of displaying only greyscale images… so a 256 color bitmap of looks like this but on the LCD looks like this .
Screenshot (38)

 

 

 

This is what the bit map of the same image looks like with different color/bit settings –

Screenshot (36)

Screenshot (37)
Screenshot (38)
There is almost no difference between images of different settings. So i would recommend to go for the 2 color bitmap as it loads the fastest (the higher the number of bits, the slower it gets to load and display the image on the screen).
Here is hackaday logo on 2 bit and 1 bit setting (no difference apparently) –
DSC02270
DSC02269
Now if u are an expert in using CCS then its alright , u already know what to do and how to open the example etc.
But if you are a noob like me then its extremely difficult to get all the correct files by creating a New Project, so as a work around follow these steps –
1. Import the extracted folder into your workspace.
2. Right click on “MSP-EXP430F5438_Grlib_Example” folder and paste it there it self(just do Ctrl+V). Screenshot (41) 3. A dialogue box will open up asking you to fill some particulars…. better change the name of the project, in my case it is “My_msp430f5438_grlib_trial”.
4. Now you are ready to change the “main.c” and other files in your project.

Now select the images that you want to display and rename them properly…. this step is necessary as the image reformer tool will name your variables and constants accordingly in the file that it creates. Then execute the image reformer tool by clicking on the gear icon and the files will be stored wherever u want it to.

After that u need to bring those files to the “images” folder in the folder that you created when you were copying the existing example from the workspace.

Then you need to add some additional lines in the “image.h” file in the images folder. Those lines are just initializations of the image files that you copied. For e.g: Before editing it looked something like this –

#include "grlib.h"

#ifndef __IMAGES_H__
#define __IMAGES_H__

//*****************************************************************************
//
// Prototypes for the image arrays.
//
//*****************************************************************************
extern const Graphics_Image LPRocket_130x50_1BPP_UNCOMP;
extern const Graphics_Image TI_Logo_107x100_1BPP_UNCOMP;

#endif // __IMAGES_H__

After editing this is what it looks like –

<pre>#include "grlib.h"

#ifndef __IMAGES_H__
#define __IMAGES_H__

//*****************************************************************************
//
// Prototypes for the image arrays.
//
//*****************************************************************************
extern const Graphics_Image LPRocket_130x50_1BPP_UNCOMP;
extern const Graphics_Image TI_Logo_107x100_1BPP_UNCOMP;
extern const Graphics_Image flame1BPP_UNCOMP;
extern const Graphics_Image hack1BPP_COMP_RLE4;
extern const Graphics_Image hack_a1BPP_UNCOMP;
extern const Graphics_Image pic1BPP_UNCOMP;
extern const Graphics_Image rev1BPP_UNCOMP;
extern const Graphics_Image nodejs1BPP_UNCOMP;
extern const Graphics_Image nordic2BPP_UNCOMP;
extern const Graphics_Image nrf1BPP_UNCOMP;
extern const Graphics_Image ti1BPP_UNCOMP;
#endif // __IMAGES_H__

[The correct names to be copied to the images.h file can be found from the files that were generated after you clicked on the gear button of the image reformer tool.]

Now you need to edit the main.c file….This is what it looks like– i encourage you to find out the differences yourself and understand how i added the extra code.



#include "grlib.h"
#include "radioButton.h"
#include "checkbox.h"
#include "LcdDriver/Hitachi138x110_HD66753.h"
#include "LcdDriver/HAL_MSP_EXP430F5438_HITACHI138x110_HD66753.h"
#include "images/images.h"
#include "driverlib.h"

Graphics_Context g_sContext;
int32_t stringWidth = 0;

void boardInit(void);
void clockInit();
void Delay(void);


/**********************************************************************//**
 * @brief  This is the example code's main function.
 *
 * @param  none
 *
 * @return none
 *************************************************************************/

void main(void)
{
    // Basic GPIO Initialization
    boardInit();
    clockInit();

    // Set up LCD
    Hitachi138x110_HD66753_initDisplay();
    Graphics_initContext(&g_sContext, &g_sHitachi138x110_HD66753);
    Graphics_setForegroundColor(&g_sContext, ClrBlack);
    Graphics_setBackgroundColor(&g_sContext, ClrWhite);
    Graphics_setFont(&g_sContext, &g_sFontCmss12b);
    Graphics_clearDisplay(&g_sContext);

    //**********************************************
    //***************** Note ***********************
    //**********************************************
    // This LCD display has adjustable contrast.
    // The default contrast setting likely needs
    // adjustment for optimal performance.
    //**********************************************
    Hitachi138x110_HD66753_setContrast(110);
    Hitachi138x110_HD66753_setBacklight(2);

    // Intro Screen
    Graphics_drawStringCentered(&g_sContext,
                                "By",
                                AUTO_STRING_LENGTH,
                                69,
                                27,
                                TRANSPARENT_TEXT);
    Graphics_drawStringCentered(&g_sContext,
                                "SHANTAM RAJ",
                                AUTO_STRING_LENGTH,
                                69,
                                54,
                                TRANSPARENT_TEXT);
    Graphics_drawStringCentered(&g_sContext,
                                "ECE, IIT Ghy",
                                AUTO_STRING_LENGTH,
                                69,
                                81,
                                TRANSPARENT_TEXT);
    Delay();

    Graphics_clearDisplay(&g_sContext);
    // Draw Images on the display
    Graphics_drawImage(&g_sContext, &LPRocket_130x50_1BPP_UNCOMP, 4, 30);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &TI_Logo_107x100_1BPP_UNCOMP, 15, 5);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &flame1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &rev1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &hack1BPP_COMP_RLE4, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &hack_a1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &pic1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &nodejs1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &nordic2BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &nrf1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    Graphics_drawImage(&g_sContext, &ti1BPP_UNCOMP, 0, 0);
    Delay();
    Graphics_clearDisplay(&g_sContext);

    while(1)
    {
        Graphics_drawStringCentered(&g_sContext,
                                            "Thats it folks !!",
                                            AUTO_STRING_LENGTH,
                                            69,
                                            27,
                                            TRANSPARENT_TEXT);
    }
}

void boardInit(void)
{
    //Tie unused ports
    GPIO_setAsOutputPin(
        GPIO_PORT_PA,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PA,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_PB,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PB,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_PC,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PC,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_PD,
        GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 +
        GPIO_PIN6 + GPIO_PIN7 + GPIO_PIN8 + GPIO_PIN9 +
        GPIO_PIN10 + GPIO_PIN11 + GPIO_PIN12 + GPIO_PIN13 +
        GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsPeripheralModuleFunctionOutputPin(
        GPIO_PORT_PD,
        GPIO_PIN0 + GPIO_PIN1
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PD,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    // P10.0 to USB RST pin,
    // ...if enabled with J5
    GPIO_setAsOutputPin(
        GPIO_PORT_P11,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 + GPIO_PIN12 +
        GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsInputPin(
        GPIO_PORT_PE,
        GPIO_PIN8
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PE,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_P11,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P11,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_PJ,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_PJ,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P6,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN7 +
        GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
        GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
        );

    GPIO_setOutputHighOnPin(
        GPIO_PORT_P6,
        GPIO_PIN6
        );

    // USB RX Pin, Input with
    // ...pulled down Resistor

    GPIO_setAsInputPinWithPullDownResistor(
        GPIO_PORT_P5,
        GPIO_PIN7
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P5,
        GPIO_PIN7
        );
}

void clockInit()
{
    UCS_setExternalClockSource(
        32768,
        0);

    UCS_turnOnLFXT1(
        UCS_XT1_DRIVE_3,
        UCS_XCAP_3
        );

    UCS_initFLLSettle(
        16000,
        488
        );

    SFR_enableInterrupt(
        SFR_OSCILLATOR_FAULT_INTERRUPT
        );
}

void Delay(void)
{
    __delay_cycles(SYSTEM_CLOCK_SPEED * 4);
}

#ifdef __ICC430__
int16_t __low_level_init(void) {
    WDT_A_hold(WDT_A_BASE); // Stop WDT (Watch Dog Timer)
    return(1);
}

#endif

After this you build the project and Debug it and then Run it to see the magic !!

Advertisements

About Shantam Raj

Currently I am a final year B.Tech undergraduate majoring in “Electronics and Communication Engineering” from IIT Guwahati. I am passionate about electronics and robotics. Apart from that I love writing, visit https://medium.com/@shantam_raj for some of my works. I am a die hard soccer fan. I also love to play badminton. I am a hardware hacking enthusiast and a tinkerer !!.
This entry was posted in MSP-EXP430F5438, MSP-EXP430F5438a, MSP430F5438 and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s