Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
    Screenshot 2024-03-03 at 15.26.06.png
    656 KB · Views: 70
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 :D
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?
 
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);
        }
 }
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.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top