Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将16x2 LCD与SPI接口,将字符放入第二行_C_Embedded_Msp430_Lcd - Fatal编程技术网

将16x2 LCD与SPI接口,将字符放入第二行

将16x2 LCD与SPI接口,将字符放入第二行,c,embedded,msp430,lcd,C,Embedded,Msp430,Lcd,我使用MSP430单片机读取模拟信号,并通过SPI连接在LCD上显示结果。LCD为16x2,根据上的SPI连接详细信息进行连接,并使用日立HD44780驱动程序。我可以填写第一行的16个字符,没问题。当我超过16时,即使我扩展了保存要打印的字符串的字符数组,最后一个字符也不会显示(如预期的那样)。问题是第二行从不显示任何内容。当第一行的某个位置中没有字符时,所有位置中仍有微弱的背景,但第二行始终为空。以下是打印中使用的功能。我做错了什么 我知道接线正确,LCD功能正常。为了测试这些,我将显示器连

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

我知道接线正确,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**

}

我认为在用于应用程序逻辑之前,您必须设计更多的驱动程序函数。我已经获取了设置光标位置的示例代码

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预计每行40个字符,因此我只添加了空格来填充第一行,然后为下一行写入字符。我相信有一个更好的解决方案,但这是快速的,它的工作。我还必须更改两行配置的初始化规范。

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