MSP430G2452 problem with displaying text on DOGXL160-7

Thread Starter

toann

Joined Nov 15, 2017
3
Hello,
I'm working on program for displaying numbers on graphic LCD DOGXL160-7 through I2C on microcontroller MSP430g2452. I2C bus is working properly, I am able to set all pixels on the display or reset display, but I can't write anything specific, like numbers. Can you please help?

In main function writeStringLCD is being called like: writeStringLCD(10, 50, "123", &status). And the display.c code is:
C:
#include "display.h"
#include"usi_i2c.h"
#include<stdint.h>
#include <msp430.h>

const unsigned char fonts[] = { /* USCI Font Table 7x5 Font Size */0x00, 0x00,
        0x00, 0x00, 0x00, /* Each Row describes a 7x5 Font */
        0x00, 0x00, 0x00, 0x00, 0x00, /* Each element in a row describes 7 (8) Column Pixels */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00,
        0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFE, 0x00,
        0x00, 0xFE, 0xFE, 0xFE, 0xFE, 0x00, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0x00,
        0xFE, 0xFE, 0xFE, 0xFE, 0x00, 0x00, 0xFE, 0xFE, 0xFE, 0x00, 0x00, 0x00,
        0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x06, 0x0E, 0xFC, 0x40, 0x38,
        0xC0, 0xCC, 0x12, 0x12, 0x12, 0xC0, 0xDE, 0x14, 0x14, 0x10, 0x20, 0x30,
        0x38, 0x30, 0x20, 0x00, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x10, 0x38, 0x7C,
        0x00, 0x08, 0x18, 0x38, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0xF2, 0x00, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0x28, 0xFE, 0x28,
        0xFE, 0x28, 0x24, 0x54, 0xFE, 0x54, 0x48, 0xC4, 0xC8, 0x10, 0x26, 0x46,
        0x6C, 0x92, 0xAA, 0x44, 0x0A, 0x00, 0xA0, 0xC0, 0x00, 0x00, 0x00, 0x38,
        0x44, 0x82, 0x00, 0x00, 0x82, 0x44, 0x38, 0x00, 0x28, 0x10, 0x7C, 0x10,
        0x28, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x0A, 0x0C, 0x00, 0x00, 0x10,
        0x10, 0x10, 0x10, 0x10, 0x00, 0x06, 0x06, 0x00, 0x00, 0x04, 0x08, 0x10,
        0x20, 0x40, 0x7C, 0x8A, 0x92, 0xA2, 0x7C, 0x00, 0x42, 0xFE, 0x02, 0x00,
        0x42, 0x86, 0x8A, 0x92, 0x62, 0x84, 0x82, 0xA2, 0xD2, 0x8C, 0x18, 0x28,
        0x48, 0xFE, 0x08, 0xE4, 0xA2, 0xA2, 0xA2, 0x9C, 0x3C, 0x52, 0x92, 0x92,
        0x0C, 0x80, 0x8E, 0x90, 0xA0, 0xC0, 0x6C, 0x92, 0x92, 0x92, 0x6C, 0x60,
        0x92, 0x92, 0x94, 0x78, 0x00, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x6A, 0x6C,
        0x00, 0x00, 0x10, 0x28, 0x44, 0x82, 0x00, 0x28, 0x28, 0x28, 0x28, 0x28,
        0x00, 0x82, 0x44, 0x28, 0x10, 0x40, 0x80, 0x8A, 0x90, 0x60, 0x4C, 0x92,
        0x9E, 0x82, 0x7C, 0x7E, 0x88, 0x88, 0x88, 0x7E, 0xFE, 0x92, 0x92, 0x92,
        0x6C, 0x7C, 0x82, 0x82, 0x82, 0x44, 0xFE, 0x82, 0x82, 0x44, 0x38, 0xFE,
        0x92, 0x92, 0x92, 0x82, 0xFE, 0x90, 0x90, 0x90, 0x80, 0x7C, 0x82, 0x92,
        0x92, 0x5E, 0xFE, 0x10, 0x10, 0x10, 0xFE, 0x00, 0x82, 0xFE, 0x82, 0x00,
        0x04, 0x02, 0x82, 0xFC, 0x80, 0xFE, 0x10, 0x28, 0x44, 0x82, 0xFE, 0x02,
        0x02, 0x02, 0x02, 0xFE, 0x40, 0x30, 0x40, 0xFE, 0xFE, 0x20, 0x10, 0x08,
        0xFE, 0x7C, 0x82, 0x82, 0x82, 0x7C, 0xFE, 0x90, 0x90, 0x90, 0x60, 0x7C,
        0x82, 0x8A, 0x84, 0x7A, 0xFE, 0x90, 0x98, 0x94, 0x62, 0x62, 0x92, 0x92,
        0x92, 0x8C, 0x80, 0x80, 0xFE, 0x80, 0x80, 0xFC, 0x02, 0x02, 0x02, 0xFC,
        0xF8, 0x04, 0x02, 0x04, 0xF8, 0xFC, 0x02, 0x1C, 0x02, 0xFC, 0xC6, 0x28,
        0x10, 0x28, 0xC6, 0xE0, 0x10, 0x0E, 0x10, 0xE0, 0x86, 0x8A, 0x92, 0xA2,
        0xC2, 0x00, 0xFE, 0x82, 0x82, 0x00, 0xA8, 0x68, 0x3E, 0x68, 0xA8, 0x00,
        0x82, 0x82, 0xFE, 0x00, 0x20, 0x40, 0x80, 0x40, 0x20, 0x02, 0x02, 0x02,
        0x02, 0x02, 0x00, 0x80, 0x40, 0x20, 0x00, 0x04, 0x2A, 0x2A, 0x2A, 0x1E,
        0xFE, 0x0A, 0x12, 0x12, 0x0C, 0x1C, 0x22, 0x22, 0x22, 0x04, 0x0C, 0x12,
        0x12, 0x0A, 0xFE, 0x1C, 0x2A, 0x2A, 0x2A, 0x18, 0x10, 0x7E, 0x90, 0x80,
        0x40, 0x30, 0x4A, 0x4A, 0x4A, 0x7C, 0xFE, 0x10, 0x20, 0x20, 0x1E, 0x00,
        0x00, 0x5E, 0x00, 0x00, 0x04, 0x02, 0x22, 0xBC, 0x00, 0xFE, 0x08, 0x14,
        0x22, 0x00, 0x00, 0x82, 0xFE, 0x02, 0x00, 0x3E, 0x20, 0x18, 0x20, 0x1E,
        0x3E, 0x10, 0x20, 0x20, 0x1E, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x3E, 0x28,
        0x28, 0x28, 0x10, 0x10, 0x28, 0x28, 0x18, 0x3E, 0x3E, 0x10, 0x20, 0x20,
        0x10, 0x12, 0x2A, 0x2A, 0x2A, 0x04, 0x20, 0xFC, 0x22, 0x02, 0x04, 0x3C,
        0x02, 0x02, 0x04, 0x3E, 0x38, 0x04, 0x02, 0x04, 0x38, 0x3C, 0x02, 0x0C,
        0x02, 0x3C, 0x22, 0x14, 0x08, 0x14, 0x22, 0x30, 0x0A, 0x0A, 0x0A, 0x3C,
        0x22, 0x26, 0x2A, 0x32, 0x22, 0x00, 0x10, 0x6C, 0x82, 0x00, 0x00, 0x00,
        0xFE, 0x00, 0x00, 0x00, 0x82, 0x6C, 0x10, 0x00, 0x10, 0x10, 0x54, 0x38,
        0x10, 0x10, 0x38, 0x54, 0x10, 0x10, 0x0E, 0x94, 0x24, 0x94, 0x0E, 0x0E,
        0x14, 0xA4, 0x14, 0x0E, 0x0E, 0x54, 0xA4, 0x54, 0x0E, 0x04, 0x2A, 0x6A,
        0xAA, 0x1E, 0x04, 0x2A, 0xAA, 0x2A, 0x1E, 0xFE, 0xFE, 0x92, 0x92, 0x92,
        0xBC, 0x42, 0x42, 0x42, 0xBC, 0x0C, 0x52, 0x12, 0x52, 0x0C, 0x3A, 0x4C,
        0x54, 0x64, 0xB8, 0x18, 0x26, 0x3C, 0x64, 0x18, 0xBC, 0x02, 0x02, 0x02,
        0xBC, 0x1C, 0x42, 0x02, 0x44, 0x1E, 0x40, 0x20, 0x10, 0x08, 0x04, 0x2A,
        0x2C, 0x38, 0x68, 0xA8, 0x30, 0x40, 0x30, 0x08, 0x30, 0x52, 0xAA, 0xAA,
        0xAA, 0x94, 0x7E, 0x90, 0xFE, 0x90, 0x90, 0x2C, 0x2A, 0x1C, 0x2A, 0x1A,
        0x12, 0x7E, 0x92, 0x92, 0x42, 0xFE, 0xA0, 0xA8, 0x5E, 0x0A, 0x38, 0x7C,
        0x7C, 0x7C, 0x38, 0x38, 0x44, 0x44, 0x44, 0x38, 0x10, 0x38, 0x7C, 0x38,
        0x10, 0x10, 0x28, 0x44, 0x28, 0x10, 0x00, 0x00, 0xEE, 0x00, 0x00, 0x70,
        0x8A, 0x8C, 0x88, 0x88, 0x06, 0x0A, 0x12, 0x22, 0x7E, 0x02, 0x22, 0x52,
        0x8A, 0x02, 0x02, 0x8A, 0x52, 0x22, 0x02, 0x08, 0x1C, 0x2A, 0x08, 0xF8,
        0x20, 0x40, 0xFE, 0x40, 0x20, 0x08, 0x04, 0xFE, 0x04, 0x08, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x0E, 0x0A, 0x0E, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x80,
        0x80, 0x02, 0x02, 0x1E, 0x00, 0x00, 0x08, 0x04, 0x02, 0x00, 0x00, 0x00,
        0x18, 0x18, 0x00, 0x00, 0x50, 0x50, 0x52, 0x54, 0x78, 0x20, 0x22, 0x2C,
        0x28, 0x30, 0x04, 0x08, 0x1E, 0x20, 0x00, 0x18, 0x10, 0x32, 0x12, 0x1C,
        0x12, 0x12, 0x1E, 0x12, 0x12, 0x12, 0x14, 0x18, 0x3E, 0x10, 0x10, 0x3E,
        0x10, 0x14, 0x18, 0x02, 0x12, 0x12, 0x1E, 0x02, 0x2A, 0x2A, 0x2A, 0x3E,
        0x00, 0x18, 0x00, 0x1A, 0x02, 0x1C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x80,
        0x82, 0xBC, 0x90, 0xE0, 0x08, 0x10, 0x3E, 0x40, 0x80, 0x70, 0x40, 0xC2,
        0x44, 0x78, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x44, 0x48, 0x50, 0xFE, 0x40,
        0x42, 0xFC, 0x40, 0x42, 0x7C, 0x50, 0x50, 0xFE, 0x50, 0x50, 0x10, 0x62,
        0x42, 0x44, 0x78, 0x20, 0xC0, 0x42, 0x7C, 0x40, 0x42, 0x42, 0x42, 0x42,
        0x7E, 0x40, 0xF2, 0x44, 0xF8, 0x40, 0x52, 0x52, 0x02, 0x04, 0x38, 0x42,
        0x44, 0x48, 0x54, 0x62, 0x40, 0xFC, 0x42, 0x52, 0x62, 0x60, 0x12, 0x02,
        0x04, 0x78, 0x10, 0x62, 0x52, 0x4C, 0x78, 0x50, 0x52, 0x7C, 0x90, 0x10,
        0x70, 0x00, 0x72, 0x04, 0x78, 0x20, 0xA2, 0xBC, 0xA0, 0x20, 0x00, 0xFE,
        0x10, 0x08, 0x00, 0x22, 0x24, 0xF8, 0x20, 0x20, 0x02, 0x42, 0x42, 0x42,
        0x02, 0x42, 0x54, 0x48, 0x54, 0x60, 0x44, 0x48, 0xDE, 0x68, 0x44, 0x00,
        0x02, 0x04, 0xF8, 0x00, 0x1E, 0x00, 0x40, 0x20, 0x1E, 0xFC, 0x22, 0x22,
        0x22, 0x22, 0x40, 0x42, 0x42, 0x44, 0x78, 0x20, 0x40, 0x20, 0x10, 0x0C,
        0x4C, 0x40, 0xFE, 0x40, 0x4C, 0x40, 0x48, 0x44, 0x4A, 0x70, 0x00, 0x54,
        0x54, 0x54, 0x02, 0x1C, 0x24, 0x44, 0x04, 0x0E, 0x02, 0x14, 0x08, 0x14,
        0x60, 0x50, 0x7C, 0x52, 0x52, 0x52, 0x20, 0xFE, 0x20, 0x28, 0x30, 0x02,
        0x42, 0x42, 0x7E, 0x02, 0x52, 0x52, 0x52, 0x52, 0x7E, 0x20, 0xA0, 0xA2,
        0xA4, 0x38, 0xF0, 0x02, 0x04, 0xF8, 0x00, 0x3E, 0x00, 0x7E, 0x02, 0x0C,
        0x7E, 0x02, 0x04, 0x08, 0x10, 0x7E, 0x42, 0x42, 0x42, 0x7E, 0x70, 0x40,
        0x42, 0x44, 0x78, 0x42, 0x42, 0x02, 0x04, 0x18, 0x40, 0x20, 0x80, 0x40,
        0x00, 0xE0, 0xA0, 0xE0, 0x00, 0x00, 0x1C, 0x22, 0x12, 0x0C, 0x32, 0x04,
        0xAA, 0x2A, 0xAA, 0x1E, 0x3E, 0x54, 0x54, 0x54, 0x28, 0x14, 0x2A, 0x2A,
        0x22, 0x04, 0x7E, 0x08, 0x08, 0x10, 0x78, 0x1C, 0x22, 0x32, 0x2A, 0x24,
        0x1E, 0x28, 0x48, 0x48, 0x30, 0x10, 0x2A, 0x2A, 0x2A, 0x3C, 0x04, 0x02,
        0x3C, 0x20, 0x20, 0x40, 0x40, 0x00, 0xE0, 0x00, 0x04, 0x02, 0x22, 0xBC,
        0x00, 0xA0, 0x40, 0xA0, 0x00, 0x00, 0x18, 0x24, 0x7E, 0x24, 0x08, 0x28,
        0xFE, 0x2A, 0x02, 0x02, 0x3E, 0x90, 0xA0, 0xA0, 0x1E, 0x1C, 0xA2, 0x22,
        0xA2, 0x1C, 0x7E, 0x28, 0x48, 0x48, 0x30, 0x30, 0x48, 0x48, 0x28, 0x7E,
        0x3C, 0x52, 0x52, 0x52, 0x3C, 0x0C, 0x14, 0x08, 0x14, 0x18, 0x1A, 0x26,
        0x20, 0x26, 0x1A, 0x3C, 0x82, 0x02, 0x84, 0x3E, 0xC6, 0xAA, 0x92, 0x82,
        0x82, 0x22, 0x3C, 0x20, 0x3E, 0x22, 0xA2, 0x94, 0x88, 0x94, 0xA2, 0x30,
        0x0A, 0x0A, 0x0A, 0x3C, 0x28, 0x28, 0x3E, 0x28, 0x48, 0x22, 0x3C, 0x28,
        0x28, 0x2E, 0x3E, 0x28, 0x38, 0x28, 0x3E, 0x10, 0x10, 0x54, 0x10, 0x10,
        0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE };

uint16_t lcdInitMacro[] = { // DogXL160 Initialization Commands
        setComEndH, setComEndL, setLCDMappingControl, setScrollLineLSB,
                setScrollLineMSB, setPanelLoading, setLCDBiasRatio,
                setVbiasPotentiometerH, setVbiasPotentiometerL,
                setRAMAddressControl, setDisplayEnable };

void clearLCD(unsigned char *buffer);
void initLCD(unsigned char *buffer);
void allPixelsOnLCD(unsigned char *buffer);
void resetLCD(unsigned char *buffer);
void writeLCD(unsigned char row, unsigned char col, unsigned short f,
        unsigned char *buffer);
void writeStringLCD(unsigned char y, unsigned char x, char word[],
        unsigned char *buffer);
void sendDataLCD(uint16_t* SData, unsigned short i, unsigned char *buffer);
void setPageAddressLCD(unsigned char PA, unsigned char *buffer);
void setColumnAdressLCD(unsigned char CA, unsigned char *buffer);

/*
* Function for initiating LCD
* init - pointer to void that contains the initialized value
*/
void initLCD(unsigned char *buffer) {
    sendDataLCD(lcdInitMacro, 11, buffer);
}

/*
* Function for sending data to LCD through I2C
* unsigned char* SData-pointer to the Data to be written to the LCD
* uint i-number of the  Datas  to be written to the LCD
*/
void sendDataLCD(uint16_t* SData, unsigned short i, unsigned char *buffer) {

    i2c_send_sequence(SData, i, buffer, LPM0_BITS); //ok
}

/*
* Function for setting page address
* unsigned char PA-page Address of the LCD RAM memory to be written
*/
void setPageAddressLCD(unsigned char PA, unsigned char *buffer) {
    // static unsigned char const*suma=PA+pageAddress;
    //static const unsigned char sum=PA+pageAddress;

    //sum = (uint16_t) (PA + pageAddress);
    uint16_t command[] = { pageAddress };
    command[0] += PA;
    // uint16_t Cmd[]={PA+pageAddress};                                                                                             //ok
    // uint16_t Cmd={(uint16_t)(PA+pageAddress)};
    //&Cmd[0]=sum; //PA+pageAddress ; Page Address Command = Page Address Initial Command + Page Address
    sendDataLCD(command, 1, buffer);
}

/*
* Function for setting column address of LCD RAM memory
* unsigned char CA-column Address of the LCD RAM memory to be written
*/
void setColumnAdressLCD(unsigned char CA, unsigned char *buffer) {
    unsigned char H = 0x00, L = 0x00;
    uint16_t columnAddress[] = { 0x78, columnLSB0, columnMSB0 };
    L = (CA & 0x0F); //separate Command Address to low and high
    H = (CA & 0xF0);
    H = (H >> 4);
    columnAddress[1] = (columnLSB0 + L); //column address CommandLSB = Column Address Initial Command
                                        //+column address bits 0..3
    columnAddress[2] = (columnMSB0 + H); //column address CommandMSB = Column Address Initial Command
                                        //+column address bits 4..7
    sendDataLCD(columnAddress, 3, buffer);
}

/*
* Function for setting all pixels on
*/
void allPixelsOnLCD(unsigned char *buffer) {
    uint16_t Cmd[] = { 0x78, setAllPixelsOn };
    sendDataLCD(Cmd, 2, buffer);
}

/*
* Function for resetting system
*/
void resetLCD(unsigned char *buffer) {
    uint16_t Cmd[] = { 0x78, systemReset };
    sendDataLCD(Cmd, 2, buffer);
}

/*
* Function for setting all pixels off
*/
void clearLCD(unsigned char *buffer) {
    uint16_t lcdData[] = { 0x78, 0x00 };
    unsigned char p = 0, c;
    for (p = 26; p > 0; p--) { //25 pages
        for (c = 160; c > 0; c--) { //160 columns
            setPageAddressLCD(0x00 + p, buffer);
            setColumnAdressLCD(0x00 + c, buffer);
            sendDataLCD(lcdData, 2, buffer);
        }
    }
}

/*
* Function for writing fonts from array to LCD
*
* unsigned char row-page Address
* unsigned char col-column Address
* unsigned short f-pointer to the font to be written to the LCD
*/
void writeLCD(unsigned char row, unsigned char col, unsigned short f,
        unsigned char *buffer) { //each font consists of 5 columns of 2 pages
    //each page presents 4 pixels
    uint16_t lcdData[3]; //pointer to the both pages of a column
    uint16_t* ptr;
    unsigned char H = 0x00, L = 0x00, c;
    for (c = 0; c < 5; c++) { //font block size 5 columns
        L = (fonts[f + c] & 0x0F); //LSB 4 pixels are saved to L
        H = (fonts[f + c] & 0xF0); //MSB 4 pixels are saved to H
        H = (H >> 4);
        lcdData[1] = 0x00;
        lcdData[2] = 0x00;
        if ((H & 0x01) == 0x01) { //each pixel in the H is converted to 2 bits, 11 pixel on - 00 pixel off
            lcdData[1] = lcdData[1] + 0xC0;
        };
        if ((H & 0x02) == 0x02) {
            lcdData[1] = lcdData[1] + 0x30;
        };
        if ((H & 0x04) == 0x04) {
            lcdData[1] = lcdData[1] + 0x0C;
        };
        if ((H & 0x08) == 0x08) {
            lcdData[1] = lcdData[1] + 0x03;
        };
        if ((L & 0x01) == 0x01) { //each pixel in the L is converted to 2 bits,  11 pixel on - 00 pixel off
            lcdData[2] = lcdData[2] + 0xC0;
        };
        if ((L & 0x02) == 0x02) {
            lcdData[2] = lcdData[2] + 0x30;
        };
        if ((L & 0x04) == 0x04) {
            lcdData[2] = lcdData[2] + 0x0C;
        };
        if ((L & 0x08) == 0x08) {
            lcdData[2] = lcdData[2] + 0x03;
        };
        unsigned char p;
        uint16_t probne[]={0x78,0x10, 0x14, 0x18, 0x02};
        for (p = 0; p < 2; p++) { //font page size 2 pages
            ptr = lcdData + p;
            setPageAddressLCD(0x00 + p + row, buffer);
            setColumnAdressLCD(0x00 + c + col, buffer);
            sendDataLCD(ptr, 1, buffer); //column that consists of two pages is sent to the LCD
        }
    }
}

/*
* Function for writing String to LCD
*
* unsigned char y-page address
* unsigned char x-column address
* char world[]-pointer to the String to be written to the LCD
*/
void writeStringLCD(unsigned char y, unsigned char x, char word[],
        unsigned char *buffer) {
    unsigned char k, a = 0;
    do { //writes a font to a block of 8x5 Pixels
        k = word[a];
        writeLCD(y, x, 5 * k, buffer);
        x = x + 6; //points to the next Block
        a++;
        k = word[a];
    } while (k != 0); //writes until the end of the String
}
Mod edit: code tags
 
Last edited by a moderator:

Thread Starter

toann

Joined Nov 15, 2017
3
just some random pixels show up, probably after initialisation, few hours ago number of pixels increased when the sentence lenght increased, currently I don't think it has influence of pixel amount
 

Thread Starter

toann

Joined Nov 15, 2017
3
Okay, my mistake was I was writing to address for "write command", not "write data" during writing datas. I am now able to display lines but writing numbers still doesn't work, even though the address is correct. When I try to display something else than lines, nothing happens.
 
Top