【问题标题】:Interfacing a 16x2 LCD with SPI, Getting Characters into the Second Row将 16x2 LCD 与 SPI 连接,将字符放入第二行
【发布时间】:2017-03-16 00:06:00
【问题描述】:

我正在使用 MSP430 MCU 读取模拟信号并通过 SPI 连接在 LCD 上显示结果。 LCD 为 16x2,根据Datasheet 上的 SPI 连接详细信息进行连接,并使用日立 HD44780 驱动程序。我可以填写第一行的16个字符没有问题。当我超过 16 时,即使我扩展包含我要打印的字符串的 char 数组,最后一个字符也不会显示(如预期的那样)。问题是第二行从不显示任何内容。当第一行某个位置没有字符时,所有位置仍然有淡淡的背景,但第二行始终是连续空白。以下是打印中使用的功能。我做错了什么?

我知道接线正确且 LCD 功能正常。为了测试这些,我将显示器连接到 arduino 进行测试,因为代码更简单,而且我能够在弓形行中显示字符。非描述性变量由 MSP430 源文件定义,包括寄存器、缓冲区和其他将器件置于 SPI 通信模式的控件。

void AlignLaserTarget()
{

    int i,k, j;
    struct testResults *ptestResults;
    char mess1[17]; //changed from 8 to hold 16 characters

    ptestResults=getTestResults();

    // reset global vars
    timeI1=0;
    timeA=0;
    i=starResults.ch1Amplitude; //analog integer value to be printed on LCD
    j=starResults.ch2Amplitude; //same
    k=starResults.ch3Amplitude; //same, but should go in second row
    sprintf(mess1,"1:%i 2:%i", i, j);
    stringTo_lcd8( mess1);
}

void stringTo_lcd8( char* lcdString )
{
    int i;

        LCD_COMMAND_MODE;       // display code
        timer_us(20);
        write_lcd8( 0x01); // clear display
        timer_ms(2);
        LCD_DATA_MODE; //enable data sending pin

        for ( i=0; *lcdString !=0 ; ++i)
        {
            write_lcd8( *lcdString);
            ++lcdString;
        }                       // end of display code

        timer_us(10000);    // 10ms delay . should not be needed as normal interval between counts is at least 75 ms or 12 in. at 800ft/min rate
}
//*******************************************************

void write_lcd8( unsigned char lcdbyte)
{
      UCA0IFG &= ~UCTXIFG;  // CLEAR FLAG
      UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
      UCA0CTL0 = UCMST+UCSYNC+ UCMSB+ UCCKPH;
      UCA0BR0 = 0x80;                           // /hex80
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      timer_us(100);
        LCD_CHIP_ENABLE;            // LCD enable pin output
        timer_us(20); // added trp
        UCA0TXBUF =lcdbyte;
        timer_us(150);
        while (!(UCA0IFG&UCTXIFG));
        UCA0IFG &= ~UCTXIFG;  // CLEAR FLAG
        LCD_CHIP_DISABLE;
        timer_us(30);
          UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
          UCA0CTL0 |= UCMST+UCSYNC+ UCMSB+ UCCKPH;
          UCA0BR0 = 0x02;                           // /2
          UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

}

【问题讨论】:

    标签: c embedded msp430 lcd


    【解决方案1】:

    我认为您必须在用于应用程序逻辑之前设计更多的驱动程序功能。我已经使用示例代码来设置光标位置

    void Lcd8_Set_Cursor(char line, char col)
    {
        if(line == 1)
          Lcd8_Cmd(0x80 + col);
        else if(line == 2)
            Lcd8_Cmd(0xC0 + col);
    }
    

    然后在您的打印逻辑中使用相同的。当长度超过 16 时,您可以换行开始写作。

    【讨论】:

    • 你为什么选择那些特定的十六进制值?它们是用于 HD44780 驱动程序的命令吗?我如何将 set cursor 命令与我存在的代码相匹配?调用第 1 行字符串的函数,然后调用第 2 行字符串的函数?
    • @Rejesh6115 已阅读 HD44780 的数据表 - 这是您应该做的。 Rajesh 如何知道如何将光标命令与您的软件相匹配?不知道为什么有人投了反对票,希望不是你。
    • @barny 您的评论没有帮助。我阅读了数据表,0x80 应该将光标设置在 0、0 位置,但我认为 0x90 将光标设置为 1、0 位置,因为它是 2x16 显示器,这就是为什么我问这些十六进制值来自哪里。我没有对答案投反对票。
    【解决方案2】:

    HD44780 预计每行 40 个字符,所以我只是添加空格来填充第一行,然后为下一行写字符。我确信有一个更好的解决方案,但这很快而且奏效了。我还必须更改两行配置的初始化规范。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      相关资源
      最近更新 更多