LCDPresentation View Online: Difference between revisions

From K-LUG Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 12: Line 12:


<h3>LCD Kit Parts list</h3>
<h3>LCD Kit Parts list</h3>
<pre>
__ 10K trim pot
__ 10K trim pot
__ 25 pin male D IDC
__ 25 pin male D IDC
Line 24: Line 25:
__ 2 line x 12 character LCD
__ 2 line x 12 character LCD
__ Interface Circuit board
__ Interface Circuit board
</pre>


<h3>Kit Options</h3>
<h3>Kit Options</h3>
Line 46: Line 47:




<H3>Interface - Mechanical </H3>
There are several different styles of interface layouts For a given layout the pins will have the same function The same pin numbers will have the same function across layouts.




<H3>Interface - Electrical</H3>
<pre>
Pin# Pin# Symbol Level Function
8 bit 4 bit
==== ====== ===== ====== ==========================
1 1 Vss GND Ground
2 2 Vcc +5V Module power
3 3 Vee NOTE1 Liquid crystal drive
4 4 RS H/L Register select, H=data, L=command
5 5 R/~W H/L Read/Write, H=read , L=write
6 6 E H->L Edge-sensitive Enable
7 - DB0 Data bit 0 (not used in 4 bit mode)
8 - DB1 Data bit 1 (not used in 4 bit mode)
9 - DB2 Data bit 2 (not used in 4 bit mode)
10 - DB3 Data bit 3 (not used in 4 bit mode)
11 7 DB4 Data bit 4
12 8 DB5 Data bit 5
13 9 DB6 Data bit 6
14 10 DB7 Data bit 7
</pre>
NOTE1: On standard modules Vee is between GND and 5V; on temperature extended modules it is between GND and -7V






<H3>Interface - Electrical</H3>
Back Lighting
Power may be additional interface pins or separate connections
LED simple, high power Electro-Luminescent complex drive circuit, less power Cold Cathode Fluorescent complex drive circuit, less power, not usually found on char displays
<H3>Interface - Options </H3>
Hardware Software 8 bit Write and wait - more interface lines - Write data and wait for - faster max time 4 bit - Simple - 4 less interface lines Check busy - needs 2 write operations - Write and check status - May be faster - Requires bidirectional data bus
<H3>Interface - Timing </H3>
Control Signal Timing
If you look at the spec sheet you will find diagrams like the next page. These are important if you are running at the maximum speed the display can support, such as memory mapped I/O with a micro-processor.
For a parallel port or port based I/O on a micro-processor it is simpler (slower) we usually won't come close to these limits. In compatibility mode, the parallel port is simulating talking to a printer over an 8MHz AT bus. The minimum transition is about 500ns even on a GHz machine.
<H3>Write timing    LCD controller </H3>
<pre>
WRITE:
______ _____________________________ ___________
RS ______X_________valid_RS_level______X__________
| |
| |
|<--40ns->| 10ns->| |<--
______| | | |____________
R/W ______\_________|___R/W_low____|____/_____________
| |
|<----230ns--->|
| |
|<-------------|------500ns------>|
|______________| |_________
E ________________/ \__________________/
20ns(max)-->||<-- -->||<--20ns(max)
|<--80ns-->||
| -->|
|<--10ns
__________________|_______________|________________
D0-D7 __________________X__valid_data___X____________
</pre>
<H3>Write timing - Port I/O</H3>
<pre>
_______ _____________ ____________________ __
RS_______X_____________X____________________X__ ____ __ __
R/-W ____\____________/ \___________________/
Note that for  write and wait  R/-W can be tied low ______ ________ __ __ _______ _______ __
DATA ______X________X__ __X_______X_______X__ Bits 7-0 7-4 3-0 ___ ___ ___
E ________/ \____________/ \__/ \___ 8 Bit 4 Bit
</pre>
<H3>Parallel port signals</H3>
So how do we connect to the parallel port? Data is easy just connect the parallel port data to LCD data. The LCD requires 2 or 3 control lines, the parallel port has 4 available; so there are several possibilities. We will use the connection used by Winamp.
<H3>Parallel port connection</H3>
D-Type Hardware Pin No Name Direction Register Inverted LCD Sig LCD pin 1 -Strobe Out Control Yes E 6 2 Data 0 Out Data Data0 7 3 Data 1 Out Data Data1 8 4 Data 2 Out Data Data2 9 5 Data 3 Out Data Data3 10 6 Data 4 Out Data Data4 11 7 Data 5 Out Data Data5 12 8 Data 6 Out Data Data6 13 9 Data 7 Out Data Data7 14 14 -Linefeed Out Control Yes R/-W 5 16 Initialize Out Control RS 4 18  25 Ground Gnd Gnd 2
<H3>LCD Commands</H3>
<pre>
D7 D6 D5 D4 D3 D2 D1 D0 Instruction/Description
0 0 0 0 0 0 0 1 Clear Display
0 0 0 0 0 0 1 * Return to Home Position
0 0 0 0 0 1 ID S Set Cursor Move Direction
0 0 0 0 1 D C B Enable Display/Cursor
0 0 0 1 SC RL * * Cursor/Display Shift
0 0 1 DL N F * * Set Interface Length
0 1 A A A A A A Set CGRAM Address
1 A A A A A A A Set Display Address
ID 0 = Decrement cursor position 1 = Increment cursor position
S 0 = No display shift 1 = Display shift
D 0 = Display off 1 = Display on
C 0 = Cursor off 1 = Cursor on
B 0 = Cursor blink off 1 = Cursor blink on
SC 0 = Move cursor 1 = Shift display
RL 0 = Shift left 1 = Shift right
DL 0 = 4-bit interface 1 = 8-bit interface
N 0 = 1/8 or 1/11 Duty (1 line) 1 = 1/16 Duty (2 lines)
F 0 = 5x7 dots 1 = 5x10 dots
A Address LCD Commands
</pre>
<H3>LCD Commands</H3>
RS is register select 0=command, 1=data. R/-W is read/write control 0=write,1=read. Commands are issued with R/S=0 and R/-W=0. Put the command on the data lines, and toggle E from L->H->L.
The Clear Display and Return Home commands can take up to 1.64ms, the rest take ~40usec.
Even with only 8 commands, it can be a bit confusing with all the options We only need a subset of the commands to initialize the LCD.
1. Set Interface Length - use 0011 1000 8 bit interface, 2 lines, 5x7 dot characters
2. Enable Display/Cursor - use 0000 1100 display on, no cursor
3. Clear Display - use 0000 0001 no options 4. Set Cursor Move Direction - use 0000 0110 increment cursor, no shift Then we can use Set Display Address and data writes to put characters on the display.
<H3>Writing Data</H3>
After initializing per the previous slide writing starts at the first position on line 1. To write data, we set RS=1, R/-W=0, put the ASCII character on the data lines, and toggle E from L->H->L. The controller has 80 bytes of data memory that are organized differently depending on the mode. In single line mode it starts at 0 offset and is linearly addressed to offset 0x4F. In some documents, you will see memory addressed as 0x80  0xCF; this is the actual command to set the memory address (remember command bit 0x80 indicates display address set). In 2 line mode the display memory is split with the first 40 bytes starting at offset 0 (0x80) and the second line at offset 0x40 (0xC0).
<H3>Display Addressing</H3>
The base controller can display 2 lines x 8 char. For each additional 8 characters, a display driver is added to handle another 2 lines x 8. For a 1 line x 16 characters, there are two possibilities. There could be the controller and a display driver, in which case it would look like a single line display. The other case is to use only the controller and treat it as a 2 line x 8 character display with the 2  lines  on one line. This makes a difference in how you address the second 8 characters!
Four line displays, for example 4 lines x 20 characters, the other lines are mapped onto lines 1 and 2. Line 3 is the second half of line 1 and line 4 is the second half of line 2.
Line 1 0x80  0x93
Line 2 0xC0  0xD3
Line 3 0x94  0xA7
Line 4 0xD4 - 0xE7
<H3>So what about the code?</H3> There are several ways to talk to the parallel port
1. Direct port I/O  requires root authority
2. Write a kernel device driver  complex (although Mark Harris has done most of the leg work for us) and non standard
3. Use the existing parallel port device driver for device /dev/parport0 This can run in user state and it is commonly available. I used this option. File device drivers support open, close, read, and write for normal operation. Unfortunately toggling control port bits is not  normal operation . For hardware specific operations, the ioctl (i/o control) operation is provided. We will use this for both data and control writes. The constants are in include/linux/ppdev.h
<H3>Control Functions</H3>
When attaching an LCD display, there are several options for the control functions.
When attaching an LCD display, there are several options for the control functions.
Rather than invent our own, we used an existing definition originally used by a Winamp
Rather than invent our own, we used an existing definition originally used by a Winamp
Line 100: Line 279:
LCD has back light capability, the connections may not be on the connector
LCD has back light capability, the connections may not be on the connector


== [[http://k-lug.org/old.site/presentations/lcd/lcd_project.tar.gz Download the Tarball containing source code here]] ==
== [[http://k-lug.org/old.site/presentations/lcd/lcd_project.tar.gz Download the Tarball containing source code here]] ==</pre>

Latest revision as of 23:38, 1 January 2006

Build an LCD Display for your Computer

(page under construction)

A recent project for our [K-LUG] Linux User group was to create ourselves LCD Displays for computers. We created kits containing all necessary parts for < $20. Some used their LCD Display to show the health of their headless servers, some to show off title and artist information from an MP3 player, and others still to simply have fun with animation. Here is a picture of one of the finished products

http://www.pcig.info/uploads/Main/LCDTuxsm.jpg

Intro to the LCD Kit Project

Welcome to the first K-LUG project involving the attaching of interesting hardware to a computer. We created this project because one member had several monitorless servers he wanted to view performance stats on. We also picked this project so we would have some interesting code to write, and we figured it would be cheap, easy and fun! Ideally our attached display would connect via USB, however, we chose a parallel port connected display because no one seems to use the parallel port anymore, and by using a parallel port the kit was easier to code and cheaper to buy.

LCD Kit Parts list

__ 10K trim pot
__ 25 pin male D IDC
__ 3 pin single row header
__ 3 pin socket shell
__ 2 female socket pins
__ 16 pin header
__ 26 pin header
__ 26 position dual row socket
__ 27 ohm 1/4w resistor 30584CC
__ 26 conductor ribbon cable 6” - 24”
__ 2 line x 12 character LCD
__ Interface Circuit board

Kit Options

The kit contains a 3 pin single row header, a 3 pin socket shell, and 2 female socket pins for the power connection. Both of the outer pins are ground, the center pin is +5 volts. Only one ground pin requires a connection so only 2 socket pins are supplied. If you would prefer to hard wire the power connection these parts can be ignored and the power connections soldered directly to the board. There is enough ribbon cable for a 24” length between the 26 pin header and the 25 pin D connector. If you plan to mount the display in a box, with the 25 pin D connector mounted on the box you may want a shorter cable rather than try to stuff 24” of cable in the box. Consider what you want and we can cut the cable to fit.

Background Information

When you first look at attaching an LCD display to the parallel port, it looks simple – a bunch of connections, a potentiometer, and maybe a resistor for the back light. In fact, it can be messy and discouraging. This kit is designed to make the interface simple. It was designed by Dennis DeLorme and [Kevin Neff] – if you have questions they should be able to help.


Interface - Mechanical

There are several different styles of interface layouts For a given layout the pins will have the same function The same pin numbers will have the same function across layouts.


Interface - Electrical

 
Pin# Pin# Symbol Level Function 
8 bit 4 bit 
==== ====== ===== ====== ========================== 
1 1 Vss GND Ground 
2 2 Vcc +5V Module power 
3 3 Vee NOTE1 Liquid crystal drive 
4 4 RS H/L Register select, H=data, L=command 
5 5 R/~W H/L Read/Write, H=read , L=write 
6 6 E H->L Edge-sensitive Enable 
7 - DB0 Data bit 0 (not used in 4 bit mode) 
8 - DB1 Data bit 1 (not used in 4 bit mode) 
9 - DB2 Data bit 2 (not used in 4 bit mode) 
10 - DB3 Data bit 3 (not used in 4 bit mode) 
11 7 DB4 Data bit 4 
12 8 DB5 Data bit 5 
13 9 DB6 Data bit 6 
14 10 DB7 Data bit 7 

NOTE1: On standard modules Vee is between GND and 5V; on temperature extended modules it is between GND and -7V


Interface - Electrical

Back Lighting Power may be additional interface pins or separate connections LED simple, high power Electro-Luminescent complex drive circuit, less power Cold Cathode Fluorescent complex drive circuit, less power, not usually found on char displays




Interface - Options

Hardware Software 8 bit Write and wait - more interface lines - Write data and wait for - faster max time 4 bit - Simple - 4 less interface lines Check busy - needs 2 write operations - Write and check status - May be faster - Requires bidirectional data bus


Interface - Timing

Control Signal Timing

If you look at the spec sheet you will find diagrams like the next page. These are important if you are running at the maximum speed the display can support, such as memory mapped I/O with a micro-processor.

For a parallel port or port based I/O on a micro-processor it is simpler (slower) we usually won't come close to these limits. In compatibility mode, the parallel port is simulating talking to a printer over an 8MHz AT bus. The minimum transition is about 500ns even on a GHz machine.


Write timing LCD controller

WRITE:

 ______ _____________________________ ___________ 

RS ______X_________valid_RS_level______X__________ 

| | 

| | 

|<--40ns->| 10ns->| |<--

 ______| | | |____________ 

R/W ______\_________|___R/W_low____|____/_____________ 

| | 

|<----230ns--->| 

| | 

|<-------------|------500ns------>| 

|______________| |_________ 

E ________________/ \__________________/ 

20ns(max)-->||<-- -->||<--20ns(max) 

|<--80ns-->||

 | -->| 

|<--10ns 

__________________|_______________|________________ 

D0-D7 __________________X__valid_data___X____________ 

Write timing - Port I/O

 _______ _____________ ____________________ __ 

RS_______X_____________X____________________X__ ____ __ __ 

R/-W ____\____________/ \___________________/ 

Note that for  write and wait  R/-W can be tied low ______ ________ __ __ _______ _______ __ 

DATA ______X________X__ __X_______X_______X__ Bits 7-0 7-4 3-0 ___ ___ ___ 

E ________/ \____________/ \__/ \___ 8 Bit 4 Bit

Parallel port signals

So how do we connect to the parallel port? Data is easy just connect the parallel port data to LCD data. The LCD requires 2 or 3 control lines, the parallel port has 4 available; so there are several possibilities. We will use the connection used by Winamp.


Parallel port connection

D-Type Hardware Pin No Name Direction Register Inverted LCD Sig LCD pin 1 -Strobe Out Control Yes E 6 2 Data 0 Out Data Data0 7 3 Data 1 Out Data Data1 8 4 Data 2 Out Data Data2 9 5 Data 3 Out Data Data3 10 6 Data 4 Out Data Data4 11 7 Data 5 Out Data Data5 12 8 Data 6 Out Data Data6 13 9 Data 7 Out Data Data7 14 14 -Linefeed Out Control Yes R/-W 5 16 Initialize Out Control RS 4 18   25 Ground Gnd Gnd 2

LCD Commands

D7 D6 D5 D4 D3 D2 D1 D0 Instruction/Description 
0 0 0 0 0 0 0 1 Clear Display 
0 0 0 0 0 0 1 * Return to Home Position 
0 0 0 0 0 1 ID S Set Cursor Move Direction 
0 0 0 0 1 D C B Enable Display/Cursor 
0 0 0 1 SC RL * * Cursor/Display Shift 
0 0 1 DL N F * * Set Interface Length 
0 1 A A A A A A Set CGRAM Address 
1 A A A A A A A Set Display Address 
ID 0 = Decrement cursor position 1 = Increment cursor position 
S 0 = No display shift 1 = Display shift 
D 0 = Display off 1 = Display on 
C 0 = Cursor off 1 = Cursor on 
B 0 = Cursor blink off 1 = Cursor blink on 
SC 0 = Move cursor 1 = Shift display 
RL 0 = Shift left 1 = Shift right 
DL 0 = 4-bit interface 1 = 8-bit interface 
N 0 = 1/8 or 1/11 Duty (1 line) 1 = 1/16 Duty (2 lines) 
F 0 = 5x7 dots 1 = 5x10 dots 
A Address LCD Commands


LCD Commands

RS is register select 0=command, 1=data. R/-W is read/write control 0=write,1=read. Commands are issued with R/S=0 and R/-W=0. Put the command on the data lines, and toggle E from L->H->L.

The Clear Display and Return Home commands can take up to 1.64ms, the rest take ~40usec.

Even with only 8 commands, it can be a bit confusing with all the options We only need a subset of the commands to initialize the LCD.

1. Set Interface Length - use 0011 1000 8 bit interface, 2 lines, 5x7 dot characters

2. Enable Display/Cursor - use 0000 1100 display on, no cursor

3. Clear Display - use 0000 0001 no options 4. Set Cursor Move Direction - use 0000 0110 increment cursor, no shift Then we can use Set Display Address and data writes to put characters on the display.


Writing Data

After initializing per the previous slide writing starts at the first position on line 1. To write data, we set RS=1, R/-W=0, put the ASCII character on the data lines, and toggle E from L->H->L. The controller has 80 bytes of data memory that are organized differently depending on the mode. In single line mode it starts at 0 offset and is linearly addressed to offset 0x4F. In some documents, you will see memory addressed as 0x80 0xCF; this is the actual command to set the memory address (remember command bit 0x80 indicates display address set). In 2 line mode the display memory is split with the first 40 bytes starting at offset 0 (0x80) and the second line at offset 0x40 (0xC0).

Display Addressing

The base controller can display 2 lines x 8 char. For each additional 8 characters, a display driver is added to handle another 2 lines x 8. For a 1 line x 16 characters, there are two possibilities. There could be the controller and a display driver, in which case it would look like a single line display. The other case is to use only the controller and treat it as a 2 line x 8 character display with the 2 lines on one line. This makes a difference in how you address the second 8 characters!

Four line displays, for example 4 lines x 20 characters, the other lines are mapped onto lines 1 and 2. Line 3 is the second half of line 1 and line 4 is the second half of line 2.

Line 1 0x80 0x93

Line 2 0xC0 0xD3

Line 3 0x94 0xA7

Line 4 0xD4 - 0xE7


So what about the code?

There are several ways to talk to the parallel port

1. Direct port I/O requires root authority 2. Write a kernel device driver complex (although Mark Harris has done most of the leg work for us) and non standard 3. Use the existing parallel port device driver for device /dev/parport0 This can run in user state and it is commonly available. I used this option. File device drivers support open, close, read, and write for normal operation. Unfortunately toggling control port bits is not normal operation . For hardware specific operations, the ioctl (i/o control) operation is provided. We will use this for both data and control writes. The constants are in include/linux/ppdev.h



Control Functions

When attaching an LCD display, there are several options for the control functions. Rather than invent our own, we used an existing definition originally used by a Winamp add-on. The connections are as follows.... will convert more later...



LCD Connections table
Parallel Port Port Function LCD LCD Function
18-25 GND 1 GND
-- 2 +5V
-- 3 contrast
16 initialize 4 RS
14 -linefeed 5 R/-W
1 -strobe 6 E
2 Data 0 7 DB 0
3 Data 1 8 DB 1
4 Data 2 9 DB 2
5 Data 3 10 DB 3
6 Data 4 11 DB 4
7 Data 5 12 DB 5
8 Data 6 13 DB 6
9 Data 7 14 DB 7
-- (15) (back light +)
-- (16) (back light -)

Note: Pins 15 and 16 on the LCD are not standard so may not be on every LCD. Even if an LCD has back light capability, the connections may not be on the connector

== [Download the Tarball containing source code here] ==