Controlling an HD44780 LCD by ATTiny2313 via AVR-GCC

  • Thread starter whatry109
  • Start date
  • Tags
    Lcd
In summary, the author found a way to control a -style LCD display from an ATTiny2313 using code found on Martin Thomas' website.
  • #1
whatry109
3
1
After a day of tinkering I finally figured out how to control a -style LCD display from an ATTiny2313 ( ATTiny2313 Datasheet )class ATMEL AVR microcontroller. There are a lot of websites out there claiming to show you how to do this on similar AVRs. I tried about 10 of them and, intriguingly, only one of them worked! I don’t know if it’s user error, or an incompatibility of the ATTiny2313 running code written for an ATMega8, but since it took me so long to get this right I decided to share it on the internet for anyone else having a similar struggle. First, the results:

attiny_2313_lcd_hd44780-525x393.jpg

You might recognize this LCD panel from some PC parallel port / LCD interface projects I worked on about 5 years ago. It’s a 20-column, 2-row, 8-bit parallel character LCD. This means that ranter than telling each little square to light up to form individual letters, you can just output text to the microcontroller embedded in the display and it can draw the letters, move the cursor, or clear the screen.

attiny_2313_lcd_hd44780_2-525x534.jpg

As you can see this thing is pretty easy to wire-up to the ATTiny2313. These are the connections I made:
Code:
LCD1 -> GND

LCD2 -> +5V

LCD3 (contrast) -> GND

LCD4 (RS) -> AVR D0 (pin2)

LCD5 (R/W) -> AVR D1 (pin3)

LCD6 (ES) -> AVR D2 (pin6)

LCD 11-14 (data) -> AVR B0-B3 (pins 12-15)

The code I used to FINALLY allow me to control this LCD from the ATTiny2313 was found on Martin Thomas’ page. I included the .h and .c files and successfully ran the following program (with great results) on my AVR. The internal RC clock works, and supposedly any external clock (<8MHz) should work too.
Code:
// THIS THE TEST PROGRAM "main.c"

// ATTiny2313 / HD44780 LCD INTERFACE

#include <stdlib.h>

#include <avr/io.h>

#include <util/delay.h>

#include "lcd.h"

#include "lcd.c"int main(void)

{

    int i=0;

    lcd_init(LCD_DISP_ON);

    lcd_clrscr();

    lcd_puts("ATTiny 2313 LCD Demo");

    lcd_puts("  www.SWHarden.com  ");

    _delay_ms(1000);

    lcd_clrscr();

    for (;;) {

        lcd_putc(i);

        i++;

        _delay_ms(50);

    }

}

// THIS IS PART OF MY INCLUDED "lcd.h"

// THE WIRING CHART DESCRIBED IN THIS BLOG ENTRY

// IS MATCHED TO THE VALUES DISPLAYED BELOW

#define LCD_PORT         PORTB        /**< port for the LCD lines   */

#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */

#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */

#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */

#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */

#define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */

#define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */

#define LCD_DATA2_PIN    2            /**< pin for 4bit data bit 2  */

#define LCD_DATA3_PIN    3            /**< pin for 4bit data bit 3  */

#define LCD_RS_PORT      PORTD     /**< port for RS line         */

#define LCD_RS_PIN       0            /**< pin  for RS line         */

#define LCD_RW_PORT      PORTD     /**< port for RW line         */

#define LCD_RW_PIN       1            /**< pin  for RW line         */

#define LCD_E_PORT       PORTD     /**< port for Enable line     */

#define LCD_E_PIN        2            /**< pin  for Enable line     */// AND A LITTLE LOWER, I CHANGED THIS LINE TO 4-BIT MODE

#define LCD_FUNCTION_8BIT     0      /*   DB4: set 8BIT mode (0->4BIT mode) */
 
  • Like
Likes berkeman
Engineering news on Phys.org
  • #2
So there you have it! I hope this helps someone out there – even if it’s just a reminder to save your work so you don’t have to start all over again. Thanks for reading!
 

1. How do I connect an HD44780 LCD to an ATTiny2313 microcontroller?

The HD44780 LCD can be connected to an ATTiny2313 microcontroller using 6 pins: Vcc, Gnd, RS, RW, E, and D4-D7. These pins can be connected directly to the corresponding pins on the microcontroller, or using a breadboard or PCB.

2. Can I use AVR-GCC to program the ATTiny2313 for controlling the HD44780 LCD?

Yes, AVR-GCC is a popular and widely used compiler for programming AVR microcontrollers, including the ATTiny2313. It is compatible with most popular programming environments and can be used to write code for controlling the HD44780 LCD.

3. What is the purpose of the E pin on the HD44780 LCD?

The E (enable) pin on the HD44780 LCD is used to enable or disable the LCD's read/write operations. It acts as a control signal for the LCD, allowing data to be read from or written to the LCD.

4. How can I display characters on the HD44780 LCD using the ATTiny2313?

To display characters on the HD44780 LCD, you will need to send commands and data to the LCD using the RS (register select) and RW (read/write) pins. These commands and data can be sent using the appropriate functions in your AVR-GCC code. You will also need to configure the LCD for your specific display settings, such as number of lines and character size.

5. Is it possible to use an HD44780 LCD with an ATTiny2313 without using AVR-GCC?

Yes, it is possible to use an HD44780 LCD with an ATTiny2313 without using AVR-GCC. Other programming languages and environments such as Arduino, Python, and C++ can also be used to program the ATTiny2313 for controlling the LCD. However, AVR-GCC is a popular and widely used option that offers good compatibility and support for this microcontroller and LCD combination.

Similar threads

  • Electrical Engineering
Replies
5
Views
2K
  • Electrical Engineering
Replies
11
Views
7K
Replies
5
Views
3K
  • Electrical Engineering
Replies
6
Views
1K
Replies
2
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Electrical Engineering
Replies
2
Views
2K
  • Electrical Engineering
Replies
27
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top