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 / interfacing 8×2 lcd with pic18f883

interfacing 8×2 lcd with pic18f883

|

Microcontroller › PIC › interfacing 8×2 lcd with pic18f883

  • This topic has 5 replies, 2 voices, and was last updated 10 years, 11 months ago by kiran kumar.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • July 31, 2014 at 2:59 pm #3199
    kiran kumar
    Participant

    Hi,

        

         I am trying to run a sample code of 16×2 lcd with pic18f887 by making some changes with respect to my own circuit like interfacing 8×2 lcd with pic18f883 using 4bit mode.

     

    Things completed: changed pin config, XTAL_FREQ,  with respect to my micro controller and also successfully compiled

     

    Problem faced : blank (no) output.

     

    please help me .

     

    KIRAN KUMAR

     

     

    August 1, 2014 at 4:22 am #11958
    kiran kumar
    Participant

    *******************MAIN.C*****************************

     

     

    #include<htc.h>

    __CONFIG(LVP_OFF & FCMEN_OFF & IESO_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
    #define RS RA5
    #define EN RA4
    #define D4 RC0
    #define D5 RC1
    #define D6 RC2
    #define D7 RC3
     
     
    #define _XTAL_FREQ 4000000
    #include “lcd.h”
     
     
     
    void main()
    {
     int i;
      TRISA = 0X00;
      TRISC = 0x00;
      Lcd4_Init();
      while(1)
      {
        Lcd4_Set_Cursor(1,1);
        Lcd4_Write_String(“electroSome LCD Hello World”);
        for(i=0;i<15;i++)
        {
          __delay_ms(1000);
          Lcd4_Shift_Left();
        }
        for(i=0;i<15;i++)
        {
          __delay_ms(1000);
          Lcd4_Shift_Right();
        }
        Lcd4_Clear();
        Lcd4_Set_Cursor(2,1);
    //Lcd4_Write_String(“electroSome LCD Hello World”);
        Lcd4_Write_Char(‘e’);
        Lcd4_Write_Char(‘S’);
        __delay_ms(2000);
      }
    }
     
     
     
    *********************************LCD.H*******************************************
     
     
     
     
    //LCD Functions Developed by electroSome
     
     
     
    #ifndef D0
    #define D0 RB0
    #define D1 RB1
    #define D2 RB2
    #define D3 RB3
    #endif
     
     
    //LCD 8 Bit Interfacing Functions
    void Lcd8_Port(char a)
    {
    if(a & 1)
    D0 = 1;
    else 
    D0 = 0;
     
    if(a & 2)
    D1 = 1;
    else
    D1 = 0;
     
    if(a & 4)
    D2 = 1;
    else
    D2 = 0;
     
    if(a & 8)
    D3 = 1;
    else
    D3 = 0;
     
    if(a & 16)
    D4 = 1;
    else
    D4 = 0;
     
    if(a & 32)
    D5 = 1;
    else
    D5 = 0;
     
    if(a & 64)
    D6 = 1;
    else 
    D6 = 0;
     
    if(a & 128)
    D7 = 1;
    else
    D7 = 0;
    }
    void Lcd8_Cmd(char a)
    { 
      RS = 0;             // => RS = 0
      Lcd8_Port(a);             //Data transfer
      EN  = 1;             // => E = 1
      __delay_ms(5);
      EN  = 0;             // => E = 0
    }
     
    Lcd8_Clear()
    {
     Lcd8_Cmd(1);
    }
     
    void Lcd8_Set_Cursor(char a, char b)
    {
    if(a == 1)
     Lcd8_Cmd(0x80 + b);
    else if(a == 2)
    Lcd8_Cmd(0xC0 + b);
    }
     
    void Lcd8_Init()
    {
    Lcd8_Port(0x00);
    RS = 0;
    __delay_ms(25);
    ///////////// Reset process from datasheet /////////
      Lcd8_Cmd(0x30);
    __delay_ms(5);
      Lcd8_Cmd(0x30);
    __delay_ms(15);
      Lcd8_Cmd(0x30);
      /////////////////////////////////////////////////////
      Lcd8_Cmd(0x38);    //function set
      Lcd8_Cmd(0x0C);    //display on,cursor off,blink off
      Lcd8_Cmd(0x01);    //clear display
      Lcd8_Cmd(0x06);    //entry mode, set increment
    }
     
    void Lcd8_Write_Char(char a)
    {
       RS = 1;             // => RS = 1
       Lcd8_Port(a);             //Data transfer
       EN  = 1;             // => E = 1
      __delay_ms(4);
       EN  = 0;             // => E = 04
    }
     
    void Lcd8_Write_String(char *a)
    {
    int i;
    for(i=0;a!=’’;i++)
    Lcd8_Write_Char(a);
    }
     
    void Lcd8_Shift_Right()
    {
    Lcd8_Cmd(0x1C);
    }
     
    void Lcd8_Shift_Left()
    {
    Lcd8_Cmd(0x18);
    }
    //End LCD 8 Bit Interfacing Functions
     
    //LCD 4 Bit Interfacing Functions
     
    void Lcd4_Port(char a)
    {
    if(a & 1)
    D4 = 1;
    else 
    D4 = 0;
     
    if(a & 2)
    D5 = 1;
    else
    D5 = 0;
     
    if(a & 4)
    D6 = 1;
    else
    D6 = 0;
     
    if(a & 8)
    D7 = 1;
    else
    D7 = 0;
    }
    void Lcd4_Cmd(char a)
    { 
    RS = 0;             // => RS = 0
    Lcd4_Port(a);
    EN  = 1;             // => E = 1
      __delay_ms(4);
      EN  = 0;             // => E = 0
    }
     
    Lcd4_Clear()
    {
    Lcd4_Cmd(0);
    Lcd4_Cmd(1);
    }
     
    void Lcd4_Set_Cursor(char a, char b)
    {
    char temp,z,y;
    if(a == 1)
    {
     temp = 0x80 + b;
    z = temp>>4;
    y = (0x80+b) & 0x0F;
    Lcd4_Cmd(z);
    Lcd4_Cmd(y);
    }
    else if(a == 2)
    {
    temp = 0xC0 + b;
    z = temp>>4;
    y = (0xC0+b) & 0x0F;
    Lcd4_Cmd(z);
    Lcd4_Cmd(y);
    }
    }
     
    void Lcd4_Init()
    {
    Lcd4_Port(0x00);
       __delay_ms(20);
      Lcd4_Cmd(0x03);
    __delay_ms(5);
      Lcd4_Cmd(0x03);
    __delay_ms(11);
      Lcd4_Cmd(0x03);
      /////////////////////////////////////////////////////
      Lcd4_Cmd(0x02);    
    Lcd4_Cmd(0x02);
      Lcd4_Cmd(0x08);
    Lcd4_Cmd(0x00); 
    Lcd4_Cmd(0x0C);     
      Lcd4_Cmd(0x00);    
      Lcd4_Cmd(0x06);   
    }
     
    void Lcd4_Write_Char(char a)
    {
       char temp,y;
       temp = a&0x0F; 
       y = a&0xF0;
    RS = 1;             // => RS = 1
       Lcd4_Port(y>>4);             //Data transfer
    EN = 1;
    __delay_ms(5);
    EN = 0;
    Lcd4_Port(temp);
    EN = 1;
    __delay_ms(5);
    EN = 0;
    }
     
    void Lcd4_Write_String(char *a)
    {
    int i;
    for(i=0;a!=’’;i++)
    Lcd4_Write_Char(a);
    }
     
    void Lcd4_Shift_Right()
    {
    Lcd4_Cmd(0x01);
    Lcd4_Cmd(0x0C);
    }
     
    void Lcd4_Shift_Left()
    {
    Lcd4_Cmd(0x01);
    Lcd4_Cmd(0x08);
    }
    //End LCD 4 Bit Interfacing Functions
     
     
    PLEASE GIVE ME ANY SOLUTION
     
    August 1, 2014 at 6:42 am #11960
    Ashutosh Bhatt
    Participant

    everything seems OK.

    the problem may be the lcd.h file may not have been included

    or there may be some problem in initializing 4-bit LCD mode

    first try simple 8 bit mode then go for 4-bit mode

    August 1, 2014 at 12:01 pm #11967
    kiran kumar
    Participant

    Thank you for the reply Mr Bhatt, 

     

    Is there any change in command or code with respect to the 8×2 and 16×2?

     

    August 2, 2014 at 8:08 pm #11973
    Ashutosh Bhatt
    Participant

    the only change in displaying characters. all other things remains same

    August 4, 2014 at 10:26 am #11978
    kiran kumar
    Participant

    Thank you Mr Bhatt.

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

RSS Recent Posts

  • More fun with ws2812 this time XC8 and CLC July 16, 2025
  • Pic18f25q10 osccon1 settings swordfish basic July 16, 2025
  • Pickit 5 July 16, 2025
  • turbo jet fan - feedback appreciated. July 16, 2025
  • I Wanna build a robot July 16, 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