Easy Clear-screen Trick for BPK/BPI-series Displays
The LCD Serial Backpack® is a simple and very efficient way to get serial data into an alphanumeric display. About its only limitation is that it requires a short pause after the clear-screen instruction to allow the LCD to complete the operation.
With most microcontrollers, generating a 1-ms delay after clear-screen is no problem, but PCs and some other computers may lack fine-grained timing capabilities, or may buffer outgoing data in a way that removes the time delay.
This tip presents an easy (and probably obvious) solution--follow the clear-screen instruction with an unnecessary, but harmless, cursor-move instruction.
Making the Problem Clear
The LCD Serial Backpack is an intelligent device that initializes an alphanumeric LCD, then converts serial data into the LCD's parallel format. To distinguish between data (characters to be printed on the screen) and instructions (actions that affect the LCD's status or formatting), the Backpack watches for a single, special character: ASCII 254. The next received byte is treated as an instruction, then the Backpack reverts to 'data' mode.
That's all the Backpack does. No buffering, no handshaking, nada.
It's unusual for a manufacturer to boast about how little a product does, but in this case there's an excellent reason: The Backpack's simplicity of operation translates directly to the very low clock speed of its processor. This in turn means the lowest possible current draw--typically less than 1mA. (Some competing products draw 5x the current or more!) Low current draw mean longer battery life, smaller/cheaper voltage regulators, less heat, and so on.
The only gotcha is that most LCDs take a little more than a millisecond to clear the screen. Data arriving while the LCD is busy is ignored (unless it's buffered and transferred after the LCD is finished, as in our BPP-, ILM-, and graphics displays). So if you follow a clear-screen instruction with new text, the first text character may be dropped.
Using our handy serial sender program to demonstrate, the screen below illustrates the problem. When you press send, the PC transmits the bytes 254 1 and then the string "hello" at 9600. Without a time delay, a BPK-equipped LCD ends up displaying "ello."
The Solution
The clear-screen instruction actually does two things--it overwrites every display-RAM location with the space character (blank), and it returns the cursor/printing position to the first display location (upper left corner of the display).
So the solution to the clear-screen problem is to follow the clear instruction with a cursor-positioning instruction to the same screen location. Instruction 128 positions the cursor to the beginning of display RAM, so our modified clear screen looks like this:
Now the screen clears and the string "hello" appears.
Summary
At 9600 baud, the clear-screen instruction can cause the next character to be dropped by BPK-series displays. To combat this, either insert a 1-ms time delay after clear screen, or follow clear screen with a redundant move-cursor instruction. The four byte values that should be sent are:
254 1 254 128
For C programmers, bytes are 'unsigned chars.' In many dialects of BASIC, byte values must be sent using the CHR or CHR$ function. For example:
PRINT #1,CHR$(254);CHR$(1);CHR$(254);CHR$(128);
(assuming that the serial port is open and has been assigned #1.)
BASIC Stamp ® users can either use the approach described here, or follow the clear-screen with a PAUSE 1 instruction. Either will work fine.
|