Issue with Interfacing LCD with PIC16F877A

Farhaad

New Member
I would like to know why after E is printed in the 2nd line completely, after some time why it starts to print on first line too.
Simulation: Ive used the Proteus Version 8.16
Compiler: CCS Compiler 5.008
P.S Im a new joiner to this forum. So if there are any mistakes, please let me know. Ill try to follow the rules next time
 

Attachments

  • Screenshot 2024-03-03 at 15.26.06.png
    656 KB · Views: 262
Last edited:
You are writing an "E" to the display once a second?

If you mean it's not starting where you expect, you need whatever command the display uses to set the cursor (or write) position before sending data.

Note that often the text lines are not stored in contiguous display RAM, and you need to set the correct write position at each line change.
 
You mean like 0x04(It used to change location of a cursor to left side) and 0x06(It changes the position of cursor to right side) right? Thanks a lot...
 
Typically, the LCD controller IC may have 80 (or more) bytes of RAM, with the first line starting at 0x00 and the second line staring at 0x40 for a two-line display.

That allow for wider displays and more lines of text with the sam IC, depending what the character layout of the glass LCD itself is.

To set the write address, the command is usually 0x80 plus the address, so eg. 0x80 sets address zero, start of the first line, & 0xC0 sets addess 0x40, start of the second line.

Four line displays may use out of sequence start addresses for the lines...
 
Your LCD init needs to be in order.. Proteus expects the exact init routine.
Can you please tell whats the correct order? This is how I've considered so far. Feel free to tell make what changes need to made.
1) 0x38 - 2 Rows 3x7/8 Matrix
2) 0x0E/F - Display ON, Cursor Blink/Not Blink
3) 0x80/0xC0- First Row or Second Row
 
rjenkinsgb Also, I have noticed this. When I use a big string and want to it keep displaying in the first row, some of the end part doesnt display. What is the reason this is occuring. And how to fix this type of situation?
 

Attachments

  • Screenshot 2024-03-05 at 02.26.10.png
    998.8 KB · Views: 210
  • Screenshot 2024-03-05 at 09.22.03.png
    993.5 KB · Views: 198
When I say exact.. The LCD should automatically run in 8bit but proteus needs to see it for simulation
1 must always be function set with lines set to 0 or 1, then cursor... display on/off etc..

Are you scrolling the text? as that model only shows 16 digits in a row.
 
Yes. I am scrolling the text and Only "LINE ONE OF THE LCD DISPL" seems to print. If you see the SS attached in this post, I've taken a simple example of a string with 26 characters which as "a-z" and the LCD seems to only print from "a-y". Cant understand what the issue is.
 

Attachments

  • Screenshot 2024-03-05 at 09.22.03.png
    993.5 KB · Views: 197
char a~z is 26 characters, BUT a string needs a terminator so use "char a[27] "
Also I see you are using CCS.. Its not good practice to declare variables in line.. That is a C++ trait and if you use any other compiler it will complain.. I'm surprized that CCS is letting that happen.
 
char a[27] also doesnt work. Is it a Proteus issue by any chance? Honestly, sometimes I cant be sure if if the code is wrong or if Proteus is faulty.
Also according to rjenkinsgb and the website (https://www.engineersgarage.com/articles-arduino-16x2-character-lcd-scrolling-long-texts/) Its supposed to be able to store 40 characters.
 

Attachments

  • Screenshot 2024-03-05 at 11.47.43.png
    987.6 KB · Views: 192
Last edited:
Okay looking at the arduino example they are printing the full string to the DD ram.
You need to write the whole string to the screen, only then can you send the autoscroll command.

If you write the character one by one AND autoscroll at the same time the result will no be what you want.

write a string to screen function. and write the data first
Code:
void LCDstring(char * str)
   {
    while(*str !=0)
         LCDdata(*str++);
   }

Then scroll in a loop
 
So to reconfirm. You're telling me that if I want to display a-z and scroll then like print 'a' on 0x8F(First Row Last Column) then move it to the left one column, then print 'b' on 0x8F and move it left one column, its not possible?
 
So to reconfirm. You're telling me that if I want to display a-z and scroll then like print 'a' on 0x8F(First Row Last Column) then move it to the left one column, then print 'b' on 0x8F and move it left one column, its not possible?
The basic structure of an Hitachi based LCD module is usually 2 rows of 40 characters - the actual visible part (such as 2x16) is a 'window' on to that 2x40 memory space - if you hardware scroll the display it simply moves that 'window' left or right along the buffer.

I would suggest you do a loop to print the entire character set from 32 (space) to 128 one character at a time after each other, where you will see the action of the memory buffer, by which character appears as the first character of the second row.

Four line displays though come in a number of different configurations, so you need to know exactly which type you have, often they use two separate display chips, the first does the odd number lines, and the second does the even lines.
 
I just made one using your hardware ( my labels are different )

Code:
char txt[] = {"hello world from the other side of mars"};
..
void LCDstring(char * str)
    {
    while(*str !=0)
        LCDdata(*str++);    
    }
..
..
void main(void)
    {
    LCDinit();
    LCDstring(txt);
    while (1)
        {
        LCDcmd(0x18);
        delayMs(300);
        }
 }
 
Does the LCDdata(*str++); print the data?
 
Thank you will try it out. Meanwhile, I feel Im still not very clear with LCD operation. I know the commands and etc but during execution I'm a bit unsure how its gonna execute. Can you recommend anything to get more info on LCDs. And what kind of programs if I make would help me grasp the full concepts on LCD.


Edit: So the program which you mentioned its starts to print Characters(32[Space]-47[Backward Slash]) then on the second Row it starts from Character 96.
96-47 gives 49 Characters.
So the 16 Characters + 49 Characters are in the first row? How does it exceed 40?
 

Attachments

  • Screenshot 2024-03-05 at 16.15.38.png
    764.9 KB · Views: 201
Last edited:
It's probably hex 0x40 then
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…