EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / LCD interface giving garbage value

LCD interface giving garbage value

|

Microcontroller › PIC › LCD interface giving garbage value

  • This topic has 4 replies, 3 voices, and was last updated 11 years, 10 months ago by Ashutosh Bhatt.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • February 4, 2014 at 5:14 am #2844
    cdsanghani
    Participant

    I have interface 4-bit, 16×2 LCD with PIC16F877 using hi-tech compiler. 

    I have compile the code and done successfully. But in LCD display it is giving garbage value. Code is given below.

     

    //LCD Control pins
     
    #include<pic.h>
    #include<htc.h>
    #include “lcd.h”
    #include<conio.h>
    #include<stdio.h>
    #include<string.h>
     
     
    #define rs RA3
    #define rw RA2
    #define en RA1
    //LCD Data pins
    #define lcdport PORTD
     
    void delayms(unsigned int);
    void lcd_ini();
    void dis_cmd(unsigned char);
    void dis_data(unsigned char *);
    void lcdcmd(unsigned char);
    void lcddata(unsigned char);
     
    void delayms(unsigned int a)
    {
    int k,j;
     
    for(k=0;k<a;k++)
    for(j=0;j<1175;j++);
    }
     
     
    void main(void)
    {
    unsigned char a=’x’;
    // unsigned char data0[]=”hijkkj”;
    char *p;
    unsigned int i=0;
    ADCON1=0x06;
    TRISA=0;
    PORTA=0;
    TRISD=0; // Configure Port D as output port
    PORTD=0;
    delayms(5);
    lcd_ini(); // LCD initialization
    delayms(5);
     
    p=&a;
    // p=data0;
    // while(data0!=’’)
     
    /* while(*p!=’’)
    { dis_data(*p);
    // dis_data(data0);
    delayms(10);
    p++;
    delayms(1);
    delayms(1);
    }*/
     
    dis_data(*p);
    delayms(1000);
    // dis_cmd(0x85);
    // dis_data(‘b’);
     
    }
    void lcd_ini()                    
    {
    dis_cmd(0x02);     // To initialize LCD in 4-bit mode.
    delayms(5);
    dis_cmd(0x18); // To initialize LCD in 1 lines, 5×7 dots and 4bit mode.
    delayms(5);
    dis_cmd(0xF);      // Display on Cursor blinking
    delayms(5);
    dis_cmd(0x01); //clear screen
    delayms(5);
    dis_cmd(0x06);      // Entry mode
    delayms(5);
    dis_cmd(0x80);      // cursor position at first line
    delayms(1);
    delayms(1);
    delayms(1);    
    }
     
    void dis_cmd(unsigned char cmd_value)
    {
    unsigned char cmd_value1;
    delayms(5);
    cmd_value1 = (cmd_value & 0x0F); // Mask lower nibble because RB4-RB7 pins are being used
    lcdcmd(cmd_value1); // Send to LCD
    delayms(5);
    cmd_value1 = ((cmd_value<<4) & 0x0F); // Shift 4-bit and mask
    lcdcmd(cmd_value1); // Send to LCD
    delayms(5);
    }
     
     
    void dis_data(unsigned char *data_value)
    {
     
    unsigned char data_value1;
    delayms(5);
    data_value1=(*data_value&0x0F);
    lcddata(data_value1);
    delayms(5);
    data_value1=((*data_value<<4)&0x0F);
    lcddata(data_value1);
    delayms(5);
    // dis_cmd(0x14);
    }
     
     
     
    void lcdcmd(unsigned char cmdout)
    {
    lcdport=cmdout; //Send command to lcdport=PORTB
    rs=0;
    rw=0;
    en=1;
    delayms(10);
    en=0;
    }
     
    void lcddata(unsigned char dataout)
    {
    lcdport=dataout; //Send data to lcdport=PORTB
    rs=1;
    rw=0;
    en=1;
    delayms(10);
    en=0;
    }
    February 5, 2014 at 4:05 am #10940
    AJISH ALFRED
    Participant

    Hi,

    Rather than using pointers and all like,

    dis_data(*p);

     

    Try this,

     

    dis_data(‘b’);

     

    If it is working then there must be some issues in your code only, otherwise check the circuit connections for any mistake.

    February 7, 2014 at 10:55 am #10957
    Ashutosh Bhatt
    Participant

    for LCD interfacing on any platform there are mainly three to four functions

    lcd_init()

    lcd_send_command()

    lcd_send_data()

    lcd_print()

    lcd_busy()

     

    u can refer tutorials for LCD interfacing on this site.

    February 7, 2014 at 11:11 am #10958
    cdsanghani
    Participant

    YA ITS OK BUT IF I WILL USE INBUILT FUCTION THEN HOW CAN I KNOW WHICH PIN OF LCD AT WHICH PORT CONECTD SO IF I WANT TO KNOW ABOUT THE FUCTION DESCRIPTION THEN HOW CAN I KNOW

    February 9, 2014 at 1:20 pm #10986
    Ashutosh Bhatt
    Participant

    from your code i can say you want to use header file lcd.h. 

    if you are including this header file no need to write any lcd functions in code. you can just write the neame of the function with parameters. it will be called from header file. 

    to see the pin details open lcd.h file in notepad. the pins are define as macro. same as you have define in your program on top.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What is involved to convert a small town to fiber optic? December 13, 2025
  • Measuring controller current output with a meter December 13, 2025
  • Oshonsoft MSSP simulation question December 13, 2025
  • Droplet1 December 12, 2025
  • Help to Identify capacitor fault December 12, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise