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 / Replies / hey gana.. reffer to this

hey gana.. reffer to this

|

Projects › Projects › About LCD 2×16 › hey gana.. reffer to this

April 4, 2011 at 2:30 am #5869
romel emperado
Participant

hey gana..

 

reffer to this sample code.. it’s working.. I’ve using this code of my projects.. this is 4bit mode

 

// 4 bit example

#include<reg51.h>

#define LCD P1
#define LCD_EN        0x80
#define LCD_RS        0x20
                     
//LCD Commands        

#define LCD_SETMODE       0x04
#define LCD_SETVISIBLE       0x08
#define LCD_SETFUNCTION       0x28
#define LCD_SETDDADDR       0x80

void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char*);

void  main (void)
{
lcd_init();
lcd_cmd(0x80);            // ist line address
lcd_str(”     i love  “);
lcd_cmd(0xC0);              // 2nd line address
lcd_str(“Romel emperado”);
while(1);
}

void delayus(unsigned char delay){
    while(delay–);
}

void delayms(unsigned char delay){
    while(delay–)
        delayus(149);
}

void lcd_reset()
{
    LCD = 0xFF;
    delayms(40);
    LCD = 0x03+LCD_EN;
    LCD = 0x03;
    delayms(40);
    LCD = 0x03+LCD_EN;
    LCD = 0x03;
    delayms(5);
    LCD = 0x03+LCD_EN;
    LCD = 0x03;
    delayms(5);
    LCD = 0x02+LCD_EN;
    LCD = 0x02;
    delayms(5);
}

void lcd_init ()
{
    lcd_reset();
    lcd_cmd(LCD_SETFUNCTION);                    // 4-bit mode – 1 line – 5×7 font.
    lcd_cmd(LCD_SETVISIBLE+0x04);                // Display no cursor – no blink.
    lcd_cmd(LCD_SETMODE+0x02);                   // Automatic Increment – No Display shift.
    lcd_cmd(LCD_SETDDADDR);                      // Address DDRAM with 0 offset 80h.
 }

 void lcd_cmd (char cmd)
{
    LCD = ((cmd >> 4) & 0x0F)|LCD_EN;
    LCD = ((cmd >> 4) & 0x0F);

    LCD = (cmd & 0x0F)|LCD_EN;
    LCD = (cmd & 0x0F);

    delayus(250);
    delayus(250);
}

void lcd_data (unsigned char dat)
{
    LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
    LCD = (((dat >> 4) & 0x0F)|LCD_RS);
    
    LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
    LCD = ((dat & 0x0F)|LCD_RS);

    delayus(250);
    delayus(250);
}

void lcd_str (unsigned char *str)
{
    while(*str){
        lcd_data(*str++);
    }
}

RSS Recent Posts

  • Siemens large industrial PLC parts June 15, 2025
  • Parts required for a personal project June 15, 2025
  • Cant log in to Easy PC forum June 15, 2025
  • Failure of polypropylene motor-run capacitors June 15, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz 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