gpt4 book ai didi

c - 将 16x2 LCD 与 SPI 连接,将字符放入第二行

转载 作者:行者123 更新时间:2023-11-30 16:48:54 24 4
gpt4 key购买 nike

我正在使用 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 时,您可以切换线路并开始写入。

关于c - 将 16x2 LCD 与 SPI 连接,将字符放入第二行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42823020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com