Thursday, December 1, 2011

16x2 Char LCD with TI MSP430 Launch Pad


      what we are gonna do is  interfacing MSP430 with an LCD module. In this case a typical 16x2 parallel LCD module with the Texas Instruments' MSP430G2211 on Launchpad development board. i will not cover much on the LCD side because i have already explained the working of HD44780 LCD in my previous post.


if you are new to LCD and have no idea how to make them work. checkout my previous post 


Things To keep in mid 

Supply Voltage

              The MSP430 (like most MCUs today) runs on 3.3-3.5V. If you get an LCD module that only work with  5V then be prepared to either have separate voltage sources for your MCU and LCD or have the ability to step up/down your voltage source. Here's a link that has some ideas on how to do this.  
or You can also use Transistor or Mosfet based  Translator 
Microcontroller SideLCD Side

but is guess at most of time you don't need a level translator . all you have to do the is power the 5V type lcd with 5v and let the signal line 3.5 volts . i have tested this kind of circuit and it worked fine.

LCD Contrast 
           
         i seen some lcd which works with both of the power (3.5V and 5V) supply but contrast is as low as you need to have special focus on the lcd to see the characters on the lcd . so be aware of  low lcd contrast when 3.5 v power is there

MSP430 Pin configuration  to LCD


Here's how the MCU pins are interfaced to the LCD.   all pin Number with MSP430G2211

MCU PIN Number LCD PIN Number FUNCTION
PORT1.0 Pin 1 11 D4
PORT1.1 Pin 2 12 D5
PORT1.2 Pin 313 D6
PORT1.3 Pin 4 14 D7
PORT1.6 Pin 8 6 EN
PORT1.7 Pin 9  4 RS


The other LCD pins connections are as follows:

Pin   16         |       GND      
Pin   15         |       Power for LED
Pin    5          |        (R/W) is grounded because we are always writeing to lcd  (UPDATED)
Pin   3           |       Outout from potentiometer for LCD contrast
Pin   1           |       GND
Pin   2           |       Vcc


Software Source Code


The software code is easy to under sand and  reusable in another application because 
i have created a header file which have all the routines to  control the lcd
all you have to do is copy the hearder file lcd16.h and lcd16.c into your project directory
#include "lcd16.h"

Routines  in the program



void lcdinit(void);                          // This routine take no input and return nothing. it initialize the lcd    
void integerToLcd(int integer ); );     //This routine take an integer as input and print that number to LCD

void lcdData(unsigned char l); // This rountine take a ASCII value  and print the corresponding char to the LCD

void prints(char *s);  // This rountine take a String value as input and print the corresponding char to the LCD

void gotoXy(unsigned char  x,unsigned char y); //This routine will take the cursor to a specific position on the lcd. 



CLICK HERE TO DOWNLOAD The SOURCE CODE


46 comments:

  1. Check the circuit connection . It is wrong !!

    ReplyDelete
  2. hi arjun

    please describe whats wrong with the connections

    ReplyDelete
  3. Did you find out what is wrong with circuit? I tried it and it did not work...

    ReplyDelete
  4. Yea it worked for me too. But quick question, data write is trigerred by falling edge of enable or rising edge? Because many datasheets out there say that rising edge of enable starts writing process.

    Thank you

    ReplyDelete
    Replies
    1. I think you are from Turkey. May I ask you a few questions about circuit? Could you please send me your contact details? My e-mail is ozaslanozgur@gmail.com .

      Delete
  5. hi guys

    i have tested this circuit more then 5 times and it's fine


    it will work fine

    ReplyDelete
  6. Hi. First off thanks for writing this article, VERY helpful.
    Two details about the circuit:
    1)"PORT1.6 Pin 9" should read "PORT1.7 Pin 9"
    2)You do not mention grounding pin 5 (R/!W) - spotted it on your PIC project

    I expect that is the error mentioned and it now works!

    ReplyDelete
  7. @onlinetime thank your for spotting the problems

    i was just a typing mistake ,i have now updated the article

    ReplyDelete
  8. Hi. I have problem with interfacing MSP430 LaunchPad with LCD 16x2. I make all by example but nothing is displayed on LCD. I think MSP430 send no data to LCD controller. Can you help me please.

    ReplyDelete
  9. hi tristan

    try to adjust the contrast from the pot on pin 3

    i hope you r having the lcd which work with 3.5 volts because normal 5v lcd have really low contrast
    so if you have 5v lcd the don't worry you can still test this circuit
    all you have to do is power the lcd with 5v supply and rest of the circuit is still on 3.5v

    ihope this will solve your problem

    ReplyDelete
  10. Thanks for help Gaurav Chaudhary. The problem was the contrast of the LCD. Everything in this project work correct and I'm very glad.

    ReplyDelete
  11. please can any one help me ? I am getting all the connection right but the screen gets refreshed at very high rate and cursor keeps moving on entire screen at very high speed and nothing gets printed.I am using the IAR workbench for program.please provide the solution.Thank You.

    ReplyDelete
  12. source code is the same provided by on the side and I havent made any changes to it.can you confirm that RS pin is 7 or not.Because datasheet is showing pin 4 as the RS pin.Thank You.

    ReplyDelete
    Replies
    1. RS of lcd is pin 4 thank you for text errors

      Delete
    2. now I have correct circuit but the screen is keep printing the y and the cursor is still moving across the screen after writing the y at very fast speed.please help.

      Delete
  13. This comment has been removed by the author.

    ReplyDelete
  14. How do you hide the cursor?

    Also, how do you shift it so the output is on pins 1.0, 1.1, 1.4, 1.5, 1.6, 1.6 instead, as I want to use Switch 2 (S2).

    Thanks

    ReplyDelete
  15. hello.

    pleas i want to sho the temeratur valus on this LCD with MSP430...can som1 help me plzzzz

    ReplyDelete
  16. #define data P1
    #define BF P1_7
    #define RS P2_0
    #define RW P2_1
    #define EN P2_2
    #define clear LCDcontrol(0x01)
    #define row1 LCDcontrol(0x80)
    #define row2 LCDcontrol(0xC0)
    ///////////////////

    void delay(unsigned char time)
    {
    int n;
    for(n=0;n<time;n++) ;
    }
    void LCDcontrol(unsigned char x)
    {
    EN=1;
    RS=0;
    RW=0;
    data=x;
    EN=0;
    delay(100);
    }
    void LCDinit(void)
    {
    LCDcontrol(0x30);
    LCDcontrol(0x30);
    LCDcontrol(0x30);
    LCDcontrol(0x38);
    LCDcontrol(0x0C);
    LCDcontrol(0x06);
    }
    void LCD_putc(long dl)
    { if(dl=='\n')
    {
    LCDcontrol(0xC0);
    return;
    }
    data = dl;
    RS=1; RW=0;
    EN=1; EN=0;;
    delay(150);
    }
    void LCD_puts(char *s)
    {
    while(*s)
    LCD_putc(*s++);
    }
    void LCD_number(long number)
    {
    unsigned char a,b,c,d,e,f,g,h,i,j;
    a=number/1000000000;
    b=(number-1000000000*a)/100000000;
    c=(number-1000000000*a-100000000*b)/10000000;
    d=(number-1000000000*a-100000000*b-10000000*c)/1000000;
    e=(number-1000000000*a-100000000*b-10000000*c-1000000*d)/100000;
    f=(number-1000000000*a-100000000*b-10000000*c-1000000*d-100000*e)/10000;
    g=(number-1000000000*a-100000000*b-10000000*c-1000000*d-100000*e-10000*f)/1000;
    h=(number-1000000000*a-100000000*b-10000000*c-1000000*d-100000*e-10000*f-1000*g)/100;
    i=(number-1000000000*a-100000000*b-10000000*c-1000000*d-100000*e-10000*f-1000*g-100*h)/10;
    j=(number-1000000000*a-100000000*b-10000000*c-1000000*d-100000*e-10000*f-1000*g-100*h-10*i);
    LCD_putc(a+48);
    LCD_putc(b+48);
    LCD_putc(c+48);
    LCD_putc(d+48);
    LCD_putc(e+48);
    LCD_putc(f+48);
    LCD_putc(g+48);
    LCD_putc(h+48);
    LCD_putc(i+48);
    LCD_putc(j+48);
    delay(200);
    }
    void TRE(int y)
    { int i,n;
    for(n=0;n<y;n++)
    { for(i=0;i<5000;i++);}
    }

    ReplyDelete
  17. hi Gaurav Chaudhary...You have given a great information..
    I am working with MSP430g2231.. ll ur source code run for this MSP?? if so how should i add those two files to project directory ? i am using CSSV4...pls help me..

    ReplyDelete
  18. Hi!

    I'm attempting to migrate this program to the TI Delfino series processor - any chance you could provide a more commented version of the code just so we could unerstand what you did a little better? Thanks!!

    ReplyDelete
  19. Hi Gaurav, Thanks for the tutorial. I have wired everything up ok and have the LCD powered and displaying a blank matrix via the contrast potentiometer. I have removed the jumper pins to the onboard LEDs and checked the links to the LCD, the code compiles with a few warnings but downloads to the MSP430

    I brought the LCD from DealExtreme so now turning my attention this as a possible issue.

    I noted someone mentioned about the enable pin earlier in the comments, in your code how could I adjust this as a test? Are you aware of an easy way to test the LCD

    ReplyDelete
  20. in Supply Voltage translation circuit what is the resister value u people are using ?? pls suggest me as soon as possile ?

    ReplyDelete
    Replies
    1. you can use any npn transistor you like . like bc547 bc548 , 2n2369 just anything

      Delete
    2. Hi,first of all thanks for sharing. I would like to know the value of the R1 resistor, i will use a transistor based translator with a bc547.

      Delete
  21. would u tell about contrast and and where to connect rs to which pin..?

    ReplyDelete
  22. Thank you for the code..... it works out well......

    ReplyDelete
  23. Any changes to be made to this when interfacing with MSP430G2553, Gaurav? Because when I connect as per the given setup and run the code, the first row of LCD completely darkens once, and then once again ( 2 blinks of the entire first row) and then no response. Please let me know ASAP!! Thanks :)

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete
  25. Thanks for the code. I just had to make some port connection changes to make it work. Good stuff!! :)

    ReplyDelete
    Replies
    1. GAUTRUNX plz tel me wt changes u made for MSP430G2553...
      Rply as soon as possible... plz...

      Delete
    2. Hope I am not too late, Hemanth Kumar :)

      Basically I used an LCD shield that had its own port configs (used PORT 2).
      So generally, what u have to do is make sure which configuration for LCD u r using, that is, what are your connections.
      If you are using the exact code given here, then make sure you have some way of adjusting pot contrast. Also ground the D0, D1 , D2 and D3 pins of your LCD. If other config u r using, then make sure u correspondingly change the bit masks and the way u are sending the nibbles of data through the pins (shift the bits before sending if needed) in the lcd16.c file. I would recommend u use a ready made shield of some sort for the LCD instead of using 16 wires, as u might be facing problem of loose connections too.

      Delete
    3. if just related to msp430g2553, make sure u r using include header file of that uC itself. no other changes.

      Delete
  26. This comment has been removed by the author.

    ReplyDelete
  27. Wow~ nice post~ But, i am very new to this LCD topics.

    I downloaded your source code, but i am still confused about it..

    Can you post the simplest code to display just one word on the LCD using 8 bit mode? Just for learning purpose. =)

    Thank you veryyy veryyy much~ =)

    ReplyDelete
  28. Any changes to be made to this when interfacing with MSP430G2553, Gaurav?i m using IAR embedded test bench to run ur code but i m new to this so can u help me out in checking the output in the software it runs with out any error but i m nt able to check it on the pc pls reply as soon as possible.
    thank u

    ReplyDelete
  29. Works like a champ..... Thanks for the info!

    ReplyDelete
  30. WORKS EN TALLA el MIO THANKSSS

    ReplyDelete
  31. will this work for jhd162a lcd .please reply me soon

    ReplyDelete
  32. hi i am trying to interface interface lcd jhd162a with msp430 launchpad i tried several times, even bought new lcd , i powered lcd with 5 v , but when launchpad start , on lcd just first row is displaying with full doted Bars , no char is showing pls help, i tried your source Code & connections. even i tried cd4050 ic as a level transleter but omly 1st row is dislaying with full doted bars.

    ReplyDelete
  33. please try to adjust the contrast of the LCD Module ,

    ReplyDelete