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 9 years, 9 months ago by Prabakaran P M.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • July 11, 2015 at 2:42 pm #3761
    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++)
    {
    }
    }
    }
     
     
    August 3, 2015 at 12:52 pm #13131
    Prabakaran P M
    Participant

    save the above file in xxxx.h extension. call this function in the new project using <xxxx.h>

    Use  Setcursor(x,y) to call the function in new code.

     

  • 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

  • Refrigeration System Reliability in Harsh Aussie Conditions May 21, 2025
  • Chinese Tarrifs – 104%!?! May 21, 2025
  • can a AT89C51 be used as a rom? May 21, 2025
  • Telegram Based Alarm - Sensor cable protection May 21, 2025
  • An Update On Tarrifs May 21, 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