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:
LCD's are quite easy to use.
Here is my entire program.. go though and you will see.
Code:
#include <xc.h>

#pragma config FOSC=HS
#pragma config WDTE=OFF
#pragma config BOREN=OFF

char txt[] = {"hello world from the other side of mars"};

void delayUs(int x)
    {
    while(x--);
    }

void delayMs(int x)
    {
    while(x--)
        delayUs(1000);
    }

void    LCDcmd(char cmd)
    {
    PORTB = cmd;
    RC1 = 0;
    RC0 = 1;
    RC0 = 0;
    delayMs(5);
    }

void    LCDdata(char dat)
    {
    PORTB = dat;
    RC1 = 1;
    RC0 = 1;
    RC0 = 0;
    RC1 = 0;
    delayMs(5);
    }

void LCDgoto( char col, char row)
    {
    unsigned char tmp = 0x80;
    if(row) tmp+=0x40;
    tmp+= col;
    LCDcmd(tmp);
    }

void LCDstring(char * str)
    {
    while(*str !=0)
        LCDdata(*str++);    
    }

void LCDinit(void)
    {
    TRISB = 0;
    TRISC = 0;
    delayMs(40);
    PORTB = 0x30;
    RC0 = 1;
    RC0 = 0;
    delayMs(15);
    PORTB = 0x30;
    RC0 = 1;
    RC0 = 0;    
    delayMs(5);
    PORTB = 0x30;
    RC0 = 1;
    RC0 = 0;
    LCDcmd(0x38);
    LCDcmd(0xD);
    LCDcmd(6);
    LCDcmd(1);
    }

void main(void)
    {
    LCDinit();
    LCDstring(txt);
    while (1)
        {
        LCDcmd(0x18);
        delayMs(300);
        }
 }
 
It's probably hex 0x40 then
I have a question. If I simply run the loop It stores 40 Hex Characters and the 41st Hex Character is printed on the 2nd Line. But If I try to view all the characters by starting to display the characters from First Row Last Column position(0x8F) then I can see only Hex Characters. From 'Space' to '8'. Why?
 
Your using MPLAB right? Oh god. I never used MPLAB much, so the port syntax and stuff is difficult for me to understand. But I'll try.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…