Technical notes on using Analog Devices DSPs, processors and development tools
Contact our technical support at dsp.support@analog.com and at dsptools.support@analog.com
Or vi sit our o n-li ne r esou rces htt p:/ /www.analog.com/ee-notes and http://www.analog.com/processors
Connecting Character LCD Panels to ADSP-21262 SHARC® DSPs
Contributed by Brian M. Rev 1 – December 16, 2003
Introduction
This document contains example code and
hardware to interface an ADSP-21262 SHARC
DSP to a Hitachi HD44780-compatible character
LCD driver. The specific module used in this
example is an Optrex DMC-16128, which has a
16x1 character dot matrix LCD controlled by the
HD44780 driver.
A character LCD module interfaced to the DSP
can prove to be a very useful tool. In addition to
providing a user interface, the character device
can be used as a real-time debugging interface.
Using the character device to print the function
currently executing (or the state of buffers while
running) is a viable alternative to halting the
processor to check these states when using an
emulator.
Hardware Interface
The critical control signals on the LCD driver are
constrained by timing specifications that are
slow. They are too slow to be used with the
Parallel Port. However, using software to control
general-purpose flags, it is possible to generate
the necessary waveforms. This method will work
for any DSP that provides at least 11 bidirectional programmable flags (in the SHARC®
family of DSPs, the ADSP-21065, ADSP-21161,
and ADSP-21262 provide enough programmable
flags to implement this interface). This will allow
both reading and writing capabilities with an 8bit interface. (The HD44780 compatible drivers
Copyright 2003, Analog Devices, Inc. All rights reserved. Analog Devices assumes no responsibility for customer product design or the use or application of
customers’ products or for any infringements of patents or rights of others which may result from Analog Devices assistance. All trademarks and logos are property
of their respective holders. Information furnished by Analog Devices Applications and Development Tools Engineers is believed to be accurate and reliable, however
no responsibility is assumed by Analog Devices regarding technical accuracy and topicality of the content provided in Analog Devices’ Engineer-to-Engineer Notes.
can also operate with a 4-bit interface if fewer
general-purpose flag pins are available.)
Figure 1. Hardware Interface
On the ADSP-21262 SHARC DSP, the Parallel
Port pins are multiplexed with the generalpurpose flag pins. Therefore, any access to the
Parallel Port also disturbs the LCD interface. To
avoid this problem, it is necessary to use one of
the DAI pins as a general-purpose flag, so that
the enable signal to the LCD will never be
changed unintentionally.
As shown in Figure 1, the final interface
implementation requires no glue logic. Each of
the 11 control pins for the HD44780 driver are
connected to a unique programmable flag pin
(when connecting to the ADSP-21262 SHARC
DSP, connect the E pin of the HD44780 to the
DAI pin being used a programmable flag, as
described above).
a
For the power interface, SHARC EZ-KIT Lite™
development boards provide pins for both a 5V
and Ground, which can be connected to the Vdd
and Vss pins of the LCD module, respectively.
For the Vee connection, use a variable
potentiometer to control the contrast of the LCD,
or simply ground Vee for maximum contrast.
Since this device will handle characters and
strings, it is most useful to develop the code to
interface to the LCD module using the C
language. The code fragments contained in this
document are in C, and are compiled using the
VisualDSP++ development suite version 3.0
(service pack 1).
Code Listings 1 and 2 show the code necessary
Software
The most important step in developing the
software for this LCD controller is to emulate the
hold times necessary to communicate via the
interface. This can be done using “NOP” loops or
the timer. This example uses “NOP” loops. The
entirety of the code to access the LCD as
described in this document is included, along
with a VisualDSP++® project file.
to read from and write to the device. Note that in
most cases, it is necessary to wait for the device
to be ready before performing an actual read or
write. Part of the call to the read and write
function is a Boolean variable (bftest - Busy Flag
Test), indicating this requirement.
At the end of this document is a complete code
listing that contains the minor functions called
from the listings presented here.
//Read from the LCD
//Inputs passed - RegisterSelect = Indicates the desired state of the RS pin
// bftest = wait for the busy flag to clear before writing
//Outputs returned - the byte of data read from the LCD
int readFromLCD(int RegisterSelect, int bftest)
{
const int ReadWrite = 1;
asm("r0=flags; r0=r0 or %0; flags=r0;"::"d" (RegisterSelect<<26):"r0");
asm("r0=flags; r0=r0 or %0; flags=r0;"::"d" (ReadWrite<<28):"r0");
nanosec(1);
SRU(HIGH,DAI_PB15_I);
nanosec(3);
asm("r0=flags; r1=0x5555; %0=r0 and r1;":"=d" (data)::"r0","r1");
SRU(LOW,DAI_PB15_I);
nanosec(1);
Connecting Character LCD Panels to ADSP-21262 SHARC® DSPs (EE-219) Page 2 of 11
data = despreadData(data);
return data;
}
Listing 1. readFromLCD()
a
//Write to the LCD
//Inputs passed - RegisterSelect = Indicates the desired state of the RS pin
// data = the byte of data to write to the lcd
// bftest = wait for the busy flag to clear before writing
//Outputs returned - none
void writeToLCD(int RegisterSelect, int data, int bftest)
{
const int Enable = 30,
ReadWrite = 0;
int busyflag=1;
asm("bit set flags 0xAAAA;");
asm("bit clr flags 0x54005555;");
asm("r0=flags; r0=r0 or %0; flags=r0;"::"d" (RegisterSelect<<26):"r0");
asm("r0=flags; r0=r0 or %0; flags=r0;"::"d" (ReadWrite<<28):"r0");
asm("r0=flags; r0=r0 or %0; flags=r0;"::"d" (data):"r0");
nanosec(1);
SRU(HIGH,DAI_PB15_I);
nanosec(3);
SRU(LOW,DAI_PB15_I);
nanosec(1);
return;
}
Listing 2. writeToLCD()
Two functions, readFromLCD() and
writeToLCD(), are the basis for any other
function that will access the LCD. The functions
supplied in this example are:
lcdprintf() (Listings 4 and 5),
3),
lcdshiftright() (Listing 6), lcdshiftleft()
(Listing 7), and
Connecting Character LCD Panels to ADSP-21262 SHARC® DSPs (EE-219) Page 3 of 11
lcdblink() (Listing 8).
lcdinit() (Listing
lcdInit() performs an initialization routine that
is outlined in both the Hitachi HD44780 data
sheet [2] and the Optrex LCD Module User’s
Manual [3]. Performing this initialization may
not always be necessary, but using it will
guarantee that the LCD is in its initial state
before any commands are set.
a
lcdprintf() is a macro that parses a string in
the same manner as a standard printf. The
lcdprint() function is called by the
lcdprintf() macro to display the desired
characters, and the sprintf() function is called
by the macro to handle the arguments that are
passed. At this time, if no arguments are to be
passed, it is necessary to call the
lcdprint()
function directly, as the preprocessor cannot
handle a call without any arguments, and the
variable length argument functions in the C
runtime are not functioning.
The display for the 16x1 character LCD of the
DMC-16128 must be accessed as 2 lines, each
displaying 8 characters at a time. The first eight
characters are accessed by DD-RAM addresses
0x0 through 0x27, and the last eight characters
are accessed by addresses 0x40 through 0x67.
When reading or writing a string of more than
eight characters to the LCD, it is necessary to
write the first eight characters to the lower
addresses in succession, then change the DDRAM address to the upper address and write the
final characters.
The LCD driver has the ability to shift the
characters already in DD-RAM to the right or to
the left. However, these commands do not
automatically wrap the contents of the second
line to the first or vice versa. Therefore, it is
necessary to program the entire string into both
the upper and lower memory locations, with the
upper locations being shifted to the left by eight
locations.
This is exactly how the
lcdprint() function
operates. Specifically, it clears the display and
returns the cursor to home and writes the entire
string (up to 40 characters), beginning with the
first DD-RAM location. The DD-RAM location
is then changed to the second line, and the string
is written again beginning with the ninth
character at address 0x40. The rest of the string
is written, and then the first eight characters are
written beginning at address 0x60. This method
allows wrapping from the right half of the LCD
to the left, and vice versa.
The final three functions supplied are effects on
the display, and do not change the DD-RAM
contents. As their names suggest,
lcdshiftleft() and lcdshiftright() shift
the DD-RAM addresses currently displayed. The
function shifts the display a single character in
the specified direction the number of times
passed, repeated at the interval passed (in
hundreds of microseconds). Similarly,
lcdblink() turns the display off and on, the
number of times passed, at the interval passed (in
hundreds of microseconds).
//Initialize the LCD as described in the HD44780 Datasheet
//Inputs passed - none
//Outputs returned - none
void initLCD()
{
int readbyte,
dummybyte,
flagvalues;
//Handle the parallel port interrupt using ppInterruptVector
interrupt(SIG_PP, ppInterruptVector);
//Set up DAI pin 15 as an output that is low
SRU(LOW,DAI_PB15_I);
SRU(LOW,PBEN15_I);
//Set up the DSP to access the LCD
Connecting Character LCD Panels to ADSP-21262 SHARC® DSPs (EE-219) Page 4 of 11
Loading...
+ 7 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.