Interfacing an MSP430g2553 with a 16x4 LCD screen

440 views Asked by At

I'm having trouble getting my msp430 to communicate with a 16x4 LCD screen. Data sheet for the LCD screen: https://www.beta-estore.com/download/rk/RK-10290_410.pdf

Here is my code:

#define READMODE P2OUT = (P2OUT | BIT1) //set R/W pin high
#define WRITEMODE P2OUT=(P2OUT & ~BIT1) //set R/W pin low
#define ENABLEON P2OUT=P2OUT | 0x04 //set enable pin high
#define ENABLEOFF P2OUT=P2OUT & 0xFB //set enable pin low
#define RSDATA P2OUT = (P2OUT | BIT0) //set register select bit high so that the databus is sent to display
#define RSINSTRUCTION P2OUT = (P2OUT & ~BIT0) //set register select low so databus is sent to command register for initialization
int main(void){
  WDTCTL = WDTPW + WDTHOLD; //stop watchdog timer
  P1DIR = 0xFF;  //The entire P1 register is output
  P2DIR = 0xF7; //The entire P2 register is output except for p2.3
  P1OUT = 0x00;
  P2OUT = 0x01;
  ENABLEOFF;
  WRITEMODE;
  RSINSTRUCTION;
  sendCommand(0x30); //function set for 8 bit mode and display type
  sendCommand(0x01); //clear screen
  sendCommand(0x02); //Return Home
  sendCommand(0x07); //Increment cursor and screen right
  sendCommand(0x0B); //Screen display on and blinking cursor
  sendChar('a');
}

/**This function checks if the LCD is busy
 */
void isBusy(void){
  P1DIR &= ~BIT7; //Set bit 7 of P1 register as input
  READMODE;
  RSINSTRUCTION;
  while((P1IN & BIT7) == BIT7){
    dataRead();
  }
  P1DIR |= BIT7; //Set bit 7 of P1 register back to output 
  WRITEMODE;
}

/**Allows databus to be sent to LCD 
 */
void dataWrite(void){
  ENABLEOFF;
  __delay_cycles(1000000);
  ENABLEON;
  __delay_cycles(1000000);
  ENABLEOFF;
  __delay_cycles(1000000);
}

/**This function is only for checking if the LCD is busy.  If it is busy 
 * it will blink the enable light on and off
 */
void dataRead(void){
  ENABLEOFF;
  __delay_cycles(1000000);
  ENABLEON;
  __delay_cycles(1000000);
  ENABLEOFF;
  __delay_cycles(1000000);
}

/**This function sends a command to the LCD screen
 */
void sendCommand(unsigned char command){
  isBusy();
  WRITEMODE;
  RSINSTRUCTION;
  P1OUT = command;
  dataWrite();
}

void sendChar(char letter){
  RSDATA;
  WRITEMODE;
  P1OUT = letter;
  dataWrite();
}

I'm pretty positive all my pins are connected correctly. The LCD is projecting light but that's it. I can't even get the cursor to show up and blink on the screen. I have my bus connected to 8 LED lights so I can be sure the correct commands are being sent. That is also why I have the long delay in between each write operation. Not sure what to do from here to troubleshoot. Any help would be greatly appreciated.

1

There are 1 answers

0
user3736114 On

Sorry for the delay. The solution to the issue was adding a potentiometer to the circuit so I could change the contrast of the LCD. I also had to change the line

sendCommand(0x0B); //Screen display on and blinking cursor

to

sendCommand(0x0F); //Screen display on and blinking cursor

Thank you all for the contributions.