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 / m having same problem with

m having same problem with

|

Microcontroller › AVR › problem regarding interfacing LCD using ATMEGA16 code by CHINMAY CHINARA › m having same problem with

December 6, 2011 at 9:40 am #6912
Sagar
Participant

m having same problem with JHD162A ATmega16

heres the code…

 

//#define F_CPU 16000000

#include <avr/io.h>
//#include <util/delay.h>

#define lcd_data PORTB

/*

PD.0=rs
PD.1=rw
PD.2=en

*/

void lcdbusy() //function to monitor d7th bit (busy flag)
{
    DDRB=0x7f;// this will make msb of portb to input

    PORTD=0xfe;// rs=0 rw=1 en=1, rw=1->read from lcd

    while(PINB>>7) //move the msb to lsb
    {

        PORTD |=0x04; //en-> from low to high
        PORTD &=0xfb; //en-> from high to low
    }

    DDRB=0xff;//make PORTB for output

}

void initlcd()
{
    DDRD=0xff; //PORTD as output
    DDRB=0xff; //portb as output
    
    lcd_data=0x38; //8 bit,5×7 dots
    PORTD=0xfc; //rs=0 rw=0 en=1, 0xfc where c=1100
    PORTD=0xf8; //rs=0 rw=0 en=0, 0xf8 where 8=1000, frm en->high to low

    lcdbusy(); // w8 b4 executing next command

    lcd_data=0x0f; //cursor blinking display on
    PORTD=0xfc;
    PORTD=0xf8;

    lcd_data=0x01; // clear lcd
    PORTD=0xfc;
    PORTD=0xf8;

    lcdbusy();

    lcd_data=0x06; //entry mode
    PORTD=0xfc;
    PORTD=0xf8;

    lcdbusy();
}

void lcdcmd(unsigned char ch)
{
    lcd_data=ch;
    PORTD=0xfc;
    PORTD=0xf8;

    lcdbusy();
}

void lcdchar(unsigned char ch)
{
    lcd_data=ch;
    PORTD=0xfd; // 0xfd where d=1101 rs=w rw=0 en=1
    PORTD=0xf9; //9=1001 rs=1 rw=0 en=0, en-> from high to low
    lcdbusy();
}

void lcdstring(char *str)
{
    while(*str)
    {
        lcdchar(*str);
        str++;
    }
}

int main()
{
    initlcd();
    lcdcmd(0x80);// move cursor to 1st line 1st column
    lcdstring(“Welcome ATmega16 !”);

    while(1);

    return 0;

}

 

 

m i missing something ?

RSS feed: Recent Posts Recent Posts

  • Advice for an ESP32 Soil Tensiometer project with 5V sensors September 9, 2026
  • Marantz SR4500 – CS49400 DSP reverse-engineering / custom active crossover September 9, 2026
  • How does an air tag work? September 9, 2026
  • Cheap ways to link 5 Keithley units and 4 BNC units? September 8, 2026
  • Sony KV-29VL40 - 4 Blink error - IC001 Pin 17 high September 8, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 Arrowfly 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 Arrowfly
Privacy Policy | Advertising

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