Paul Thomsen – Technology & Science

my thoughts on science and (mostly) computer-related technologies and technologies other than computer management

Getting started using LCD displays from a Windows PC using the U421 October 10, 2010

Filed under: electronics,programming,U421 — Paul Thomsen @ 10:30 pm

Full function monitors are admittedly cheap these days (roughly $100 on the low end), so using an LCD display from a PC has little value. But you can build an LCD solution for $60 and the information on it will be visible even when your screensaver is active or the machine is locked. They also allow you to more immediately focus on the information you display on them (as opposed to the multiple windows on your monitors).

Assuming you have a need to use an LCD display from your Windows PC, here’s a solution that will work:

The strength of the U421 in this case is that it has LCD APIs, so you don’t have to worry about the subtleties of timing the data transfer and coordinating RS, R/W, and E.

The wiring is fairly simple:

  • B data lines to the LCD data lines (i.e. B0 to DB0, B1 to DB1, etc.)
  • A data lines to the RS/Rw/E lines (A0 to Rw, A1 to Rs, A2 to E)
  • power lines as appropriate, except nothing to VDD (unless you want to set up a control for contrast)

Preparation for the coding is:

  • copy the USBMicro USBm.dll into the bin\debug folder of the application
  • add “using System.Runtime.InteropServices” to the ‘using’ part of your code
  • add the public class USBm from the USBMicro sample code to your application

The key code is:

result = USBm.USBm_FindDevices();
Device = 0; // assuming there’s only one device
USBm.USBm_DirectionA(Device, 0xFF, 0xFF); // output only
USBm.USBm_DirectionB(Device, 0xFF, 0xFF);
result =
USBm.USBm_InitLCD(Device, 0x01, 0x12); // A.0 is the RW line, A.1 is the RS line; data port B, A.2 is the E line
result = USBm.USBm_LCDCmd(Device, 0x30 + 8); // function set: 8 bit; 2 lines, font 0
result = USBm.USBm_LCDCmd(Device, 0x04); // entry mode – not incrementing, in either direction
result = USBm.USBm_LCDCmd(Device, 0x0C); // display on; no cursor, no blinking
result = USBm.USBm_LCDCmd(Device, 0x01); // clear display

output[0] = “initialized”;
for (int i = 0; i < output[0].Length; i++)
    result =
USBm.USBm_LCDData(Device, Convert.ToByte(output[0][i]));

p.s. There’s a key difference between the LCD-20x4Y (black on green) and LCD-20x4BW (black on white) displays – the second line starts at a different DDRAM address. Use 64 rather than 40.

 

One Response to “Getting started using LCD displays from a Windows PC using the U421”

  1. Paul Thomsen Says:

    It also does 1-Wire (and claims to do various other common electronics interfaces). So the low-level details are left to the hardware and its library, allowing you to focus on the application-level details.

    (BTW – I am not in any way related to USBmicro)


Leave a comment