Tool/software: TI C/C++ Compiler
Hi Roberto Romano,
With the reference to this link, i have changed some pin assignments and compiled the program and dumped on to msp430g2553.
On the launchpad MSP-EXP430G2 its working fine,after the reset and able to display on the LCD screen.
but when i am dumping to the stand alone board of the same microcontroller its not working all the connection are fine,but is not displaying on the LCD.
Is anything going wrong ,Should i add any thing more to code to make it work.
/* This program is an example of HD44780 driver no busy check
Original from Marek Prochazka, adapted and debugged then released to public domain in TI e2e.
This program use a bit free assignment to lcd pinout so 6 free pin can be connected to LCD any way.
uP selected from Project setting. Tested on an LCD 16x2 and MSP430G2231
*/
//#include "io430.h"
//<msp430g2452.h>
#include <msp430g2553.h>
// LCD Port assignement
#define LCD_DIR P2DIR
#define LCD_OUT P2OUT
// Lcd Pin assignement
#define LCD_PIN_RS BIT2
//#define LCD_PIN_RW BIT7
#define LCD_PIN_EN BIT3
#define LCD_PIN_D4 BIT6
#define LCD_PIN_D5 BIT7
#define LCD_PIN_D6 BIT4
#define LCD_PIN_D7 BIT5
// Procedure to strobe data to LCD register
void LCDPulseEN(void)
{ // Set Enable active
__delay_cycles(20);
LCD_OUT |= LCD_PIN_EN;
__delay_cycles(20);
// Release Strobe
LCD_OUT &= (~LCD_PIN_EN);
}
// this send 4 bit of data
void SendNibble(char data)
{
// Clear all data bit
LCD_OUT &= ~(LCD_PIN_D4|LCD_PIN_D5|LCD_PIN_D6|LCD_PIN_D7);
// Set data bit on port bit
if(data & 0x01)
LCD_OUT |= LCD_PIN_D4;
if(data & 0x02)
LCD_OUT |= LCD_PIN_D5;
if(data & 0x04)
LCD_OUT |= LCD_PIN_D6;
if(data & 0x08)
LCD_OUT |= LCD_PIN_D7;
// Nibble set complete, send to LCD
LCDPulseEN();
__delay_cycles(500);
}
// Send a byte of data to LCD register
void SendByte(unsigned char data)
{
SendNibble((data>>4) & 0x0F);
SendNibble((data) & 0x0F);
__delay_cycles(500);
}
// send a byte to command register
void SendInstruction(unsigned char data)
{
// Set Register to command
LCD_OUT &= ~LCD_PIN_RS;
SendByte(data);
__delay_cycles(80000);
}
// Send a byte of data to LCD register
void LCDputch(unsigned char data)
{
// Set Register to data
LCD_OUT |= LCD_PIN_RS;
SendByte(data);
__delay_cycles(500);
}
void InitLCD(void)
{
// clear all bit of LCD control & data Lines
LCD_OUT &= ~(LCD_PIN_EN|LCD_PIN_RS); //|LCD_PIN_RW);
// Set LCD pins to output
LCD_DIR |=(LCD_PIN_EN|LCD_PIN_RS|LCD_PIN_D4|LCD_PIN_D5|LCD_PIN_D6|LCD_PIN_D7); // |LCD_PIN_RW
// wait Powerup
__delay_cycles(100000);
// LCD can be in an unknown state so set to a known state sending 3 times LCD set to 8 bit mode
SendNibble(3);
__delay_cycles(16000); // Wait for init
SendNibble(3);
__delay_cycles(400);
SendNibble(3);
__delay_cycles(400);
// now is 8 bit, sending 2 set mode to 4 bit (0x2n)
SendNibble(2);
__delay_cycles(800);
// Now set to mode 4 bit 2 line 5x7 char
SendInstruction(0x28);
__delay_cycles(8000);
// Make cursor visible one line set to 0x0c to invisible cursor
SendInstruction(0x0e);//c
__delay_cycles(800);
// Clear screen
SendInstruction(0x01);
__delay_cycles(8000);
// Increment address mode
SendInstruction(0x06);
__delay_cycles(8000);
// Set write data address to 0
SendInstruction(0x80);
}
// Set write cursor to Row and Col
void LCDSetPosition(char Row, char Col)
{
// if row is not 0 add 0x40 (4 line models require adding 0 20 60 40)
if(Row)
Col+=0x40;
SendInstruction(0x80 | Col);
__delay_cycles(800);
}
// Clear LCD
void LCDClear(void)
{
SendInstruction(0x01);
__delay_cycles(100000);
}
// Lcd cursor to first row first column
void LCDGoToHome(void)
{
SendInstruction(0x02);
__delay_cycles(100000);
}
// Shift left mode
void LCDShiftLeft(void)
{
SendInstruction(0x18);
}
// Shift right mode
void LCDShiftRight(void)
{
SendInstruction(0x1C);
}
// Cursor blinking mode
void LCDBlinkCursor(void)
{
SendInstruction(0x0F);
}
// Print a text line to LCD screen
void LCDPrintString(const char * Text)
{
while (*Text)
LCDputch(*Text++);
}
/***************************** 8 MHZ clock config *****************************/
void configureClocks_1MHZ(void)
{
#if 0
// Set system DCO to 8MHz
// BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
__bis_SR_register(SCG1 + SCG0); // Stop DCO
// BCSCTL2 |= SELM_1 + DIVM_3; // MCLK = LFXT1/8
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = 0;
DCOCTL = CALBC1_1MHZ;
FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
// Set LFXT1 to the VLO @ 12kHz
// BCSCTL3 |= LFXT1S_2;
#else
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */
#endif
}
void main (void)
{
char c;
int i;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
configureClocks_1MHZ();
P2SEL &= ~(0xC0);
P2DIR |= 0xC0;
InitLCD();
LCDPrintString("Hello world");
c='0';
while(1)
{
LCDSetPosition(1,10);
for(i=0;i<100;i++)
__delay_cycles(1000);
LCDputch(c);
c++;
if(c>'9') c='0';
}
}