NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, B.tech projects, M.tech projects, online Embedded C training

Interfacing 16x2 character LCD display with MSP430 Launch pad – 4-bit mode

Interfacing 16x2 character LCD display with MSP430 Launch pad is quite simple. You just need a separate 5V power supply to drive the LCD AND the remaining things will be taken care by the MSP430 and its firmware code. One of the main advantages of MSP430 Launch pad is its in-built debugging feature and its pin configuration. In this tutorial, I am not going to start from the scrap of LCD. But I encourage you to read my previous tutorials about introduction to LCD and its interfacing to microcontroller, where you can find the LCD commands, LCD functions, LCD interface mechanism etc.
In this post, I just show the connections between the LCD and MSP430 Launch pad, A test program to  display a string of characters on it, and finally a small video is presented in which output of the program is shown.
1. Construction:
Generally 16x2 character LCD displays requires eight data lines, three control lines (RS, EN, R/W) and 5v power supply and common ground. Here the microcontroller belongs to MSP430 family which runs worth 3.3v USB power supply. But the 16x2 LCD requires 5v power supply which should be provided separately. A small important note for you “don’t use USB power supply taken from MSP430 launch pad for LCD display” which may damage your pc USB port, so be careful about that.
The MSP430G2553 is a 20 pin IC, it is necessary to save I/O pins as many as possible, therefore it is possible to interface more number of I/O devices. For this purpose, in this tutorial i was planned to connect LCD in 4-bit mode, so that I can save four I/O pins when compared to 8-bit mode.
The upper data lines of the LCD are connected to Port 2 upper pins of the MSP430G2553 microcontroller and the control lines connected to Port1 pins (RS - P1.6 and EN - P1.7). Another more important thing is that connect the ground pin MSP430 Launch Pad with LCD ground pin in to order form the closed loop circuit. If you won’t connect the two grounds, then you notice some garbage characters appear on the LCD display while executing the program.One more important point in this tutorial that I connected the R/W pin of the LCD to ground, because I am not performing read operation on LCD, just write operation only. For write operation the LCD R/W pin should be connected to the ground.
2. Circuit Diagram to interface 16x2 LCD with MSP430 microcontroller – 4bit mode:

Circuit Diagram to interface 16x2 LCD with MSP430 microcontroller – 4bit mode

1.      Don’t use USB power supply for LCD display which is taken from the MSP430 launch pad board. Otherwise your pc USB port may damage by drawing more current from it.
2.       Join MSP430 launch pad ground point with LCD ground pin in order to form a closed circuit. Otherwise garbage characters will display.

Program code Explanation:
In the Firmware code, I have defined the following functions
send_cmd() – to send the commands to LCD
send_char() – to send the data or character to LCD
send_string() – to send the string to the LCD – when the string length is exceeds this function automatically shift the data on the screen.
LCD_Init() – LCD initialization
Delayms() – it is used to generate delay in microseconds when the CPU frequency is in MHz.
Note: Each and every port pin in the MSP430 got multiple functionalities (like General Purpose I/O, serial communication, ADC, comparator, etc...). In order to make the each port pin as GPIO, we have to use the following instructions.
       // make the port 2 function as general purpose I/O
       P2SEL = 0;
       P2SEL2 = 0;

Program code:

#include "MSP430g2553.h"
#define delay_value 500
void LCD_Init(void)
{
 send_cmd(0x28);       // configuring LCD as 2 line 5x7 matrix in 4-bit mode
 delayms(delay_value);
 send_cmd(0x0E);   //display on, cursor blink
 delayms(delay_value);
 send_cmd(0x06);  // auto increment of cursor
 delayms(delay_value);
 send_cmd(0x01);  // clear display
 delayms(delay_value);

}

void send_cmd(unsigned char command)
{


 P2OUT &= 0X00;

 P2OUT &= 0x00; // make upper bits of port as zero
    P2OUT =(command);    //mask lower nibble and send upper nibble

     P1OUT &= ~0x40;                        // RS = 0 for command, P1.6 0x40
     //RW is grounded
     P1OUT &= ~0x80;                        //EN = 0, P1.7, 0x80
     delayms(delay_value);
     P1OUT |= 0x80;                        // EN = 1, P1.7, 0x80
     delayms(delay_value);
     P1OUT &= ~0x80;                        //EN = 0, P1.7, 0x80
     delayms(delay_value);

     P2OUT &= 0x00; // make upper bits of port as zero

     P2OUT =(command<<4 data-blogger-escaped-0="" data-blogger-escaped-0x00="" data-blogger-escaped-0x40="" data-blogger-escaped-0x80="" data-blogger-escaped-and="" data-blogger-escaped-as="" data-blogger-escaped-bits="" data-blogger-escaped-char="" data-blogger-escaped-character="" data-blogger-escaped-command="" data-blogger-escaped-delay_value="" data-blogger-escaped-delayms="" data-blogger-escaped-en="1," data-blogger-escaped-for="" data-blogger-escaped-grounded="" data-blogger-escaped-i="" data-blogger-escaped-if="" data-blogger-escaped-is="" data-blogger-escaped-lower="" data-blogger-escaped-make="" data-blogger-escaped-mask="" data-blogger-escaped-nibble="" data-blogger-escaped-of="" data-blogger-escaped-p1.6="" data-blogger-escaped-p1.7="" data-blogger-escaped-p1out="" data-blogger-escaped-p2out="(String[i]<<4);" data-blogger-escaped-port="" data-blogger-escaped-rs="0" data-blogger-escaped-send="" data-blogger-escaped-send_char="" data-blogger-escaped-send_string="" data-blogger-escaped-tring="" data-blogger-escaped-unsigned="" data-blogger-escaped-upper="" data-blogger-escaped-void="" data-blogger-escaped-while="" data-blogger-escaped-x40="" data-blogger-escaped-x80="" data-blogger-escaped-zero="">=16)   // If the number of characters in the string > 16, then the below command automatically
  send_cmd(0x18);  // Shift the display right side
  delayms(40000);   // 100 millisec delay
  i++;
 }

}



void main(void)
{
 // Stop Watch Dog Timer
 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

 // PORT1 (P1.6, P1.7) are output - P1.6 - RS and P1.7 - EN for LCD
 P1DIR |= 0xC0;
 P1OUT = 0X00;

 // make the port 2 function as general purpose I/O
 P2SEL = 0 ;
 P2SEL2 = 0;

 // PORT 2 (P2.4, P2.5, P2.6, P2.7) upper 4 bits connected to LCD upper 4-bits(D4,D5,D6,D7)
 P2DIR = 0xF0;
 P2OUT = 0x00;

 delayms(1500); // wait for more than 15ms after supply rises to 4.5V
 send_cmd(0x30);
 delayms(4000);  // wait more than 4.1ms
 send_cmd(0x30);
 delayms(1000);  // wait more than 100us, but delayms(1) will provide 1ms
 send_cmd(0x30);
 delayms(1000);
 send_cmd(0x02); // return to home
 delayms(1000);

 LCD_Init(); // LCD initialization
 delayms(500);

 while(1)
 {

   send_cmd(0x01);
   delayms(delay_value);
   send_cmd(0x80);  // clear display
   delayms(delay_value);
   send_string("NPEDUCATIONS");
   delayms(60000);

 }// end of while

}

void delayms(unsigned int value)
{
 unsigned int i;
 for(i=0;i

2 comments :

  1. In which compiler have you tried and tested the code? I tried the same code with CCS v5.5 and msp430g2553 and it's not working.

    ReplyDelete
    Replies
    1. I compiled on the same compiler. Once check out the connections of your project

      Delete

Thanks for visiting NPEDUCATIONS. We will contact you soon

2 comments :

Anonymous said...

In which compiler have you tried and tested the code? I tried the same code with CCS v5.5 and msp430g2553 and it's not working.

Lovakiranvarma Myla said...

I compiled on the same compiler. Once check out the connections of your project

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.
Related Posts Plugin for WordPress, Blogger...

 
Powered by Blogger