![]() |
General Reading »
Hardware & System »
Hardware programming
Intermediate
License: The Code Project Open License (CPOL)
Simple Scott Edwards Serial Backpack LCD Class and ExampleBy Brett TrotterThis is a relatively simple class and example to control a Scott Edwards serial LCD module with position counter and line wrapping. |
C# 2.0, Windows, .NET 2.0VS2005, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||


This is a fairly simple application and class library that wraps the control functions of a Scott Edwards Serial Backpack LCD module. It makes use of the .NET 2.0 framework's System.IO.Ports namespace and the proprietary (but documented) LCD control commands of the BPI-216 LCD. They are common enough that I assumed others might be interested.
The Scott Edwards Serial LCDs have a fairly simple command structure, but if you have a 2x16 LCD, you end up writing into the off-screen area before the line wraps around again, since the buffers are for a 40 character LCD.
I wanted a class that would keep track of the cursor position and automatically wrap to the next line at the appropriate place. You can write any stream of bytes, or any string to the display, and it is wrapped automatically. With this, you can send a continuous string, including newlines, to the LCD, and it will never go outside the display. Additionally, you can position the cursor through an X,Y coordinate pair or individual X or Y position.
Since the screen interprets characters 8-31 as repeats of the custom characters (0-7), newlines do not work without code. With this, you can optionally turn on interception of CR and/or LF as well as line blanking on new lines. I have treated CR and LF separately - LF simply moves down a line (same X position), and CR moves to the beginning of the line you are on. I also added an option so that all CR characters can be treated as CRLFs (CR executes an LF as well).
Lastly, I wrote a function that takes an 8 byte bit map (per documentation) and will load it into the specified custom character address.
RemapBackslash is turned on. Note that if you disable RemapBackslash and load a new character into #7, and eventually turn remap back on, it will reload the backslash character again. Off by default, since you lose a custom character space.An extremely simple example application is provided, that has a textbox to type into (characters appear on the LCD and the virtual LCD (V2 only), but not the textbox), and it displays the current X and Y position. Its main purpose is to demonstrate how to instantiate the LCD class and provides a test apparatus.
This code is not provided so much for educational use as it is for sharing of a handy utility. The code should be fairly straightforward, and it is fairly heavily commented. I also haven't used any crazy syntactical tricks.
One thing I neglected to mention above that needs pointing out- the Pos, X, and Y properties set/get where the cursor is going to write. When auto-scroll is on, the cursor will always jump to 0,1, and the display will not scroll up until the next character is entered. Similarly, if Clear on Wrap is on, the display doesn't clear the line until text is entered on it, even though the cursor is technically on the line already.
When reading the RawScreen property, characters that have not been touched are nulls (using a nullable byte type) - this may have uses, but you have to watch for it when/if you update a virtual LCD label.
Lastly, auto-scroll implies Clear on Wrap; since the display must move everything up a line, the new line is naturally clear.
ScreenUpdated event for easier client use/updating of virtual displays.WriteByDiff).| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 9 Sep 2007 Editor: Smitha Vijayan |
Copyright 2007 by Brett Trotter Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |