LCD interfacing problem
So what I am trying to do is display some characters on my LCD which is connected to Altera FPGA Board. The LCD should be at first at line1 and line 2 but after a loop , the string should change to line 2 and line 1 Respectively. For Example, the string is "This is FPGA Project for fun".So What I want is the LCD display to show:
///////LCD Display case 1//
This is FPGA Pro
ject for fun
///////////////////
and at the next loop
////////Ideal LCD Display case 2///
ject for fun
This is FPGA Pro
///////////////////////////////
But what I am getting is different. For the case 1 it displays according to the desired output but for case 2 the LCD Display shows something like this:
//////LCD Display Case2////
ject for fun
o
///////////////////////////////
As you can see the the "This is FPGA Pr" doesn't occur for the looping
This is my NIOS C code:
#include "sys/alt_stdio.h"
#include "priv/alt_busy_sleep.h"
#include "altera_avalon_pio_regs.h"
#include "system.h"
void SendCommand(alt_u8 cmd);
void SendData(alt_u8 data);
void SendMessage(char* Text);
int main()
{
SendCommand(0x0038);
SendCommand(0x000F);
SendCommand(0x0001);
SendCommand(0x0006);
char Text[]="This is FPGA Project for fun";
SendMessage(Text);
SendCommand(0x000C);
}
void SendCommand(alt_u8 cmd)
{
IOWR_ALTERA_AVALON_PIO_DATA(LCD_BITBANG_BASE,0x0400|cmd);
alt_busy_sleep(1000);
IOWR_ALTERA_AVALON_PIO_DATA(LCD_BITBANG_BASE,0x0000);
alt_busy_sleep(1000);
}
void SendData(alt_u8 data)
{
IOWR_ALTERA_AVALON_PIO_DATA(LCD_BITBANG_BASE,0x0600|data);
alt_busy_sleep(1000);
IOWR_ALTERA_AVALON_PIO_DATA(LCD_BITBANG_BASE,0x0000);
alt_busy_sleep(1000);
}
void SendMessage(char* Text)
{ int i,k,l;
k=0;
l=0;
while(l<50)
{
if(k==0)
{
for(i=0;i<=strlen(Text);i++)
{
if(i<16)
{
SendData(Text[i]);
}
else if(i==16)
{
SendCommand(0x00C0);
SendData(Text[i]);
}
else if(i>16 && i<=(strlen(Text)-1))
{
SendData(Text[i]);
}
}
k=1;
i=0;
}
else if(k==1)
{
for(i=0;i<=strlen(Text);i++)
{
if(i<16)
{
SendCommand(0x00C0);
SendData(Text[i]);
}
else if(i==16)
{
SendCommand(0x0080);
SendData(Text[i]);
}
else if(i>16 && i<=(strlen(Text)-1))
{
SendData(Text[i]);
}
}
k=0;
i=0;
}
l=l+1;
alt_putstr(Text);
alt_busy_sleep(1500000);
SendCommand(0x0001);
SendCommand(0x0006);
}
}
Hi,
Greetings and welcome to Intel's forum.
As I look into your code, the issue might lie in the integer ' i ' is limiting the characters in a string for display. You may try to increase the value and see whether it solves the issue.
Here is a link on how NIOS II driver controls the Character LCD for your reference: https://www.intel.com/content/www/us/en/support/programmable/articles/000078036.html
Hope to hear on your findings. Thank you.
Regards,
Kelly