I'm trying interfacing a standard 16x2lcd whit a msp430g2211, but I can't , I'm tired and I don't know what to do,I tried everything but I can't see a single character. please help!
thanks a lot!
my code:
/*Here's how the MCU pins are interfaced to the target.
MSP430 LCD interface
Function | MSP Pin
----------------------------
RW | GND
RS | P1.0
EN | P1.1
DB7 | P1.7
DB6 | P1.6
DB5 | P1.5
DB4 | P1.4
DB3 | GND
DB2 | GND
DB1 | GND
DB0 | GND
/////////////////////////////// */
#include <msp430g2211.h>
#define EN BIT1
#define RS BIT0
#define PIN_MASK ((RS | EN | BIT7 | BIT6 | BIT5 | BIT4))
void waitlcd(volatile unsigned int x)
{
volatile unsigned int i;
for (x ;x>1;x--)
for (i=0;i<=110;i++);
}
void lcdcmd(unsigned char Data)
{
P1OUT &= ~RS; //because sending command
P1OUT &=~EN;
P1OUT |= (Data & 0xF0);
P1OUT |=EN;
waitlcd(2);
P1OUT &=~EN;
P1OUT |= ((Data & 0x0F) << 4);
P1OUT |=EN;
waitlcd(2);
P1OUT &=~EN;
}
void lcdData(unsigned char l)
{
P1OUT |=RS; //because sending data
P1OUT &=~EN;
P1OUT |=(l & 0xF0);
P1OUT |=EN;
waitlcd(2);
P1OUT &=~EN;
P1OUT |= ((l & 0x0F) << 4);
P1OUT |=EN;
waitlcd(2);
P1OUT &=~EN;
}
void lcdinit(void)
{
P1DIR |= PIN_MASK;
P1OUT &= ~(PIN_MASK);
waitlcd(250);
P1OUT &= ~RS; //because sending command
P1OUT &=~EN;
P1OUT =0x20;//set data length 4 bit
P1OUT |=EN;
waitlcd(2);
P1OUT &=~EN;
waitlcd(250);
lcdcmd(0x28); //set data length 4 bit 2 line
waitlcd(250);
lcdcmd(0x0E); // set display on cursor on blink on
waitlcd(250);
lcdcmd(0x01); // clear lcd
waitlcd(250);
lcdcmd(0x06); // cursor shift direction
waitlcd(250);
lcdcmd(0x80); //set ram address
waitlcd(250);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ; //BCSCTL1 Calibration Data for 1MHz
DCOCTL = CALDCO_1MHZ; //DCOCTL Calibration Data for 1MHz
lcdinit();
lcdData('A');
for(;;){
waitlcd(1);
}
}// end main