Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

LCD interfacing problem

Rezef
Novice
967 Views

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);
}
}

 

0 Kudos
1 Solution
KellyJialin_Goh
Employee
919 Views

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


View solution in original post

0 Kudos
6 Replies
KellyJialin_Goh
Employee
920 Views

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


0 Kudos
KellyJialin_Goh
Employee
918 Views

Hi,

Please ignore the accepted solution, and looking forward on your findings whether the feedback provided has solved your issue.


Thank you.

Regards,

Kelly


0 Kudos
Rezef
Novice
905 Views

But i is working when the looping occurs for k==0 but only when k==1 it seems that i is not working as expected and instead starts from i=15. To solve that I intialized the value of i to zero too at the end of each case, but it didn't seem to work. Can it be due to some memory issues, or are some commands to be passed for the k==1 case to work?

0 Kudos
KellyJialin_Goh
Employee
864 Views

Hi,

You may check out this link that has more information on 4.2.3.4 accessing the memory and mapping of the NIOS II processor, 4.2.3.4.1 creating a simple C application on things to take note: https://www.intel.com/content/www/us/en/docs/programmable/683689/current/accessing-memory-with-the-processor.html


Thank you.

Regards,

Kelly


0 Kudos
Rezef
Novice
856 Views

I have found the issue.It was a mistake on my code part.I was sending the SendCommand(0x00C0) for each  letter .As it was intiailized for each letter, it was getting overwritten.All I had to do was change the i<15 to i==0 and then make another condition for i<15 llike the following:

for(i=0;i<=strlen(Text);i++)
{
if(i==0)
{
SendCommand(0x00C0);
SendData(Text[i]);
}
else if(i<15)
{
SendData(Text[i]);
}
else if(i==15)
{
SendCommand(0x0080);
SendData(Text[i]);
}
else if(i>15 && i<=(strlen(Text)-1))
{
SendData(Text[i]);
}
}
}

Thanks Kelly for your help in the i part. I will select your answer as the accepted solution

0 Kudos
KellyJialin_Goh
Employee
834 Views

Hi,

I’m glad that your question has been addressed, I now transition this thread to community support. If you have a new question, Please login to ‘https://supporttickets.intel.com’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.


p/s: If any answer from the community or Intel Support are helpful, please feel free to give best answer or rate 4/5 survey.


Thank you.

Regards,

Kelly Jialin, GOH

 


0 Kudos
Reply