我正在使用MSP430 MCU讀取模擬信號並將結果顯示在具有SPI連接的LCD上。 LCD是16x2,根據Datasheet上的SPI連接細節連接,並使用Hitachi HD44780驅動程序。我可以填寫第一行的16個字符沒有問題。當我超過16時,即使擴展包含要打印的字符串的char數組,也不會顯示最後一個字符(如預期的那樣)。問題是第二行從不顯示任何東西。當第一行的某個位置沒有字符時,所有位置仍然有一個微弱的背景,但第二行始終是空白的。以下是打印中使用的功能。我究竟做錯了什麼?將16x2 LCD與SPI連接,將字符插入第二行
我知道接線是正確的,並且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**
}
爲什麼選擇這些特定的十六進制值?他們是否是HD44780驅動程序的命令? 我將如何使用我的代碼存在的設置光標命令?調用第1行字符串的函數,然後調用第2行字符串的函數? –
@ Rejesh6115已經閱讀了HD44780的數據表 - 這是你應該做的。 Rajesh如何知道如何將光標命令與你的軟件配合?不知道爲什麼有人低調,希望不是你。 – barny
@barny你的評論是沒有用的。我讀數據表,0x80應該將光標設置在0,0的位置,但我認爲0x90將光標設置爲1,0的位置,因爲它是一個2x16顯示器,這就是爲什麼我問這些十六進制值來自哪裏。我沒有降低答案。 –