Circuit Diagram
Circuit Diagram
Circuit Diagram
Circuit description
Fig. 1 shows the circuit for AVR ATmega16-based moving-message display on an
LCD. It consists of an ATmega16 microcontroller, a 162 LCD, an SPI6 connector
and a power supply section.To derive the power supply for the circuit, 230V AC
mains is stepped down by a 9V, 250mA secondary transformer, rectified by
bridge rectifier module BR1A and filtered by capacitor C1. The voltage is
regulated by a 7805 regulator. LED1 glows to indicate the presence of power in
the circuit. The regulated 5V DC powers the entire circuit including SPI6
connector.
Port-C pins PC4 through PC7 of the microcontroller (IC2) are connected to data
lines D4 through D7 of the LCD. The LCD control linesread/write (R/W),
register-select (RS) and enable (E)are connected to PD6, PC2 and PC3 of IC2,
respectively.
Why AVR microcontroller? AVR is faster and more powerful than 8051
microcontroller, yet reasonably cheaper and in-circuit programmable. Most AVR
development software are free as these are Open Source. Moreover, discussions
and tutorials on the AVR family of processors are available on the Internet.
ATmega16 is a high-performance, low-power 8-bit AVR microcontroller. It has 16
kB of in-system self-programmable flash, 1 kB of internal SRAM, 512 bytes of
EEPROM, 328 general-purpose working registers and JTAG Interface (which
supports programming of flash, EEPROM, fuse and lock bits).
twice.
Controlling a standard numeric LCD is not that difficult. To display text on the
LCD, correct library files for the LCD are needed. Many LCD libraries are
available on the Internet, which are used in various applications. You may get
confused which library is suitable for your application.
Libraries for LCDs found in AVRLIB library occupy unnecessary program
memory space. To solve the problem, you can write your own library for LCD
control.
Software program
This project demonstrates sending the text to the LCD controller and scrolling it
across the LCD. For the project, AVR Studio 4 and WINAVR software need to be
installed in your PC. Three program codes are used heremovm.c, lcd2.c and
lcd2.h. The movm.c contains the text message to be scrolled on the LCD. lcd2.c
and lcd2.h are the library files. The programming technique given here may not
be the best as it uses a simple logic, but it works pretty fine. The LCD library for
4-line or 4-bit mode operation is used here. Each pin connected to the LCD can
be defined separately in the lcd2.h code. The LCD and AVR port configurations in
the C code along with comments are given below:
Enable control line. The E control line is used to tell the LCD that the instruction
for sending the data on the data bus is ready to be executed. E must always be
manipulated when communicating with the LCD. That is, before interacting with
the LCD, E line is always made low. The following instructions toggle enable pin
to initiate write operation:
The complete subroutine of this code can be found in lcd2.c. The E line must be
left high for the time required by the LCD to get ready for receiving the data; its
normally about 250 nanoseconds (check the datasheet for exact duration).
Busy status of the LCD. It takes some time for each instruction to be executed by
the LCD. The delay varies depending on the frequency of the crystal attached to
the oscillator input of the HD44780 as well as the instruction being executed.
While it is possible to write the code that waits for a specific amount of time to
allow the LCD to execute instructions, this method of waiting is not very flexible.
If the crystal frequency is changed, the software needs to be modified.
Additionally, if the LCD itself is changed, the program might not work even if the
new LCD is HD44780-compatible. The code needs to be modified accordingly.
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.
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:
);k++,i++)
{
lcd_putc(pgm_read_
byte(&string[i]));
}
WaitMs(RATE);
j++;
}
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.
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
Here two options for burning the hex code in standard ISP mode are explained.
Some AVR tools that support ISP programming include STK600, STK500,
AVRISP mkII, JTAGICE mkII and AVR Dragon. There are also many other AVR
programming tools available in the market.
PonyProg2000 software. This software along with programmer circuit is
available from www.lancos.com/prog.html website. After installing
PonyProg2000, select the device family as AVR Micro and device type as
ATmega16. Now in Setup menu, select SI Prog I/O option for serial
programmer and COM port from Interface Setup option. In Security and
Configuration Bits option, configure the bits as shown in Fig. 3. Next, open the
device file (hex code) and click Write All option to burn the chip.
Frontline TopView software. This software along with programmer board is
available from www.frontline-electronics.com website. After installing the
software, select COM port from Settings menu. In Device menu, select the
device as ATmega16. Burn the hex code into the chip by clicking Program
option. Note that the microcontroller uses a 16MHz externally generated clock.
Program the fuse bits in the software by selecting upper and lower bytes as
follows:
Fuse low byte = EF
Fuse high byte = C9
If the fuse bits are not configured properly, the text will scroll slowly or text
scrolling may not function properly even if the scrolling rate in the code is
changed. The SPI6 connector allows you to program the AVR using SPI adaptor
in ISP mode.
Components :
1) IC 7805
2) ATmega16 AVR microcontroller
3) 16x2 LCD Display
4) 1 amp bridge rectifier module
5) LED
6) RESISTORS : 470 ohm, 47 ohm,10k ohm,10k ohm
7) Capacitors: 1mF(electrolytic), 10uF(electrolytic),
22pF(ceramic), 22pF(ceramic)
8) 16 MHz crystal oscillator