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 / program for 4 bit lcd interface with 89s52

program for 4 bit lcd interface with 89s52

|

Microcontroller › 8051 › program for 4 bit lcd interface with 89s52

  • This topic has 3 replies, 3 voices, and was last updated 9 years ago by Anonymous.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • April 23, 2016 at 11:14 am #4428
    Akshay
    Participant

    Hii friends,

    I am working on the project of DAS. In that case I designed all the circuit hardwere, but i m troubling with lcd output.

    I connected the LCD in this manner using PORT 0

    LCD pines : RS – P0.1 ;| R/W – P0.2 ||; EN – P0.3 ;|| DB4 – P0.4 ;|| DB5 – P0.5 ||DB6 – P0.6  ||AND||  DB7 – P0.7

    Can u please help to code for this.

    I found lots of codes in running mode, but anyone can't help for my case.and also tell the problem why codes are not working.

     

    April 24, 2016 at 8:44 am #13890
    Ashutosh Bhatt
    Participant

    you can find many readymade codes for LCD interfacing in 4 bit mode just make change as per ur pin connections and it should work

    May 20, 2016 at 11:42 am #13931
    Anonymous
    Guest

    hi akshay,

            here below you can find 4-bit lcd C prgm code.

     

    /*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
     
    LCD clear initialization:
     
    ===================
     
    This is the sub-routine to initialise the lcd to 4bit. this has more advantage
     
    than the 8-bit lcd. One of the advantage is using less pins compared to 8bit lcd.
     
    — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */
     
    void lcd_init() //LCD_INITIAL SUB-ROUTINE HEADER
     
    {
     
    cmd(0x01,0); // Lcd clear instruction
     
    cmd(0x02,0);
     
    cmd(0x30,0); // 8 bit initialisation
     
    cmd(0x32,0); // auxillary instruction for 4 bit lcd
     
    cmd(0x20,0); // 4 bit initialisation
     
    cmd(0x28,0); // 4 bit, 5×7 dot matrix
     
    cmd(0x0c,0); // display ON, cursor OFF
     
    cmd(0x80,0); // First row, first position
     
    }
     
    /*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
     
    4-bit lcd program sub routine:
     
    =========================
     
    This is the sub-routine to send data to the lcd. By seperating the 8bit data into
     
    4-4bits and send to lcd using 4-lcd data lines.
     
    — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */
     
    void cmd(char p,int q) // LCD COMMAND SUB-ROUTINE HEADER
     
    {
     
    char r; // Declaring the character variable
     
    rs=q; // selecting whether the hex is command or data
     
    lcd=lcd&0xf0; // clearing the lcd's 4bit
     
    r=p>>4; // source data is rotated 4 times
     
    r=r&0x0f; // getting upper nibble seperately
     
    lcd=lcd|r; // moving the upper nibble to lcd
     
    e=1; // enabling lcd
     
    delay_us(20); // delay sub-routine is called for 7u.sec
     
    e=0; // disabling lcd
     
    lcd=lcd&0xf0; // clearing the lcd's 4bit
     
    r=p; // moving source data to 'r'
     
    p=p&0x0f; // getting lower nibble seperately
     
    lcd=lcd|p; // moving the lower nibble to lcd
     
    e=1; // enabling lcd
     
    delay_us(20); // delay sub-routine is called for 7u.sec
     
    e=0; // disabling lcd
     
    }
     
    /*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
     
    Sub-routine for to display the string in lcd :
     
    ===================================
     
    This is the sub-routine which simplifies the string to display in the lcd and
     
    make the user to prgm easier.this sub-routine includes displaying string, starting
     
    address and time spend to display each character.
     
    — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */
     
    void strg_cmd(char p[],char add,int u) // STRING FUNCTION SUB-ROUTINE HEADER
     
    {
     
    int i,j; // Declaring the int variables
     
    j=strlen(p); // measuring the string length
     
    cmd(add,0); // passing the starting address to lcd
     
    for(i=0;i<j;i++) // for loop continues until the last character
     
    {
     
    cmd(p,1); // cmd sub-routine is called
     
    delay_ms(u); // delay is called for each char to display
     
    }
     
    }
    May 20, 2016 at 11:49 am #13932
    Anonymous
    Guest
    /*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
     
    HEADER FILE DECLARATION:
     
    ========================
     
    — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */
     
    #include<REGX52.H>;
     
    #include<string.h>;
     
    /*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
     
    SFR AND PINS DECLARATION:
     
    ========================
     
    — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */
     
    sfr lcd=P0;  // 
     
    sbit e=P3^6;
     
    sbit rs=P3^7;
     
    /*– — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
     
    SUB-ROUTINE HEADER DECLARATION:
     
    ===============================
     
    — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */
     
    void lcd_init(void);
     
    void cmd(char,int);
     
    void strg_cmd(char p[],char,int);
     
     
    note: here R/W pin of lcd is not used, so it is not mentioned above.
     
    contact: cbiinfrastructures3502gmail.com, [email protected] 
  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Curved lines in PCB design June 15, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 15, 2025
  • using a RTC in SF basic June 15, 2025
  • PIC KIT 3 not able to program dsPIC June 15, 2025
  • Siemens large industrial PLC parts June 15, 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