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 / LCD Library for AVR Atmega32

LCD Library for AVR Atmega32

|

Microcontroller › AVR › LCD Library for AVR Atmega32

  • This topic has 1 reply, 2 voices, and was last updated 11 years, 9 months ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • August 11, 2013 at 5:28 pm #2588
    Shishir K Chakravarthy
    Participant
    //An LCD library for interfacing Atmega 32 to a 16X2 LCD…
    //Author: Shishir K Chakravarthy ~Blitz
    //Interface manual:
    //Enable –>           PORTD PIN0
    //Register Select –>  PORTD PIN1
    //Read/Write –>       PORTD PIN2
    //D0 –> PORTB PIN0 |         
    //D1 –> PORTB PIN1   |
    //D2 –> PORTB PIN2 |
    //D3 –> PORTB PIN3 | for 8 bit data
    //D4 –> PORTB PIN4 |
    //D5 –> PORTB PIN5 |
    //D6 –> PORTB PIN6 |
    //D7 –> PORTB PIN7 |
    //Commands :
    //LCD_INIT(); –> Initializes the LCD for Display PS:Cursor OFF
    //LCD_WRITE(“string”); –> To display characters
    //LCD_WRITE_NUM(value,width); –>To display number of specified width
    //LCD_SETCURSOR(x,y); –>To set cursor coordinates
    //LCD_CLEAR(); –>Erases LCD memory
    //Enjoy!!!
     
     
    #ifndef m32_16X2_LCD_H_
    #define m32_16X2_LCD_H_
     
    #include <avr/io.h>
    #include <util/delay.h>
    #include <stdlib.h>
     
    #define DATADIR_PORTB DDRB
    #define DATADIR_PORTD DDRD
    #define LCD_CONTROL PORTD
    #define LCD_DT PORTB
    #define EN PIND0
    #define RS PIND1
    #define RW PIND2
     
    void LCD_INIT();
    void LCD_CMD(unsigned char);
    void LCD_DATA(unsigned char);
    void LCD_WRITE(char *string);
    void LCD_WRITE_NUM(unsigned char, unsigned char);
    void LCD_SETCURSOR(uint8_t, uint8_t);
    void LCD_CLEAR();
    void LCD_BUSY_CHECK();
    void LCD_FLASH();
     
    unsigned char InitColumn[2]={0,64};
     
    void LCD_INIT()
    {
    DATADIR_PORTD |= (1<<EN|1<<RS|1<<RW);
    DATADIR_PORTB = 0xFF;
    _delay_ms(20);
     
    LCD_CMD(0x01);
    _delay_ms(2);
    LCD_CMD(0x38);
    _delay_us(50);
    LCD_CMD(0x0C);
    _delay_us(50);
    LCD_CMD(0x06);
    _delay_us(50);
    }
     
    void LCD_CMD(unsigned char cmd)
    {
    LCD_CHECK_BUSY();
    LCD_DT = cmd;
    LCD_CONTROL &=~((1<<RW)|(1<<RS));
    LCD_FLASH();
    LCD_DT = 0;
    }
     
    void LCD_DATA(unsigned char data)
    {
    LCD_CHECK_BUSY();
    LCD_DT = data;
    LCD_CONTROL &=~(1<<RW);
    LCD_CONTROL |=1<<RS;
    LCD_FLASH();
    LCD_DT = 0;
    }
     
    void LCD_WRITE(char *string)
    {
    while(*string>0)
    {
    LCD_DATA(*string++);
    _delay_us(50);
    }
    }
     
    void LCD_WRITE_NUM(unsigned char val, unsigned char width)
    {
    unsigned char array[width];
    itoa(val,array,10);
    LCD_WRITE(array);
    _delay_us(50);
    }
     
    void LCD_SETCURSOR(uint8_t x, uint8_t y)
    {
    LCD_CMD(0x80 + InitColumn[y] + x);
    _delay_us(50);
    }
     
    void LCD_CLEAR()
    {
    LCD_CMD(0x01);
    _delay_us(50);
    }
     
    void LCD_CHECK_BUSY()
    {
    DATADIR_PORTB = 0;
    LCD_CONTROL |= 1<<RW;
    LCD_CONTROL &=~(1<<RS);
     
    while(LCD_DT >=0x80)
    {
    LCD_FLASH();
    }
    DATADIR_PORTB = 0xFF;
    }
     
    void LCD_FLASH()
    {
    LCD_CONTROL |=1<<EN;
    asm volatile(“nop”);
    asm volatile(“nop”);
    LCD_CONTROL &=~(1<<EN);
    }
     
    #endif /*m32_16X2_LCD_H_*/
     
     
    August 12, 2013 at 5:03 am #10314
    AJISH ALFRED
    Participant

    Nice, and thanks for sharing.

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

RSS Recent Posts

  • Developing DC UPS module May 16, 2025
  • An Update On Tarrifs May 16, 2025
  • Trying to use a L9110s motor driver chip May 16, 2025
  • I want to make a CRT with some modifications But i have no Idea where to start May 16, 2025
  • Funny Images Thread! May 16, 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