Click here to Skip to main content
6,595,854 members and growing! (17,727 online)
Email Password   helpLost your password?
General Reading » Hardware & System » Hardware programming     Intermediate License: The Code Project Open License (CPOL)

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, Windows, .NET 2.0VS2005, Dev
Posted:30 Aug 2007
Updated:9 Sep 2007
Views:12,321
Bookmarked:25 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
3 votes for this article.
Popularity: 2.19 Rating: 4.60 out of 5

1

2

3
1 vote, 33.3%
4
2 votes, 66.7%
5

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

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

Summary of Features

  • Absolute positioning and position awareness.
  • Automatic line wrap at the edge of screen rather than the end of the 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 an 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 (e.g., 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 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.

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

History

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Brett Trotter


Member

Occupation: Systems Engineer
Company: BT Technical Services
Location: United States United States

Other popular Hardware & System articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralGreat get tuning! PinmemberSoftwareDom21:57 9 Sep '07  
QuestionWhy no screen shot? Pinmemberyojiq0:29 4 Sep '07  
AnswerRe: Why no screen shot? PinmemberBrett Trotter4:03 4 Sep '07  
Answerdone! PinmemberBrett Trotter16:38 9 Sep '07  
GeneralRe: done! Pinmemberyojiq22: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: Smitha Vijayan
Copyright 2007 by Brett Trotter
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project