Jump to content
43oh

i2c HD44780 LCD Booster Shield


Recommended Posts

Hi all,

There are plenty of serial LCD for Ardiuno but there is none or little for LaunchPad.
I am working on a i2c serial LCD Booster Pack, using the spare MSP430G2231 lying around.

Programming for the LCD on the G2231 is partially done. Back light is not working as the LCD I have needs 5v for Backlight / 3.3 for signals.
I ordered some with 3.3v Back light but it will take a while to reach me.

post-1099-0-14119100-1354187845_thumb.jpg

I am new to i2c, I will need to learn and program the G2231 as a i2c slave.
I am also thinking of adding 5 buttons, smiliar to Arduino's LCD shields, using the ADC to scan different button / resistor values.

I am wondering if the G2231 @ 1MHz is enough to achieve the the above objective. 12c, LCD, scanning the keys.
Any ideas, comments welcomed.

Pin used.
P1.0 - P1.3 4 bit LCD interface.
P1.6 - P1.7 i2C
P2.6 - EN on LCD
P2.7 - RS on LCD

optional / undeicded
P1.5 - ADC A5 - button scan
P1.4 - BL switch. / PWM ??

Link to post
Share on other sites

Just a quick thought. You *can* run the 2231s at 16mhz. There is a forum thread about calibrating the missing values (on phone ATM so can't search easily). To use them you also need to edit the header file for the 2231 which I seem to remember is also in the forum thread.

 

Sounds like a fun booster. Can't comment much more though as I haven't successfully played with i2c.

 

Good luck.

 

Dan

 

Sent from my GT-I8160 using Tapatalk 2

 

 

Link to post
Share on other sites

Thanks, will look into that ifI need the extra speed.

 

Just a quick thought. You *can* run the 2231s at 16mhz. There is a forum thread about calibrating the missing values (on phone ATM so can't search easily). To use them you also need to edit the header file for the 2231 which I seem to remember is also in the forum thread.

 

Sounds like a fun booster. Can't comment much more though as I haven't successfully played with i2c.

 

Good luck.

 

Dan

 

Sent from my GT-I8160 using Tapatalk 2

Link to post
Share on other sites

Quick update,

 

I got the the i2c slave code going, here is a video.

 

 

 

LaunchPad acting as a Master i2c driver writes "Hello, World" and a counter to the G2231 USI i2c slave.
Data is written in 2 bytes, byte 1 toggles the RS line on the LCD, byte 2 writes to the LCD data port.

 

Master using tinyprintf by oPossum.

Link to post
Share on other sites
  • 1 month later...

By request from Oscarasimov,

 

Here is the code for the LCD section, running on MSP430G2331. 

The following code is derived from many sources and it is no way complete, just good enough to run my code.

Still waiting for my board from seeedstudio, will post complete code. (including slave i2c when I am done)

 

/*						*/
/*	LCD.h - Terence Ang		        */
/*	5/12/2012				*/		
/* 						*/
/* 	Port Pins				*/
/*  RS = P2.7 -- LCD P4				*/
/*  EN = P2.6 -- LCD P6				*/
/* 	P1.0 - P1.3 -- LCD D4 - D7		*/
/* 	R/W - GND				*/


#include<msp430.h>

#define SET_RS(X)   P2OUT = ((P2OUT & ~(BIT7)) | (X << 7))      //  RS = P2.7 -- LCD 4
#define SET_EN(X)   P2OUT = ((P2OUT & ~(BIT6)) | (X << 6))	//  EN = P2.6 -- LCD 6
#define LCD_4BIT_PORT P1OUT  					// P1.0 - P1.3 - D4 - D7

#define LCD_EN_STROBE do{SET_EN(1);SET_EN(0);}while(0)		// toggle EN.

#define CMD 			0
#define DATA 			1

// LCD Commands
#define SET_LINE1 		0x80
#define SET_LINE2 		0xc0
#define CMD_8BIT 		0x30
#define CMD_8BIT2 		0x20
#define SET_4BIT 		0x28
#define CURSOR_OFF 		0x0C
#define AUTO_INC		0x06
#define CLEAR			0x01

//LCD functions
void LCD_write(unsigned char cmd, unsigned char data);
void LCD_string(char *s);
void LCD_8bit_cmd(unsigned char data);
void LCD_clear(void);
void LCD_init(void);

/*				*/
/*	LCD.C - Terence Ang	*/
/*	5/12/2012		*/

#include"LCD.h"

// LCD Data Write function.
void LCD_write(unsigned char cmd, unsigned char data) {
        SET_RS(cmd);	                                         //set RS high for Data, Low for Command
	__delay_cycles(40); 					 //40 us delay
	LCD_4BIT_PORT = (LCD_4BIT_PORT & 0xf0) | (data >> 4);    //High Nibble
	LCD_EN_STROBE;						 // Strobe EN for LCD to accept data
	LCD_4BIT_PORT = (LCD_4BIT_PORT & 0xf0) | (data & 0x0f);  //Low Nibble
	LCD_EN_STROBE;						 // Strobe EN for LCD to accept data
}

// LCD cmd  write in 8 bit for init only.
void LCD_8bit_cmd(unsigned char data) {
	SET_RS(0);
	__delay_cycles(15000); 			                //15 ms delay
	LCD_4BIT_PORT = (LCD_4BIT_PORT & 0xf0) | (data >> 4 & 0x0f);
	LCD_EN_STROBE;					        // Strobe EN to accept data
}

void LCD_init(void) {
	LCD_8bit_cmd(CMD_8BIT); 
	LCD_8bit_cmd(CMD_8BIT); //lcd expect 8bit mode commands at first
	LCD_8bit_cmd(CMD_8BIT); 
	LCD_8bit_cmd(CMD_8BIT2);
	LCD_write(CMD, SET_4BIT); //4 bit mode command started, set two line
	LCD_write(CMD, CURSOR_OFF); // Make cursor invisible
	LCD_clear(); // Clear screen
	LCD_write(CMD, AUTO_INC); // Set entry Mode(auto increment of cursor)
}

void LCD_clear(void) {
	LCD_write(CMD, CLEAR);
	__delay_cycles(3000); //3 ms delay
}

void LCD_string(char *s) {
	while (*s)
	LCD_write(DATA, *s++);
}
Link to post
Share on other sites
  • 1 month later...

I tried your code to get my LCD working but just got garbage characters.  I did change the pin configuration using P1.4 and P1.5 for RS and EN.  I wanted to be able to use PWM on pin P2.6 for backlight brightness control.  I wanted to check/verify it was working so I loaded Energia with the LCD sketch.  Worked great.  I knew my wiring was correct and the pins could support that configuration.

 

Any ideas on why I might be getting garbage?  I created a test c program similar to this:

#include "LCD.h"

int main(void) {
   WDTCTL = WDTPW + WDTHOLD;
   LCD_init();
   while(1) {
      LCD_string("test");
      __delay_cycles(1000000);
   }
}

 

I'm starting to wonder if it has something to do with LCD timings or something similar.  My 4-bit data lines are connected as follows:

P1.0 -> D4

P1.1 -> D5

P1.2 -> D6

P1.3 -> D7

Link to post
Share on other sites

Hi, 

 

I have made some changes since I posted this but it should work as it is.

 

I will attach the new code here so you try it.

 

Regards,

Terence

 

I tried your code to get my LCD working but just got garbage characters.  I did change the pin configuration using P1.4 and P1.5 for RS and EN.  I wanted to be able to use PWM on pin P2.6 for backlight brightness control.  I wanted to check/verify it was working so I loaded Energia with the LCD sketch.  Worked great.  I knew my wiring was correct and the pins could support that configuration.

 

Any ideas on why I might be getting garbage?  I created a test c program similar to this:

#include "LCD.h"

int main(void) {
   WDTCTL = WDTPW + WDTHOLD;
   LCD_init();
   while(1) {
      LCD_string("test");
      __delay_cycles(1000000);
   }
}

 

I'm starting to wonder if it has something to do with LCD timings or something similar.  My 4-bit data lines are connected as follows:

P1.0 -> D4

P1.1 -> D5

P1.2 -> D6

P1.3 -> D7

LCD.c

LCD.h

main.c

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...