ProtoUSB LCD Driver


This tutorial guides you through driving your Hitachi HD44780 alphanumeric LCD with the ProtoUSB module. This article serves as a good introduction to using the ProtoUSB in the parallel I/O mode. The following steps will guide you through configuring your system, wiring the interface, and writing the software to communicate to the display.

Step 1 - Installing The Correct Windows Device Driver
To use the ProtoUSB in the parallel I/O mode, you must have the D2XX driver installed. In many cases, the VCP ( Virtual Comm Port ) driver will be installed. If the VCP driver is installed you can easily remove it from your system using the FTClean utility. Note that you should remove your device from the USB port, before running FTClean.

After your system has been cleaned from the VCP driver, plug in your ProtoUSB module. The Driver Installation Wizard should open. Do not allow the wizard to check Windows Update for a driver, find it manually. Point the Driver Wizard to the ftd2xx.inf file. Complete the wizard, and your system is now ready to access the ProtoUSB in parallel mode.

Step 2 - Connecting The ProtoUSB Module To The LCD
The pinout for most HD44780 displays is shown in Table 1, be sure to check the datasheet for your display to confirm the correct pinouts. Table 2 outlines the pinout for the ProtoUSB, and Figure 1 shows how we interface the two together.

Pin Number
Name
Direction
Description
1
Gnd
Power
Ground
2
Vcc
Power
+5 Volts ( +/- 10% )
3
Vee
Analog Input
Contrast Adjust
4
RS
Input
Register Select
5
R/W
Input
Read / Write
6
E
Input
Device Enable
7
D0
Bidirectional
Databus Line 0
8
D1
Bidirectional
Databus Line 1
9
D2
Bidirectional
Databus Line 2
10
D3
Bidirectional
Databus Line 3
11
D4
Bidirectional
Databus Line 4
12
D5
Bidirectional
Databus Line 5
13
D6
Bidirectional
Databus Line 6
14
D7
Bidirectional
Databus Line 7

Table 1 - HD44780 LCD Pinout

Pin Number
Serial Port Mode
Bit Bang Mode
1
Ground
Ground
2
TXD
D0
3
RXD
D1
4
RTS
D2
5
CTS
D3
6
DTR
D4
7
DSR
D5
8
DCD
D6
9
RI
D7
10
TXDEN
TXDEN
11
SLEEP
SLEEP

Table 2- ProtoUSB Pinout


Figure 1 - Hookup Diagram (click to enlarge)

Step 3 - Writing The Code

Now we need to write the software. This final step will explain the source code for the 'ProtoUSB-ParIO' project that you can download from the link below. This tutorial assumes you are using Visual Studio.NET 2003 or greater.

The project file for this project is already set up to include the correct library files. When creating your own project, do not forget to add the reference to FTD2XX.LIB in your Project|Linker settings. You will also need to copy the FTD2XX.LIB, FTD2XX.DLL & FTD2XX.H to your project directory. ProtoUSB.cpp & ProtoUSB.h are two more files that you may want to copy to your project directory. The ProtoUSB class gives you a handful of functions that make communicating to your ProtoUSB easier.

In the ProtoUSB-ParIO project, you will find this snippet in the OnInitDialog routine.

// Initialize ProtoUSB Device
//------------------------------
int nDeviceCount;
CString sMessage;

char cBuffer[64];
nDeviceCount = usbDevice.GetDeviceCount( );
if( nDeviceCount == 0 )
{
MessageBox( _T("No Devices Available"), _T("Exiting") );

OnOK( );
return TRUE;
}

usbDevice.GetDeviceSerialNumber( 0, cBuffer, 64 );
sMessage.Format( _T("Found %d devices.tDevice[0] SN: %s"), nDeviceCount, cBuffer );

SetDlgItemText( IDC_STC_STATUS, sMessage );
usbDevice.OpenDevice( 0 );

//Set Data Rate
usbDevice.SetDeviceDataRate( 1200 );

//Setup Port To Parallel Output & All Pins Outputs
usbDevice.SetDeviceMode( 0x01, 0xFF );

//Initialize LCD
InitializeHD44780( );

The important routines here, as far as communicating with your ProtoUSB, are GetDeviceCount(), GetDeviceSerialNumber(), OpenDevice(), SetDeviceDataRate(), and SetDeviceMode().

GetDeviceCount() - Enumerates all FTDI devices connected to your system.
GetDeviceSerialNumber() - Gets the serial number for a specific device.
OpenDevice() - Opens a specific device for read/write operations.
SetDeviceDataRate() - Sets the speed at which the ProtoUSB will write & read.
SetDeviceMode() - Sets device mode to parallel or serial, and sets the bit directions for parallel.

The next important snippet is in the OnDestroy() event routine.

//--------------------------
// Close ProtoUSB Device
//--------------------------
usbDevice.CloseDevice( );

//--------------------------

CloseDevice() - Closes the currently open device. [ opened with OpenDevice() ]

The last snippet that will be of interest, is the WriteHD44780() function. This routine is actually writing data bytes to our LCD.

//Write Data

//Set LCD To Write Mode [0]( RW=0:Write, RW=1:Read )
ucCtrl = 0x00;
usbDevice.WriteByteToDevice( 0x00 );

//Set LCD To Data Mode ( RS=1:Data, RS=0:Command )
if( ucRegister != 0x00 )
ucCtrl = LCD_RS_MASK;

usbDevice.WriteByteToDevice( ucCtrl );

//Set LCD E Line High ( E=1 )
usbDevice.WriteByteToDevice( ucCtrl | LCD_E_MASK );

//Set DataBus Data MSN ( DB=0x00 )
usbDevice.WriteByteToDevice( ucCtrl | ( ( ucData >> 4 ) & 0x0F ) | LCD_E_MASK );

//Set LCD E Line Low ( E=0 )
usbDevice.WriteByteToDevice( ucCtrl );

//Set LCD E Line High ( E=1 )
usbDevice.WriteByteToDevice( ucCtrl | LCD_E_MASK );

//Set DataBus Data LSN ( DB=0x00 )
usbDevice.WriteByteToDevice( ucCtrl | ( ucData & 0x0F ) | LCD_E_MASK );

//Set LCD E Line Low ( E=0 )
usbDevice.WriteByteToDevice( ucCtrl );

WriteByteToDevice() - Sets the ProtoUSB output port to the passed value.

That's it..

The WriteHD44780(), InitializeHD44780 & LcdPutString() functions are standard routines for sending data to standard LCD displays. For more information regarding LCD's refer to
http://home.iae.nl/users/pouweha/lcd/lcd0.shtml
or download the HD44780 datasheet.

Download the ProtoUSB-Tutorial Project Here
ProtoUSBTutorial.ZIP (112Kb)

AttachmentSize
hd44780.pdf389.93 KB
ProtoUSBTutorial.zip111.03 KB