Thursday, March 30, 2023

Moving Message Display On LCD

Here is an AVR based moving message display that uses a 16x2 LCD display incorporating HD44780. The 16x2 LCD can display 16 characters per line and there are two such lines. -- By SANI THEO

- Advertisement -
 

The delay or waiting instruction can be implemented easily in C language.

In C programing, the delay is called using the delay( ) function. For instance, delay(16000) command gives a delay of 16 milliseconds.

Initialising the LCD

Before using the LCD, it must be initialised and configured. This is accomplished by sending a number of initialisation instructions to the LCD.

- Advertisement -

In WINAVR GCC programming given here, the first instruction defines the crystal frequency used in the circuit. This is followed by a standard header file for AVR device-specific I/O definitions and header file for incorporating program space string utilities. The initialisation steps in movm.c file are as follows:

 [stextbox id=”grey”]#define F_CPU 16000000
#include
#include
#include
#include “lcd2.h”
#define RATE 250[/stextbox]

Clearing the display

When the LCD is first initialised, the screen should automatically be cleared by the HD44780 controller. This helps to clear the screen of any unwanted text. Clearing the screen also ensures that the text being displayed on the LCD is the one intended for display. An LCD command exists in ‘Assembly’ to accomplish this function of clearing the screen. Not surprisingly, the AVR GCC function is flexible and easy to implement.

Refer the code given below:
[stextbox id=”grey”]lcd_init(LCD_DISP_ON);
lcd_clrscr();[/stextbox]

Here the first line is for LCD initialisation (turn on the LCD) with cursor ‘off.’ The second line clears the display routine to clear the LCD screen.

Writing text to the LCD

To write text to the LCD, the desired text is put in the memory using the char string[ ] function as follows:

 [stextbox id=”grey”]char string[] PROGMEM=”WECOME TO
ELECTRONICS FOR YOU – NEW DELHI”;[/stextbox]

The program makes this text scroll on the first line and then the second line of the LCD. The speed of scrolling the text on the LCD screen is defined by “# define RATE 250” in the beginning of the movm.c code. To start with, first the LCD screen is cleared and then the location of the first character to appear on the screen is defined. Getting the text from the program memory and then scrolling it on the LCD screen continuously is achieved using the following code:

 [stextbox id=”grey”]

while(j<=(len-1))
{
lcd_clrscr();
lcd_gotoxy(0,0);

for(k=0,i=j;(k<16) && ( pgm_
read_byte(&string[i])!=’\0’
);k++,i++)
{
lcd_putc(pgm_read_
byte(&string[i]));
}

WaitMs(RATE);
j++;
}

[/stextbox]

Compiling and programming

Compiling the movm.c to generate the movm.hex code is simple. Open AVR Studio4 from the desktop and select new project from ‘Project’ menu option. Select AVR GCC option and enter the project name. Next, select ‘AVR Simulator’ and click ‘Ok’ button.

First, copy the three codes (movm.c, lcd2.c and lcd2.h) to your computer. Import the movm.c and lcd2.c files into ‘Source Files’ option on the left side of the screen. Next, import the lcd2.h file into ‘Header Files’ option. Select the device as ATmega16 and tick the box against ‘Create Hex’ option in the project configuration window. Now click ‘Rebuild All’ option in ‘Build’ menu. If the code is compiled without error, the movm.hex code is generated automatically under ‘Default’ folder of the project folder.

4B8_Part-List-new

To burn the hex code into ATmega16, any standard programmer supporting ATmega16 device can be used. There are four different AVR programming modes:
1. In-system programming (ISP)
2. High-voltage programming
3. Joint test action group (JTAG) programming
4. Program and debug interface programming

- Advertisement -

3 COMMENTS

SHARE YOUR THOUGHTS & COMMENTS

 
 

What's New @ Electronicsforu.com?

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Tech Contests