This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2553: MSP-EXP430G2 Emulation Board

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP430G2253

Tool/software: Code Composer Studio

Dear Buddy:

Current I did building LCD1602 Display by 4 bit.

But I met failure which it can not display anymore.

  1. MSP-EXP430G2 Emulation Board connect 12M crystal, not recommend 32768HZ. Whehter should remove R28/R29?
  2. LCD HW connection as below.

  /**********************************************************************

* LCD1602显示之高四位相连的方法
*
* 描述:4线数据宽度,操作Lcd1602
* 在LCD1602屏幕上第一行显示 Hello!LCD1602
* 第二行显示 MSP430G2553
* 硬件电路:MSP430g2553 20PINS
* 硬件连接:
* MSP430与LCD连接信息
* LCD1602,4位接口,即使用D4-D7数据口,D0-D3不接入MCU

* PIN1 --> 地
* PIN2 --> VCC(一定要接+5V)
* PIN3 -->仿真时悬空,实际电路 2K电阻-->地 (一定要接好,否则没有任何显示)
* PIN4 --> RS --> P1.6
* PIN5 --> R/W --> GND
* PIN6 --> EN --> P1.7
* PIN7 --> D0不接
* PIN8 --> D1不接
* PIN9 --> D2不接
* PIN10 --> D3不接
* PIN11 --> D4 --> P2.0
* PIN12 --> D5 --> P2.1
* PIN13 --> D6 --> P2.2
* PIN14 --> D7 --> P2.3
* PIN15 --> floating
* PIN16 --> floating
* 调试器:MSP-EXP430G2 Emulation Board USB 12M,not 32768 Hz
* 调试软件: CCS9.3 编译
*****************************************************************/
#include <intrinsics.h>
#include <msp430g2253.h>
#include <msp430.h>
/*****************************************************

  • Hello Mike,

    In future posts, please post your code using the Syntax Highlighter.

    Mike Jin said:
    But I met failure which it can not display anymore.

    So the LCD display was working? Do you remember what you changed before it quit working?

    Mike Jin said:
    MSP-EXP430G2 Emulation Board connect 12M crystal, not recommend 32768HZ. Whehter should remove R28/R29?

    Did you populate a 12 MHz crystal at Q2 for XT1 on the MSP-EXP430G2? Please keep in mind that XT1 can only support up to 50 kHz.

    Mike Jin said:
    LCD HW connection as below.

    I don't see the VO connection. This controls the contrast, so it may be possible the LCD is working correctly, but you can't see anything due to the wrong contrast.

    I found several resources related to this project for your reference.

    http://wiki.sunfounder.cc/index.php?title=LCD1602_Module

    https://circuitdigest.com/microcontroller-projects/interfacing-lcd-with-msp430

    https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/197064?16x2-lcd-in-4bit-mode-for-msp430g2553

    Regards,

    James

  • Dear James:

    Thank you for your stronger support!

    1. On my hand only have 12M crystal, so I must replace it by 32768HZ at XIN and XOUT. Is it right? (Emulation MSP-EXP430G  Rev.1.4  board.)
    2. LCD1602 pin3 VO connect 2Kohm R to GND.
    3. Attached code for your checking.
      LCD1602 Code MSP430G2553.txt
      /*********************************************************************
      *
      * LCD1602 Dispaly by 4 bit
      *
      * ����:4�����ݿ�ȣ�����Lcd1602
      * LCD1602 display the first line:��Hello!LCD1602
      * The second line showing:��MSP430G2553
      * Device��MSP430g2553   20PINS
      * Ӳ�����ӣ�
      * MSP430��LCD������Ϣ
      * LCD1602��4λ�ӿڣ���ʹ��D4-D7���ݿڣ�D0-D3������MCU
      
      * PIN1 --> GND
      * PIN2 --> VCC��һ��Ҫ��+5V��
      * PIN3 -->2Kohm-->GND;           ����ʱ���գ�ʵ�ʵ�· 2K����-->�� (һ��Ҫ�Ӻã�����û���κ���ʾ)
      *
      * PIN4 --> RS --> P1.6
      * PIN5 --> R/W --> GND
      * PIN6 --> EN --> P1.7
      *
      * PIN7 --> floating
      * PIN8 -->  floating
      * PIN9 -->  floating
      * PIN10 -->  floating
      *
      * PIN11 --> D4 --> P2.0
      * PIN12 --> D5 --> P2.1
      * PIN13 --> D6 --> P2.2
      * PIN14 --> D7 --> P2.3
      * PIN15 --> floating
      * PIN16 --> floating
      * ��������MSP-EXP430G2 Emulation Board USB  12M��not 32768 Hz
      * ��������� CCS9.3 ����
      *****************************************************************/
      #include <intrinsics.h>
      #include <msp430g2253.h>
      #include <msp430.h>
      /*****************************************************
      
                                                           �˿ڶ���
      
      ****************************************************/
      #define LCD_EN_PORT P1OUT    //����2��Ҫ��Ϊͬһ����
      #define LCD_EN_DDR P1DIR
      #define LCD_RS_PORT P1OUT    //����2��Ҫ��Ϊͬһ����
      #define LCD_RS_DDR P1DIR
      #define LCD_DATA_PORT P2OUT  //����3��Ҫ��Ϊͬһ����
      #define LCD_DATA_DDR P2DIR   //һ��Ҫ�ø�4λ
      #define LCD_RS BIT3
      #define LCD_EN BIT2
      #define LCD_DATA    BIT3|BIT2|BIT1|BIT0   //4λ����������ģʽ
      /***************************************************
      
                                                                Ԥ���庯��
      
      **************************************************/
      void LCD_init(void);
      void LCD_init_first(void);
      void LCD_en_write1(void);  //������ʹ��
      void LCD_en_write2(void);  //�½���ʹ��
      void LCD_write_command(unsigned char command);
      void LCD_write_data(unsigned char data);
      void LCD_set_xy (unsigned char x, unsigned char y);
      void LCD_write_string(unsigned char X,unsigned char Y, unsigned char *s);
      void LCD_write_char(unsigned char X,unsigned char Y, unsigned char data);
      void delay_1ms(void);
      void delay_nus(unsigned int n);
      void delay_nms(unsigned int n);
      unsigned char LCDBuf1[]={"Hello!LCD1602"};   //��һ��Ҫ��ʾ������
      unsigned char LCDBuf2[]={"MSP430G2553"};     //�ڶ���Ҫ��ʾ������
      
      /********************************************
      
                                                     ������
      
      *******************************************/
      
      void main()
      {
      WDTCTL = WDTPW + WDTHOLD;     // �رտ��Ź�
      LCD_init_first();
      LCD_init();
      delay_nms(100);
      LCD_write_string(0,0,LCDBuf1);
      delay_nms(10);
      LCD_write_string(0,1,LCDBuf2);
      }
      /********************************************
      
                  LCDҺ����������
      
      *******************************************/
      
      void LCD_init_first(void)         //LCD1602Һ����ʼ���������������
      {
              delay_nms(500);
           LCD_DATA_DDR|=LCD_DATA;   //���ݿڷ���Ϊ���
           LCD_EN_DDR|=LCD_EN;       //����EN�������
           LCD_RS_DDR|=LCD_RS;       //����RS�������
      
              delay_nms(50);
              LCD_write_command(0x30);
              delay_nms(50);
              LCD_write_command(0x30);
              delay_nms(5);
              LCD_write_command(0x30);
              delay_nms(500);
      
      }
      
      /*****************************************
      *
      *             LCD1602Һ����ʼ������
      *
      ****************************************/
      void LCD_init(void)
      {
      delay_nms(500);
      LCD_DATA_DDR|=LCD_DATA;   //���ݿڷ���Ϊ���
      LCD_EN_DDR|=LCD_EN;       //����EN�������
      LCD_RS_DDR|=LCD_RS;       //����RS�������
      
      delay_nms(500);
      
      LCD_write_command(0x28);  //4λ���ݽӿ�
      delay_nms(50);
      LCD_write_command(0x28);  //4λ���ݽӿ�
      delay_nms(50);
          LCD_write_command(0x28);  //4λ���ݽӿ�
      delay_nms(50);
          LCD_en_write2();
          delay_nms(50);
      LCD_write_command(0x28); //4λ���ݽӿ�
      delay_nms(500);
      LCD_write_command(0x01); //����
      LCD_write_command(0x0c); //��ʾ�����ع�꣬����˸
          LCD_write_command(0x06); //�趨���뷽ʽ����������λ
      delay_nms(50);
      
      
      }
      
      /*****************************************
      *
      *             Һ��ʹ��������
      *
      ****************************************/
      
      void LCD_en_write1(void)
      {
          LCD_EN_PORT&=~LCD_EN;
          delay_nus(10);
          LCD_EN_PORT|=LCD_EN;
      }
      
      /*****************************************
      *
      *             Һ��ʹ���½���
      *
      ****************************************/
      void LCD_en_write2(void)
      {
         LCD_EN_PORT|=LCD_EN;
         delay_nus(10);
         LCD_EN_PORT&=~LCD_EN;
      }
      
      /*****************************************
      *
      *               дָ���
      *
      ****************************************/
      void LCD_write_command(unsigned char command)
      {
         delay_nus(16);
         P2SEL=0x00;
         LCD_RS_PORT&=~LCD_RS; //RS=0
         LCD_en_write1();
         LCD_DATA_PORT&=0X0f; //�����λ
         LCD_DATA_PORT|=command&0xf0; //д����λ
      
         delay_nus(16);
         LCD_en_write2();
         command=command<<4; //����λ�Ƶ�����λ
         LCD_en_write1();
         LCD_DATA_PORT&=0x0f; //�����λ
         LCD_DATA_PORT|=command&0xf0; //д����λ
         LCD_en_write2();
      }
      
      /*****************************************
      *
      *               д���ݺ���
      *
      ****************************************/
      void LCD_write_data(unsigned char data)
      {
         delay_nus(16);
         P2SEL=0x00;
         LCD_RS_PORT|=LCD_RS;      //RS=1
         LCD_en_write1();          //E������
         LCD_DATA_PORT&=0X0f;      //�����λ
         LCD_DATA_PORT|=data&0xf0; //д����λ
         delay_nus(16);
         LCD_en_write2();
         data=data<<4;             //����λ�Ƶ�����λ
         LCD_en_write1();
         LCD_DATA_PORT&=0X0f;      //�����λ
         LCD_DATA_PORT|=data&0xf0; //д����λ
         LCD_en_write2();
      }
      
      /*****************************************
      *
      *               д��ַ����
      *
      ****************************************/
      void LCD_set_xy( unsigned char x, unsigned char y )
      {
         unsigned char address;
         if (y == 0) address = 0x80 + x;
         else address = 0xc0 + x;
         LCD_write_command( address);
      }
      
      /*****************************************
      *
      *LCD������λ��д�ַ�������x=0~15,��y=0,1
      *
      ****************************************/
      void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
      {
      LCD_set_xy( X, Y ); //д��ַ
          while (*s)          //д��ʾ�ַ�
          {
            LCD_write_data( *s );
            s++;
          }
      }
      
      /*****************************************
      *
      *     LCD������λ��д�ַ�,��x=0~15,��y=0,1
      *
      ****************************************/
      
      void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data)
      {
         LCD_set_xy( X, Y ); //д��ַ
         LCD_write_data( data);
      }
      
      /*****************************************
      *
      *               1us��ʱ����
      *
      ****************************************/
      
      void delay_1us(void)
      {
         asm("nop");
      }
      
      /*****************************************
      *
      *               N us��ʱ����
      *
      ****************************************/
      void delay_nus(unsigned int n)
      {
         unsigned int i;
         for (i=0;i<n;i++)
         delay_1us();
      }
      
      /*****************************************
      *
      *               1ms��ʱ����
      *
      ****************************************/
      void delay_1ms(void)
      {
         unsigned int i;
         for (i=0;i<1140;i++);
      }
      
      /*****************************************
      *
      *               N ms��ʱ����
      *
      ****************************************/
      void delay_nms(unsigned int n)
      {
         unsigned int i=0;
         for (i=0;i<n;i++)
         delay_1ms();
      }
      

  • Some comments for my study?

  • As James asked: When did this start failing?

    ---------------------------

    >#define LCD_DATA    BIT3|BIT2|BIT1|BIT0  

    >LCD_DATA_PORT|=command&0xf0; 

    This line writes 4-bits of command into bits 7-4, not bits 3-0. Try:

    >LCD_DATA_PORT|=(command&0xf0) >> 4;   // Half into P2.3-0

    ---------------------------

    >#define LCD_EN_PORT P1OUT 

    >#define LCD_EN BIT2

    P1.2 is used by the backchannel UART. Don't forget to remove the TXD/RXD jumpers from the "bridge" header (J3).

    ---------------------------

    >#define LCD_RS_PORT P1OUT

    >#define LCD_RS BIT3

    P1.3 is connected to button S1. On some revisions of the G2 Launchpad (I don't remember which ones) there's an external pullup resistor. You may want to check this and/or choose a diffferent pin.

     

  • Thank you very much!

    In the past days I bought  some 32.768KHZ crystals.and soldered it.

    Can you help to review pin define which is right?

    /*
    * LCD.c
    *
    * Created on: 2020年2月27日
    * Author: MikeJin
    */
    /*********************************************************************
    ** LCD1602 High 4 bits Connection Way, Not 8 bits.
    ** Description :4 wire line connect LCD1602
    * HW :MSP430g2553 20pins
    * HW Connection: MSP430 Connect LCD1602
    *
    * LCD1602,4bits,Using D4-D7 P2 Port,D0-D3 was floating
    * PIN1 VSS --> GND
    * PIN2 VDD --> VCC(+5V)
    * PIN3 V0 --> 2Kohm connect to GND
    * PIN4 RS --> pin14 P1.6
    * PIN5 R/W --> pin7 P1.5
    * PIN6 E --> pin15 P1.7
    * PIN7 D0 --> D0 was floating || * PIN8 D1 --> D1 was floating
    * PIN9 D2 --> D2 was floating || * PIN10 D3 --> D3 was floating
    * PIN11 D4 --> pin12 P2.4
    * PIN12 D5 --> pin13 P2.5
    * PIN13 D6 --> pin19 P2.6
    * PIN14 D7 --> pin18 P2.7
    * PIN15 BA --> VCC (5V)
    * PIN16 BK --> GND
    * Debugger:Emulation MSP-EXP430G2 Board
    * Development Software : CCS9.3 Composer
    *****************************************************************/

  • > PIN4 RS --> pin14 P1.6

    P1.6 is connect to LED2. Be sure to remove that jumper from J5

    > PIN11 D4 --> pin12 P2.4

    If you're moving the Dx to P2.4-7, you need to change to:

    >#define LCD_DATA    BIT7|BIT6|BIT5|BIT4

  • Dear Bruce:

    Thank you very much! But I just start to study MSP430G2553 20pin MCU.

    Current I installed 32.768KHZ between MCU pin19/18, and removed R28/29.

    Attached my code for your checking again. CCS9.3 run smoothly. But LCD1602 display nothing.

    Sample Code.txt
    /*********************************************************************
    *
    * LCD1602��ʾ֮����λ�����ķ���
    *
    * ����:4�����ݿ�ȣ�����Lcd1602
    * ��LCD1602��Ļ�ϵ�һ����ʾ��Hello!LCD1602
    * �ڶ�����ʾ��MSP430G2553
    * Ӳ����·��MSP430g2553
    * Ӳ�����ӣ�
    * MSP430��LCD������Ϣ
    * LCD1602��4λ�ӿڣ���ʹ��D4-D7���ݿڣ�D0-D3������MCU
    * PIN1 --> ��
    * PIN2 --> VCC��һ��Ҫ��+5V��
    * PIN3 -->����ʱ���գ�ʵ�ʵ�· 2K����-->�� (һ��Ҫ�Ӻã�����û���κ���ʾ)
    * PIN4 --> RS --> P1.6
    * PIN5 --> R/W --> GND
    * PIN6 --> EN --> P1.7
    * PIN7 --> D0����
    * PIN8 --> D1����
    * PIN9 --> D2����
    * PIN10 --> D3����
    * PIN11 --> D4 --> P2.4
    * PIN12 --> D5 --> P2.5
    * PIN13 --> D6 --> P2.6
    * PIN14 --> D7 --> P2.7
    * PIN15 --> VCC
    * PIN16 --> ��
    * ��������MSP430FETȫϵ��JTAG������
    * ��������� CCS5.1.1 ����
    *****************************************************************/
    #include <intrinsics.h>
    #include <msp430g2253.h>
    #include <msp430.h>
    /*****************************************************
    
                                                         �˿ڶ���
    
    ****************************************************/
    #define LCD_EN_PORT P1OUT    //����2��Ҫ��Ϊͬһ����
    #define LCD_EN_DDR P1DIR
    #define LCD_RS_PORT P1OUT    //����2��Ҫ��Ϊͬһ����
    #define LCD_RS_DDR P1DIR
    #define LCD_DATA_PORT P2OUT  //����3��Ҫ��Ϊͬһ����
    #define LCD_DATA_DDR P2DIR   //һ��Ҫ�ø�4λ
    #define LCD_RS BIT6
    #define LCD_EN BIT7
    #define LCD_DATA    BIT7|BIT6|BIT5|BIT4   //4λ����������ģʽ
    /***************************************************
    
                                                              Ԥ���庯��
    
    **************************************************/
    void LCD_init(void);
    void LCD_init_first(void);
    void LCD_en_write1(void);  //������ʹ��
    void LCD_en_write2(void);  //�½���ʹ��
    void LCD_write_command(unsigned char command);
    void LCD_write_data(unsigned char data);
    void LCD_set_xy (unsigned char x, unsigned char y);
    void LCD_write_string(unsigned char X,unsigned char Y, unsigned char *s);
    void LCD_write_char(unsigned char X,unsigned char Y, unsigned char data);
    void delay_1ms(void);
    void delay_nus(unsigned int n);
    void delay_nms(unsigned int n);
    unsigned char LCDBuf1[]={"Hello!LCD1602"};   //��һ��Ҫ��ʾ������
    unsigned char LCDBuf2[]={"MSP430G2553"};     //�ڶ���Ҫ��ʾ������
    
    /********************************************
    
                                                   ������
    
    *******************************************/
    
    void main()
    {
    WDTCTL = WDTPW + WDTHOLD;     // �رտ��Ź�
    LCD_init_first();
    LCD_init();
    delay_nms(100);
    LCD_write_string(0,0,LCDBuf1);
    delay_nms(10);
    LCD_write_string(0,1,LCDBuf2);
    }
    /********************************************
    
                LCDҺ����������
    
    *******************************************/
    
    void LCD_init_first(void)         //LCD1602Һ����ʼ���������������
    {
            delay_nms(500);
         LCD_DATA_DDR|=LCD_DATA;   //���ݿڷ���Ϊ���
         LCD_EN_DDR|=LCD_EN;       //����EN�������
         LCD_RS_DDR|=LCD_RS;       //����RS�������
    
            delay_nms(50);
            LCD_write_command(0x30);
            delay_nms(50);
            LCD_write_command(0x30);
            delay_nms(5);
            LCD_write_command(0x30);
            delay_nms(500);
    
    }
    
    /*****************************************
    *
    *             LCD1602Һ����ʼ������
    *
    ****************************************/
    void LCD_init(void)
    {
    delay_nms(500);
    LCD_DATA_DDR|=LCD_DATA;   //���ݿڷ���Ϊ���
    LCD_EN_DDR|=LCD_EN;       //����EN�������
    LCD_RS_DDR|=LCD_RS;       //����RS�������
    
    delay_nms(500);
    
    LCD_write_command(0x28);  //4λ���ݽӿ�
    delay_nms(50);
    LCD_write_command(0x28);  //4λ���ݽӿ�
    delay_nms(50);
        LCD_write_command(0x28);  //4λ���ݽӿ�
    delay_nms(50);
        LCD_en_write2();
        delay_nms(50);
    LCD_write_command(0x28); //4λ���ݽӿ�
    delay_nms(500);
    LCD_write_command(0x01); //����
    LCD_write_command(0x0c); //��ʾ�����ع�꣬����˸
        LCD_write_command(0x06); //�趨���뷽ʽ����������λ
    delay_nms(50);
    
    
    }
    
    /*****************************************
    *
    *             Һ��ʹ��������
    *
    ****************************************/
    
    void LCD_en_write1(void)
    {
        LCD_EN_PORT&=~LCD_EN;
        delay_nus(10);
        LCD_EN_PORT|=LCD_EN;
    }
    
    /*****************************************
    *
    *             Һ��ʹ���½���
    *
    ****************************************/
    void LCD_en_write2(void)
    {
       LCD_EN_PORT|=LCD_EN;
       delay_nus(10);
       LCD_EN_PORT&=~LCD_EN;
    }
    
    /*****************************************
    *
    *               дָ���
    *
    ****************************************/
    void LCD_write_command(unsigned char command)
    {
       delay_nus(16);
       P2SEL=0x00;
       LCD_RS_PORT&=~LCD_RS; //RS=0
       LCD_en_write1();
       LCD_DATA_PORT&=0X0f; //�����λ
       LCD_DATA_PORT|=command&0xf0; //д����λ
    
       delay_nus(16);
       LCD_en_write2();
       command=command<<4; //����λ�Ƶ�����λ
       LCD_en_write1();
       LCD_DATA_PORT&=0x0f; //�����λ
       LCD_DATA_PORT|=command&0xf0; //д����λ
       LCD_en_write2();
    }
    
    /*****************************************
    *
    *               д���ݺ���
    *
    ****************************************/
    void LCD_write_data(unsigned char data)
    {
       delay_nus(16);
       P2SEL=0x00;
       LCD_RS_PORT|=LCD_RS;      //RS=1
       LCD_en_write1();          //E������
       LCD_DATA_PORT&=0X0f;      //�����λ
       LCD_DATA_PORT|=data&0xf0; //д����λ
       delay_nus(16);
       LCD_en_write2();
       data=data<<4;             //����λ�Ƶ�����λ
       LCD_en_write1();
       LCD_DATA_PORT&=0X0f;      //�����λ
       LCD_DATA_PORT|=data&0xf0; //д����λ
       LCD_en_write2();
    }
    
    /*****************************************
    *
    *               д��ַ����
    *
    ****************************************/
    void LCD_set_xy( unsigned char x, unsigned char y )
    {
       unsigned char address;
       if (y == 0) address = 0x80 + x;
       else address = 0xc0 + x;
       LCD_write_command( address);
    }
    
    /*****************************************
    *
    *LCD������λ��д�ַ�������x=0~15,��y=0,1
    *
    ****************************************/
    void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
    {
    LCD_set_xy( X, Y ); //д��ַ
        while (*s)          //д��ʾ�ַ�
        {
          LCD_write_data( *s );
          s++;
        }
    }
    
    /*****************************************
    *
    *     LCD������λ��д�ַ�,��x=0~15,��y=0,1
    *
    ****************************************/
    
    void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data)
    {
       LCD_set_xy( X, Y ); //д��ַ
       LCD_write_data( data);
    }
    
    /*****************************************
    *
    *               1us��ʱ����
    *
    ****************************************/
    
    void delay_1us(void)
    {
       asm("nop");
    }
    
    /*****************************************
    *
    *               N us��ʱ����
    *
    ****************************************/
    void delay_nus(unsigned int n)
    {
       unsigned int i;
       for (i=0;i<n;i++);
       delay_1us();
    }
    
    /*****************************************
    *
    *               1ms��ʱ����
    *
    ****************************************/
    void delay_1ms(void)
    {
       unsigned int i;
       for (i=0;i<1140;i++);
    }
    
    /*****************************************
    *
    *               N ms��ʱ����
    *
    ****************************************/
    void delay_nms(unsigned int n)
    {
       unsigned int i=0;
       for (i=0;i<n;i++);
       delay_1ms();
    }
    

  • In delay_nus():

    >for (i=0;i<n;i++);
    >delay_1us();

    Remove the trailing ";" from the first line. As it is, it's not repeating the delay.

    There's a similar typo in delay_nms().

**Attention** This is a public forum