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 /   //Program to Display

  //Program to Display

|

Microcontroller › 8051 › black boxes on 16×2 LCD ›   //Program to Display

November 11, 2012 at 11:49 am #8738
Sajjad
Participant

 


//Program to Display string on LCD using AVR Microcontroller (ATmega16)

/*
LCD DATA port—-PORT B
signal port


PORT D
rs


PD0
rw


PD1
en


PD2
*/
 
#include<avr/io.h>
#include<util/delay.h>
 
#define LCD_DATA PORTB //LCD data port
 
#define ctrl PORTD
#define en PD2 // enable signal
#define rw PD1 // read/write signal
#define rs PD0 // register select signal
 
void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);
 
int main()
{
DDRB=0xff;
DDRD=0x07;
init_LCD(); // initialization of LCD
_delay_ms(50); // delay of 50 mili seconds
LCD_write_string(“EngineersGarage”); // function to print string on LCD
return 0;
}
 
void init_LCD(void)
{
LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
_delay_ms(1);
 
LCD_cmd(0x01); // clear LCD
_delay_ms(1);
 
LCD_cmd(0x0E); // cursor ON
_delay_ms(1);
 
LCD_cmd(0x80); // —8 go to first line and –0 is for 0th position
_delay_ms(1);
return;
}
 
void LCD_cmd(unsigned char cmd)
{
LCD_DATA=cmd;
ctrl =(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl =(0<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return;
}
 
void LCD_write(unsigned char data)
{
LCD_DATA= data;
ctrl = (1<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl = (1<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return ;
}
 
void LCD_write_string(unsigned char *str) //store address value of the string in pointer *str
{
int i=0;
while(str!=’’) // loop will go on till the NULL character in the string 
{
LCD_write(str); // sending data on LCD byte by byte
i++;
  }
return;
}

THIS IS THE CODE i am using. 
i have used the control pins and data pins according to code…

RSS Recent Posts

  • Projector focus circuit May 18, 2026
  • Relay question May 18, 2026
  • Phone Charger 5v to 12v May 17, 2026
  • reviving old swordfish program but? May 17, 2026
  • Assistance locating a 'trail' camera gadget, please ? May 16, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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