5,276,801 members and growing! (16,831 online)
Email Password   helpLost your password?
Languages » C# » General     Beginner

Simple Scott Edwards Serial Backpack LCD Class and Example

By Brett Trotter

This is a relatively simple class and example to control a scott edwards serial LCD module with position counter and line wrapping.
C# 2.0, C#, Windows, .NET, .NET 2.0VS2005, VS, Dev

Posted: 30 Aug 2007
Updated: 9 Sep 2007
Views: 6,630
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
2 votes for this Article.
Popularity: 1.35 Rating: 4.50 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 50.0%
4
1 vote, 50.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Screenshot - virtual_lcd.jpg

Screenshot - _MG_3300_300.jpg

Introduction

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 frameworks 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.

Background

The Scott Edwards Serial LCDs have a fairly simple command structure, but if you have a 2x16 LCD, you end up writing into the offscreen 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 seperately- LF simply moves down a line (same X position) and CR moves to the beginning of the line you're on. I also added an option so that all CR characters can be treated as CRLF's (CR executes a 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.

Summary of Features

* Absolute positioning and position awareness
* Automatic line wrap at edge of screen rather than end of buffer off-screen
* Optional interception/translation of CR and LF with optional CR = CRLF
* Support for custom characters
* Supports cursor type setting
* V2 Supports a virtual screen buffer for saving and restoring
* The V2 example code has a virtual LCD label that reflects what is on the real LCD- excluding special or custom characters
* V2.1 adds support for Auto Scroll, leveraging the virtual buffer to be able to scroll the previous line upwards
* V2.2 fixes the missing backslash in the LCD firmware by automatically loading a backslash character into the custom character memory #7 whenever 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.
* V2.3 adds a screen updated event and a LCD clock you can enable/disable with a checkbox. The new example app consumes the event of course.
* V2.4 adds a differential write procedure where given a supplied array, it will write only the changed characters to the screen. Has some optimizing so positioning commands aren't sent when the screen is already at a position (eg writing a character and then the adjacent character).

Future Features

* currently hardcoded for Scott Edwards BPI-216 Screens- perhaps will add support for other models and/or make constants instead.
* Perhaps support for multiple snapshots and restores
* Implement stream class for direct output
* Make remap backslash only load the replacement character when needed and reload either the default #7 (space) or if the user has uploaded a custom char, put it back before its next use. UPDATE: tried it, but unfortunately the hardware redraws the display every time you add a character and it uses the current custom character map, so this feature is impossible.
* others? ideas?

Using the code

An extremely simple example application is provided that has a textbox to type into (characters appear on the LCD, and the virutal LCD (V2 only), but not the textbox) and it displays the current X & 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.

Notes

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 in 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.

History

* 08/31/07 - Initial Version/Release
* 09/01/07 - V2 includes updated example app and new snapshotting feature
* 09/01/07 - V2.1 adds Auto Scroll, adds a CLS button and cursor type selector list to the example app
* 09/01/07 - V2.2 works around the missing backslash and a few typo fixes in comments
* 09/01/07 - V2.3 added ScreenUpdated event for easier client use/updating of virtual displays
* 09/10/07 - V2.4 added the differential write method (WriteByDiff)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Brett Trotter



Occupation: Web Developer
Location: United States United States

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 6 of 6 (Total in Forum: 6) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralGreat get tuning!memberSoftwareDom21:57 9 Sep '07  
QuestionRe: Great get tuning!memberBrett Trotter8:23 10 Sep '07  
QuestionWhy no screen shot?memberyojiq0:29 4 Sep '07  
AnswerRe: Why no screen shot?memberBrett Trotter4:03 4 Sep '07  
Answerdone!memberBrett Trotter16:38 9 Sep '07  
GeneralRe: done!memberyojiq22:45 10 Sep '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 9 Sep 2007
Editor:
Copyright 2007 by Brett Trotter
Everything else Copyright © CodeProject, 1999-2008
Web12 | Advertise on the Code Project