我使用SPI微控制器读取模拟信号,并将结果显示在带有MSP430连接的液晶屏上。液晶屏为16x2,根据Datasheet上的SPI连接详细信息进行连接,并使用日立HD44780驱动程序。我可以填满第一行的16个字符,没有问题。当我超过16的时候,最后一个字符没有显示(如预期的那样),即使我扩展了包含我想要打印的字符串的char数组。问题是第二行永远不会显示任何内容。当第一行中的某个位置没有字符时,所有位置仍有模糊的背景,但第二行始终连续为空。以下是打印中使用的函数。我做错了什么?
我知道线路正确,液晶屏工作正常。为了测试这些,我将显示器连接到arduino进行测试,因为代码要简单得多,而且我能够在弓形行中显示字符。非描述性变量由SPI源文件定义,包括寄存器、缓冲器和其它控件,用于将器件置于MSP430通信模式。
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**
}发布于 2017-03-17 07:31:56
HD44780期望每行有40个字符,所以我只是添加了空格来填充第一行,然后为下一行写下这些字符。我相信有更好的解决方案,但这是快速和有效的。我还必须更改两行配置的初始化规范。
发布于 2017-03-16 09:24:32
我认为在用于应用程序逻辑之前,您必须设计更多的驱动程序函数。我使用了示例代码来设置光标位置
void Lcd8_Set_Cursor(char line, char col)
{
if(line == 1)
Lcd8_Cmd(0x80 + col);
else if(line == 2)
Lcd8_Cmd(0xC0 + col);
}然后在您的打印逻辑中使用相同的代码。当长度超过16时,你可以换行并开始写作。
https://stackoverflow.com/questions/42823020
复制相似问题