ThVortex

KS0108B Graphic LCD

This component implements a 128x64 dot-matrix LCD with a pair of KS0108B or HD61202 controllers. It was initially programmed by Mrkaras, and the original version of this component is still available in the VMLAB user forum. The current version is licensed under the GNU LGPL v3. All controller commands are simulated, in addition to also simulating a variable brightness blue-colored backlight. To simulate a larger 192x64 or 128x128 LCD display, one can use two component instances and tie all the corresponding pin pairs together, with the exception of the chip select pins.

A good introduction to this type of LCD panel can be found on Dincer Aydin's LCD Info Page which contains a tutorial, relevant datasheets, and even an interactive web-based LCD simulator. The example project download includes two pre-compiled .hex files written by Fabian Maximilian Thiele. A detailed description of the examples, as well as the WinAVR source code for both .hex files, is available on the ScienceProg website here and here.

Downloads

Usage

; To use this component, use the following component definition:
;
; X _graphiclcd <RS> <RW> <E> <D7> <D6> <D5> <D4> <D3> <D2> <D1> <D0>
; + </CS1> </CS2> </RST> <LED+> <LED->

; Pins <RS>, <RW>, <E>, and <D7> through <D0> are the standard data/instruction
; register select, read/write, enable, and I/O data pins found on any KS0108B
; or HD61202 controller. The </CS1> and </CS2> pins are active-low chip select
; signals for respectively the left and right side of the LCD. Keep in mind
; that some physical LCD panels may use an active-high chip select, which could
; require modifying existing AVR code or using the builtin "ND2" gate in VMLAB
; to invert the signals. The </RST> pin is an active-low asynchronous reset for
; both controllers. The <LED+> and <LED-> pins help simulate the backlight. A
; voltage difference of +5V or greater between the pins will result in maximum
; brightness, while voltage differences below +1V result in minimum brightness.

Example

; Emulating a 128x64 LCD panel with 2 chip select pins
X _graphiclcd pc0 pc1 pc2 pd7 pd6 pd5 pd4 pd3 pd2 pd1 pd0 pc4 pc3 vdd vdd vss

; Emulating a 128x128 panel with 4 chip select pins
; pc4=/CS1, pc3=/CS2, pb2=/CS3, pb1=/CS4
Xtop _graphiclcd pc0 pc1 pc2 pd7 pd6 pd5 pd4 pd3 pd2 pd1 pd0 pc4 pc3 vdd vdd vss
Xbtm _graphiclcd pc0 pc1 pc2 pd7 pd6 pd5 pd4 pd3 pd2 pd1 pd0 pb2 pb1 vdd vdd vss

Version History

  • v0.1 - 2009-08-14 - Initial public release by Mrkaras
  • v0.2 - 2009-08-29 - Improved drawing speed
  • v0.3 - 2009-10-06 - Licensed under the LGPL by Mrkaras
  • v0.4 - 2009-11-13 - Improved GUI layout and behavior

Future Improvement Ideas

  1. There should be a "Log" and "Break on error" checkbox similar to the builtin "LCD" component. Possible errors include unrecognized commands, commands sent while a controller is busy or the </RST> pin is asserted, and attempting to read from both controllers simultaneously.
  2. Instead of two analog pins to control the backlight brightness, I think it would be more useful to have a single digital pin that can be pulse width modulated. This allows software AVR control of the backlight. You could blink it to get a user's attention or slowly fade it in or out.
  3. Do further testing with a real LCD to verify what happens if <RS> and/or <RW> pins change while <E> pin is high (i.e. are they level or edge triggered).

Screenshot

Below is an animated screen shot of the "graphiclcd" component while running the "glcd1.hex" file included with the example project file. The GUI refresh rate can be adjusted in the menu: Options -> Display Control -> Windows refresh -> Registers / Peripherals.

The contents of all user accessible registers are displayed for each controller, including the output register (Out DR) used to temporarily store data when reading the display data RAM. When the <E> and the chip select pins are asserted, and the relevant controllers are not in a busy state, then the "Status" line will show one of "rDat", "wDat", "rStat", or "wInst" to indicate which operation was selected via the <RW> and <RS> pins.