将 16x2 LCD 与 SPI 连接,让字符进入第二行
Interfacing a 16x2 LCD with SPI, Getting Characters into the Second Row
我正在使用 MSP430 MCU 读取模拟信号并在带有 SPI 连接的 LCD 上显示结果。 LCD 是 16x2,根据 Datasheet 上的 SPI 连接详细信息进行连接,并使用 Hitachi 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**
}
我认为在用于应用程序逻辑之前,您必须设计更多的驱动程序功能。我已经使用示例代码来设置光标位置
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 个字符,所以我只是添加空格来填充第一行,然后为下一行写入字符。我确信有更好的解决方案,但这很快并且有效。我还必须更改两行配置的初始化规范。
我正在使用 MSP430 MCU 读取模拟信号并在带有 SPI 连接的 LCD 上显示结果。 LCD 是 16x2,根据 Datasheet 上的 SPI 连接详细信息进行连接,并使用 Hitachi 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**
}
我认为在用于应用程序逻辑之前,您必须设计更多的驱动程序功能。我已经使用示例代码来设置光标位置
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 个字符,所以我只是添加空格来填充第一行,然后为下一行写入字符。我确信有更好的解决方案,但这很快并且有效。我还必须更改两行配置的初始化规范。