AVR PROGRAMMING ENVIRONMENT

The ENV AVR Programming Environment with LCD

By Murray Greenman ZL1BPU

Version with LCD Display


INTRODUCTION

This information should be read in conjunction with that for the "ENV", the original Beginner's Development System. Apart from the addition of the LCD display, and minor revision of the initialization procedure, the ENV facilities of this version have not changed.

The original ENV solved the problem of communication of debug information through the use of an interrupt driven telemetry system. This version adds the ability to display debug and user information on an LCD display. A wide field of additional projects becomes possible when an LCD display is added, and this system makes such projects possible, and almost easy, through the addition of a suite of LCD driver routines.

LCD Displays are notoriously difficult to get going, especially if you've not done it before, in part because the display manufacturers' data sheets are hard to understand. With this ENVLCD system, the author has done all the hard work for you.

The LCD display used is any one or two-line alphanumeric parallel LCD display which uses the Hitachi HD44780 or one of its clones. This would include most of the inexpensive displays currently available, new or used. Examples are the DSE Z4170 and Z4172, and Jaycar QP-5515. These displays come in different sizes with up to 40 characters per line. Two lines of 16 characters is the most common type.


A typical 2 x 16 LCD display

DESCRIPTION

ENVLCD is a minimal program, but with rich respources, which will operate without modification in an AVR AT90S4433 processor. It contains just about everything a program requires, except the actual user application! Instead, a series of simple example programs are included. In addition to defining and setting up all the internal resources and ports, ENVLCD sets up the timers, the UART, the A-D converter, and the LCD display. It also provides all the necessary LCD driver routines. These are all areas which are difficult for the new user.

Four main files are provided -

  • ENVLCD.ASM (the source code)
  • ENVLCD.INC (the source definitions)
  • CMDLCD.INC (the special LCD routines)
  • ENV.EXE (a DOS executable monitor)
  • ENVLCD.htm (this file)
Other files include the source code for the PC monitor program ENV.BAS, the schematic, the parts list and some screen shots. These are not changed from the original ENV system. The additional LCD schematic and its connections are shown separately. This circuitry is additional to the original circuit. The pin connections of most LCD modules are similar to those in the schematic, but should be checked.

ENVLCD.ASM
The source code for the ENV embedded program. Explore this file to understand how the LCD is controlled, how the software works, and how to write your own application with LCD display. The main addition here is a clever 24 bit binary to BCD conversion routine, handy for displaying results in decimal. There are some additional display examples in the main code and timer interrupt, showing how the LCD display is set up and used.

ENVLCD.INC
The standard definition file for this project. Similar to the original ENV.INC file, but includes some LCD definitions and a few more registers.

CMDLCD.INC
This include file (to be included for assembly) contains all the necessary software to drive the LCD display. It contains:
  • LCDSET
Resets the display, and sets up display at initialization. Used once at the start of the program.
  • LCDBLURB 
Sends two-line sign-on message stored in program memory. Can be used at start-up, or any other time. The fixed message will need editing to suit, or you may comment out just the message, and add your own message in your main .ASM file using the same label.
  • CMD_LCD
Sends any command to the display. Examples are cursor movement, change of cursor type.
  • DATA_LCD
Sends a single ASCII character to be displayed at the cursor position.
  • CURSOR
Moves the display cursor to the specified address.
  • CLEAR
Clears the display and resets the cursor to the top left.
  • PRINTH
Sends a RAM data message of specified length to the LCD as HEX-ASCII (also works with packed BCD).
  • PRINTB
Sends one byte of packed BCD or binary to the LCD for display in two consecutive character locations. BCD displays as two digits; Binary is displayed as two HEX-ASCII values.
EXAMPLES
The new software has comments which show what everything does. This program provides resources, but intentionally does nothing useful, apart from the following simple examples for illustrative purposes. The first three operate in the Timer interrupt, and are refreshed every second, while the other two are at the start of the main program, before the main loop.

  • The SECS timer is displayed at row 1 column 4, in HEX-ASCII. It counts down.
  • Another (even slower) timer and the SECS timer form a 15 bit number. This number also counts down. It is subtracted from zero to create an up-counting value, which is converted to 8 digit decimal and displayed on the LCD at row 2 column 4. Leading zeros are not suppressed.
  • The 16 bit value of the first A-D converter channel is displayed in four character HEX-ASCII on LCD starting at row 1 column 8.
  • The display is initialized and cleared.
  • A sign-on message is displayed. The message is read from program memory as text. After it has been displayed a while, the display is again cleared and the main program loop and interrupts start.

DEFINITIONS

The LCD Display connections are as follows:
Pin     Function          AVR Port     Comment
 1       GND               -            Power supply common
 2       VCC               -            +5V
 3       CONTRAST          -            0 - 5V from contrast adjustment pot
 4       REGISTER SELECT   PD2          Tells display to expect command or data
 5       READ/WRITE        PB0          Tells the display whether to read (hi) or write (lo)
 6       ENABLE            PD3          Clocks data into the display
 7       D0                -
 8       D1                -
 9       D2                -
10       D3                -
11       D4                PD4          Display data LSB (4 bit mode)
12       D5                PD5          Display data
13       D6                PD6          Display data
14       D7                PD7          Display data MSB

In this application, the software only writes to the display, so PB0 remains low. Rather than read the display status to determine when to send the next command, it is simpler to just wait long enough to ensure that the display is ready. By connecting up the READ/WRITE line however, flexibility is retained for other applications. See the schematic below for all the required connections.


Click on image for full size schematic

If you compare this additional schematic with the original schematic, you will see that some pins will end up with more than one connection. With care, the inputs and outputs can still be used, even while the LCD display is in use. The user will need to ensure that the disruption of writing to the display has minimum effect. One way to do this is to buffer the inputs and outputs so they are read and written at the correct time. The display is not affected by this action provided the ENABLE line (PD3) is not waggled.

The display has a rich character set, and can also have a few user-defined characters programmed as well. You will note that it includes the full ASCII character set, some very useful Greek characters and a collection of Japanese symbols.


The LCD Display Character Set

LCD Display Specifications can be found at http://bray.velenje.cx/avr/PDFs/lcd-spec.pdf
HD44780 Controller Specifications can be found at http://esl.ee.sun.ac.za/ppakotze/ddpde/datasheets/HD44780.pdf

This information is not for the faint hearted!

PROGRAM EXAMPLES

A number of really useful projects can be developed using the AVR micro and LCD display. For example:
  • Digital voltmeter with numeric and 32 point bar-graph display.
  • Morse Keyer with speed display
  • Battery charger, conditioner and tester with capacity and status display
  • Electronic SWR meter
  • Weather station with display
  • Audio, LF or HFsignal generator with frequency display
  • Rotator controller with prefix memories and LCD display
  • APRS message decoder
  • GPS position / heading / UTC time display
  • 40 MHz Frequency Counter with LCD display
  • HF transceiver display, with frequency readout, mode display and S meter

HOME       Download Project Archive (includes source code)


I trust you will find ENVLCD useful. Please send any feedback or questions direct to me. While the software is offered free for private use, donations to cover development costs and to encourage further development are especially welcome.
zl1bpu@nzart.org.nz

Murray Greenman CSc, ZL1BPU
94 Sim Rd, Karaka,
RD1 Papakura
NEW ZEALAND

© Copyright M. Greenman 2000-2002. All Rights Reserved. See Legal Information for details.