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 / Interfacing LCD with ATMEGA 8

Interfacing LCD with ATMEGA 8

|

Microcontroller › AVR › Interfacing LCD with ATMEGA 8

  • This topic has 4 replies, 2 voices, and was last updated 12 years, 9 months ago by AJISH ALFRED.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • February 28, 2013 at 3:50 pm #2146
    prajwal
    Participant

    Hello friends,

     

    Can i use the code LCD interfacing provided in Engineers garage for ATMEGA 8?

     

    The circuit is given for ATMEGA 16… Should i modify the code fot ATMEGA 8?

     

    Pls help…

    February 28, 2013 at 4:42 pm #9204
    AJISH ALFRED
    Participant

    Hi Prajwal,

    Which code are you using, 4-bit mode or 8-bit mode?

    Take the case of 4-bit mode, the LCD is entirely connected to portA of atmega16, but in atmega8 there is no portA.

    You have to modify your code according to the microcontroller you are using.

    March 1, 2013 at 2:21 am #9207
    prajwal
    Participant

    Thanks for the reply sir :) I will try it and post you back soon

    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…

    March 4, 2013 at 8:09 am #9233
    AJISH ALFRED
    Participant

    So you are using PORTD right?

    Then change the followinh lines:

    #define rs PB0    
    #define rw PB1
    #define en PB2

     

    as follows

     

    #define rs PD0

    #define rw PD1

    #define en PD2

     

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

RSS Recent Posts

  • 1.1kV Cockroft-Walton 200J Capacitor Charger December 4, 2025
  • Samba ( not the dance) December 4, 2025
  • mechanism to shutdown feeding when sensor temperature rises December 4, 2025
  • Looking for a ~1″ Analog CVBS Micro-Display — Any Sources? December 4, 2025
  • Annex32 Basic for ESP Micros December 4, 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