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 / Libraries

Libraries

|

Microcontroller › 8051 › Libraries

  • This topic has 1 reply, 2 voices, and was last updated 10 years, 4 months ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • July 11, 2015 at 2:42 pm #3762
    Aaron
    Participant

    I am using the Keil V3 IDE to switch I created a function that helps me set the cursor on the 20×4 LCD.

    The function is called Setcursor(x,y) to which x and y correspond to the position on the LCD. 

    Can someone please help me/guide me into making this function into a library?

    Function code to anyone who wants to use this in his projects.

    sbit RS=P2^0;
    sbit RW=P2^1;
    sbit E=P2^2;
    sbit sw=P2^4;
     
    bit on=0xff;
    bit off=0x00;
    void SetCursor (int x, int y)
    {
    RS=off;
    if(y>=5)
    {
    y=4;
    }
     
    if(x>=20) 
    {
    x=19;
    }
     
    if(y==1)
    {
    int i;
    int Line1=0x80;
    for(i=0;i<x;i++)
    {
    Line1 += 0x01;
    }
    P0=Line1;
    E=on;
    delay();
    E=off;
    delay();
    }
     
    if(y==2)
    {
    int ii;
    int Line2=0xC0;
    for(ii=0;ii<x;ii++)
    {
    Line2 += 0x01;
    }
    P0=Line2;
    E=on;
    delay();
    E=off;
    delay();
    }
     
    if(y==3)
    {
    int iii;
    int Line3=0x94;
    for(iii=0;iii<x;iii++)
    {
    Line3 += 0x01;
    }
    P0=Line3;
    E=on;
    delay();
    E=off;
    delay();
    }
     
    if(y==4)
    {
    int iv;
    int Line4=0xD4;
    for(iv=0;iv<x;iv++)
    {
    Line4 += 0x01;
    }
    P0=Line4;
    E=on;
    delay();
    E=off;
    delay();
    }
     
    }
     
    void delay(void)
    {
    int i;
    int l;
    for(i=0;i<25;i++)
    {
    for(l=0;l<255;l++)
    {
    }
    }
    }
     
     
    July 12, 2015 at 12:53 pm #13058
    Ashutosh Bhatt
    Participant

    to set line the code is 0x80 and0xC0

    to set column you have to set number from 0 to F like 0x81, 0xC4 etc

    read the LCD datasheet for furthur information

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

RSS Recent Posts

  • WTB: "The Theory Of Servicing AM, FM, And FM Receivers" by Clarence R. Green and Robert M. Bourque November 10, 2025
  • Anyone In The US Ordered From AliExpress Recently? November 10, 2025
  • Calculation of A Class amplifier November 10, 2025
  • strange laptop problem November 10, 2025
  • restarting this Christmas project November 10, 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