连接MSP430g2553和16x4 LCD屏幕

时间:2016-12-21 02:57:34

标签: msp430 lcd

我无法让我的msp430与16x4液晶屏通信。 LCD屏幕的数据表:https://www.beta-estore.com/download/rk/RK-10290_410.pdf

这是我的代码:

#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();
}

我非常肯定我的所有引脚都已正确连接。液晶显示器正在投射光,但就是这样。我甚至无法让光标在屏幕上显示和闪烁。我的总线连接到8个LED灯,所以我可以确定正在发送正确的命令。这也是我在每次写操作之间有长时间延迟的原因。不知道该怎么做才能排除故障。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

抱歉延误。该问题的解决方案是在电路中增加一个电位器,这样我就可以改变LCD的对比度。我还必须改变这条线

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

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

谢谢大家的贡献。