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 / hello sir i modified the 4

hello sir i modified the 4

|

Microcontroller › AVR › Interfacing LCD with ATMEGA 8 › hello sir i modified the 4

March 1, 2013 at 11:15 am #9212
prajwal
Participant

hello sir i modified the 4 bit mode code to atmega 8. the code is like this

 

 

#include<avr/io.h>
#include<util/delay.h>
#include<inttypes.h>
 
#define rs PB0    
#define rw PB1
#define en PB2
 
void lcd_init();
void dis_cmd(char);
void dis_data(char);
void lcdcmd(char);
void lcddata(char);
 
int main(void)
{
unsigned char data0[11]=”ENGINEERS”;
unsigned char data1[10]=”GARAGE”;
 
int i=0;
DDRD=0xFF;
lcd_init();
while(data0!=’’)
{
dis_data(data0
);
_delay_ms(200);
i++;
}
 
dis_cmd(0xC5);
 
i=0;
while(data1
!=’’)
{
dis_data(data1
);
_delay_ms(200);
i++;
}
 
while(1);
}
 
 
 
void lcd_init()    // fuction for intialize
{
dis_cmd(0x02);    // to initialize LCD in 4-bit mode.
dis_cmd(0x28);    //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
dis_cmd(0x0C);
dis_cmd(0x06);
dis_cmd(0x83);
}
 
void dis_cmd(char cmd_value)
{
char cmd_value1;
cmd_value1 = cmd_value & 0xF0;    //mask lower nibble because PA4-PA7 pins are used.
lcdcmd(cmd_value1);    // send to LCD
 
cmd_value1 = ((cmd_value<<4) & 0xF0);    //shift 4-bit and mask
lcdcmd(cmd_value1);    // send to LCD
}    
 
 
void dis_data(char data_value)
{
char data_value1;
data_value1=data_value&0xF0;
lcddata(data_value1);
 
data_value1=((data_value<<4)&0xF0);
lcddata(data_value1);
}
 
void lcdcmd(char cmdout)
{
PORTD=cmdout;
PORTD&=~(1<<rs);
PORTD&=~(1<<rw);
PORTD|=(1<<en);
_delay_ms(1);
PORTD&=~(1<<en);
}
 
void lcddata(char dataout)
{
PORTD=dataout;
PORTD|=(1<<rs);
PORTD&=~(1<<rw);
PORTD|=(1<<en);
_delay_ms(1);
PORTD&=~(1<<en);
}

 

But the lcd is not displaying anything but just black boxes are appearing on LCD first row

 

Help pls…

RSS Recent Posts

  • Telegram Based Alarm - Sensor cable protection May 21, 2025
  • Chinese Tarrifs – 104%!?! May 21, 2025
  • An Update On Tarrifs May 21, 2025
  • Tariff Updates from JLCPCB as of Today May 21, 2025
  • Solar lighting motion detector 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