【发布时间】: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**
}
【问题讨论】: