PentiumPC 119 Posted November 29, 2012 Share Posted November 29, 2012 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.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 i2CP2.6 - EN on LCDP2.7 - RS on LCDoptional / undeicdedP1.5 - ADC A5 - button scanP1.4 - BL switch. / PWM ?? bluehash 1 Quote Link to post Share on other sites
DanAndDusty 62 Posted November 29, 2012 Share Posted November 29, 2012 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 Quote Link to post Share on other sites
PentiumPC 119 Posted November 29, 2012 Author Share Posted November 29, 2012 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 Quote Link to post Share on other sites
abecedarian 330 Posted November 30, 2012 Share Posted November 30, 2012 I believe the thread is this: http://forum.43oh.com/topic/211-flashing-the-missing-dco-calibration-constants/ DanAndDusty 1 Quote Link to post Share on other sites
DanAndDusty 62 Posted November 30, 2012 Share Posted November 30, 2012 I believe the thread is this: http://forum.43oh.com/topic/211-flashing-the-missing-dco-calibration-constants/ Yup. That's the one I was thinking of. Thanks for doing the link hunting. Sent from my GT-I8160 using Tapatalk 2 abecedarian 1 Quote Link to post Share on other sites
PentiumPC 119 Posted December 4, 2012 Author Share Posted December 4, 2012 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. bluehash, pine and jsolarski 3 Quote Link to post Share on other sites
PentiumPC 119 Posted January 5, 2013 Author Share Posted January 5, 2013 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++); } bluehash and pine 2 Quote Link to post Share on other sites
PentiumPC 119 Posted February 21, 2013 Author Share Posted February 21, 2013 (edited) Finally found some time to populate this board. Somehow an overlapping track passed DRC in Eagle, so have to cut a track to fix it. the LCD booster shield is mounted on the Launchpad and communicates thru i2c. keypad code not ready. Edited March 3, 2013 by bluehash Uploaded photo to 43oh. pine 1 Quote Link to post Share on other sites
PentiumPC 119 Posted February 26, 2013 Author Share Posted February 26, 2013 (edited) Launchpad, Bluetooth and LCD stacked. Edited March 3, 2013 by bluehash Uploaded photo to 43oh Quote Link to post Share on other sites
flying4fun 0 Posted March 5, 2013 Share Posted March 5, 2013 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 Quote Link to post Share on other sites
PentiumPC 119 Posted March 5, 2013 Author Share Posted March 5, 2013 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 bluehash, flying4fun, cfb95 and 1 other 4 Quote Link to post Share on other sites
flying4fun 0 Posted March 5, 2013 Share Posted March 5, 2013 Never mind. Looks like I figured it out. I made a few changes and was apparently running strobe rs/en twice. I removed the second one and now it works great. Thanks for your code and help! Wow those additions are great. Thanks for the code update! Quote Link to post Share on other sites
PentiumPC 119 Posted March 6, 2013 Author Share Posted March 6, 2013 No problem, glad it is useful for you, the codes are meant for my lcd booster but can easily adapt it. Quote Link to post Share on other sites
KAAN_RF 0 Posted March 10, 2013 Share Posted March 10, 2013 Thanks a lot for I2C lcd code Happy coding Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.