HD44780 general:
- Removed 'long p' from keymap HD44780 serialLpt: - Backlight support - Updated documentation
This commit is contained in:
+59
-5
@@ -73,6 +73,7 @@ You can connect a keypad with all connection types. The maximum supported
|
|||||||
number of keys differs per type. There are several ways to connect the keys
|
number of keys differs per type. There are several ways to connect the keys
|
||||||
to the input pins.
|
to the input pins.
|
||||||
|
|
||||||
|
|
||||||
1.1.2.1 Direct keys
|
1.1.2.1 Direct keys
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
@@ -168,10 +169,29 @@ You can buy arrays of keys that are connected like this in the electronics
|
|||||||
shop. They usually call it a matrix keypad. To hook it to lcdproc, you
|
shop. They usually call it a matrix keypad. To hook it to lcdproc, you
|
||||||
would only need to add the resistors and diodes.
|
would only need to add the resistors and diodes.
|
||||||
|
|
||||||
|
If you want to use just one return line, for example with the serialLpt
|
||||||
|
wiring, it looks (completely drawn) like this:
|
||||||
|
|
||||||
|
O 5V
|
||||||
|
|
|
||||||
|
.-.
|
||||||
|
| | 4k7 or 22k
|
||||||
|
diodes | |
|
||||||
|
1N4148 '-'
|
||||||
|
___ |
|
||||||
|
Y0 o---|<---o o---+
|
||||||
|
___ |
|
||||||
|
Y1 o---|<---o o---+
|
||||||
|
___ |
|
||||||
|
Y2 o---|<---o o---+
|
||||||
|
___ |
|
||||||
|
Y3 o---|<---o o---+----o return line
|
||||||
|
|
||||||
|
|
||||||
If the driver generates keypresses without that you actually press a key,
|
If the driver generates keypresses without that you actually press a key,
|
||||||
it might be that the unconnected input lines are picking up
|
it might be that the unconnected input lines are picking up
|
||||||
electromagnetic waves from the air. In that case connect the unconnected
|
electromagnetic waves from the air. In that case connect the unconnected
|
||||||
input lines (pin 10, 11, 12, 13 and 15 of the LPT) to VCC.
|
input lines (pin 10, 11, 12, 13 and 15 of the LPT) to VCC = 5V.
|
||||||
|
|
||||||
|
|
||||||
1.1.3 Backlight
|
1.1.3 Backlight
|
||||||
@@ -200,7 +220,7 @@ LPT Sub-D connector | 4k7 |
|
|||||||
=== GND
|
=== GND
|
||||||
|
|
||||||
Note: 4k7 means 4,7 kohm and 330E means 330 ohm.
|
Note: 4k7 means 4,7 kohm and 330E means 330 ohm.
|
||||||
The BC327 has the following connections:
|
The BC327 transistor has the following connections:
|
||||||
|
|
||||||
_____
|
_____
|
||||||
| |
|
| |
|
||||||
@@ -216,6 +236,11 @@ the side. If that is the case, there is usually NO RESISTOR present to limit
|
|||||||
the current through the LEDs. Therefor you should add a resistor after
|
the current through the LEDs. Therefor you should add a resistor after
|
||||||
the transistor of 10 ohm.
|
the transistor of 10 ohm.
|
||||||
|
|
||||||
|
If you want the backlight to light a bit while it's switched 'off', you can
|
||||||
|
add a resistor bypassing the transistor from e to c, with a value of, say
|
||||||
|
47ohm or 22ohm. (My 4x20 has an internal resistor of 6ohm, so with 47 ohm
|
||||||
|
extra it lights at only 1/9th. I like this. Joris.)
|
||||||
|
|
||||||
|
|
||||||
1.2 4-bit
|
1.2 4-bit
|
||||||
----------
|
----------
|
||||||
@@ -508,7 +533,14 @@ complex. If you do not understand the schematic, do not build it.
|
|||||||
|
|
|
|
||||||
=== GND
|
=== GND
|
||||||
|
|
||||||
Also the serialLpt wiring supports a keypad. The 3 wires version supports
|
|
||||||
|
1.5.1 Keypad
|
||||||
|
------------
|
||||||
|
|
||||||
|
To understand this part of the serialLpt documentation, you also need to
|
||||||
|
read the keypad section in this document.
|
||||||
|
|
||||||
|
serialLpt wiring supports a keypad. The 3 wires version supports
|
||||||
8 keys, or if you use multiple return lines up to 8 x 5 = 40 lines. The
|
8 keys, or if you use multiple return lines up to 8 x 5 = 40 lines. The
|
||||||
2 wires version supports 7 keys, or with multiple return lines
|
2 wires version supports 7 keys, or with multiple return lines
|
||||||
7 x 5 = 35 keys.
|
7 x 5 = 35 keys.
|
||||||
@@ -521,8 +553,30 @@ The return lines are the following:
|
|||||||
SELIN (13) X3
|
SELIN (13) X3
|
||||||
nFAULT (15) X4
|
nFAULT (15) X4
|
||||||
|
|
||||||
To understand some of this keypad documentation, do also read the keypad
|
On lines longer than, say a meter, you should buffer the return line(s).
|
||||||
section in this document.
|
If you only have 1 return line, you can buffer it with two remaining
|
||||||
|
buffers from the 74HCT14:
|
||||||
|
|
||||||
|
1|\ 2 13|\ 12 ___
|
||||||
|
keypad o-----| >o------| >o---|___|---+---o input pin on LPT port
|
||||||
|
return |/ |/ 220E |
|
||||||
|
IC1 IC1 ---
|
||||||
|
--- 1nF
|
||||||
|
|
|
||||||
|
===
|
||||||
|
|
||||||
|
Also a backlight is suported. You will also need a port from the 74HCT14 for
|
||||||
|
that. The BL output below should be connected to the BL input in paragraph
|
||||||
|
1.1.3.
|
||||||
|
|
||||||
|
___ 3|\ 4
|
||||||
|
Data o-----|___|--+----| >o----o BL output
|
||||||
|
LPT-D3 470k | |/
|
||||||
|
--- IC1
|
||||||
|
---
|
||||||
|
|100nF
|
||||||
|
|
|
||||||
|
===
|
||||||
|
|
||||||
|
|
||||||
2. Compiling
|
2. Compiling
|
||||||
|
|||||||
@@ -7,13 +7,21 @@
|
|||||||
* Initial table taken from lcd.o Linux kernel driver by
|
* Initial table taken from lcd.o Linux kernel driver by
|
||||||
* Nils Faerber <nilsf@users.sourceforge.net>. Thanks!
|
* Nils Faerber <nilsf@users.sourceforge.net>. Thanks!
|
||||||
*
|
*
|
||||||
* Alternative mappings used:
|
|
||||||
* #112 ("p") -> #240 (large "p"), orig. mapped -> #112
|
|
||||||
* #113 ("q") -> #241 (large "q"), orig. mapped -> #113
|
|
||||||
*
|
|
||||||
* This file is released under the GNU General Public License. Refer to the
|
* This file is released under the GNU General Public License. Refer to the
|
||||||
* COPYING file distributed with this package.
|
* COPYING file distributed with this package.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* Following translations are being performed:
|
||||||
|
* - maps umlaut accent characters to the corresponding umlaut characters
|
||||||
|
* - maps other accent characters to the characters without accents
|
||||||
|
* - maps beta (=ringel-S), micro and Yen
|
||||||
|
*
|
||||||
|
* Alternative mappings:
|
||||||
|
* - #112 ("p") -> #240 (large "p"), orig. mapped -> #112
|
||||||
|
* - #113 ("q") -> #241 (large "q"), orig. mapped -> #113
|
||||||
|
*
|
||||||
|
* HD44780 misses backslash
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char HD44780_charmap[]={
|
const char HD44780_charmap[]={
|
||||||
@@ -44,7 +52,7 @@ const char HD44780_charmap[]={
|
|||||||
84, 85, 86, 87,
|
84, 85, 86, 87,
|
||||||
88, 89, 90, 91,
|
88, 89, 90, 91,
|
||||||
/* #92 */
|
/* #92 */
|
||||||
92, 93, 94, 95,
|
47, 93, 94, 95,
|
||||||
96, 97, 98, 99,
|
96, 97, 98, 99,
|
||||||
100,101,102,103,
|
100,101,102,103,
|
||||||
104,105,106,107,
|
104,105,106,107,
|
||||||
@@ -63,7 +71,7 @@ const char HD44780_charmap[]={
|
|||||||
152,153,154,155,
|
152,153,154,155,
|
||||||
156,157,158,159,
|
156,157,158,159,
|
||||||
/* #160 */
|
/* #160 */
|
||||||
160, 33,236,163,
|
160, 33,236,237,
|
||||||
164, 92,124,167,
|
164, 92,124,167,
|
||||||
34,169,170,171,
|
34,169,170,171,
|
||||||
172,173,174,175,
|
172,173,174,175,
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ void shiftreg (unsigned char displayID, unsigned char r);
|
|||||||
#define EN2 32
|
#define EN2 32
|
||||||
|
|
||||||
static unsigned int lptPort;
|
static unsigned int lptPort;
|
||||||
|
static char backlight_bit = 0;
|
||||||
|
|
||||||
// Initialisation
|
// Initialisation
|
||||||
int
|
int
|
||||||
@@ -91,21 +92,21 @@ hd_init_serialLpt (HD44780_functions * hd44780_functions, lcd_logical_driver * d
|
|||||||
hd44780_functions->backlight = lcdserLpt_HD44780_backlight;
|
hd44780_functions->backlight = lcdserLpt_HD44780_backlight;
|
||||||
hd44780_functions->scankeypad = lcdserLpt_HD44780_scankeypad;
|
hd44780_functions->scankeypad = lcdserLpt_HD44780_scankeypad;
|
||||||
|
|
||||||
// Clear the shiftregister
|
|
||||||
rawshift (0);
|
|
||||||
|
|
||||||
// setup the lcd in 4 bit mode
|
// setup the lcd in 4 bit mode
|
||||||
shiftreg (enableLines, 3);
|
shiftreg (enableLines, 3);
|
||||||
hd44780_functions->uPause (4100);
|
hd44780_functions->uPause (15000);
|
||||||
|
|
||||||
|
shiftreg (enableLines, 3);
|
||||||
|
hd44780_functions->uPause (5000);
|
||||||
|
|
||||||
shiftreg (enableLines, 3);
|
shiftreg (enableLines, 3);
|
||||||
hd44780_functions->uPause (100);
|
hd44780_functions->uPause (100);
|
||||||
|
|
||||||
shiftreg (enableLines, 3);
|
shiftreg (enableLines, 3);
|
||||||
hd44780_functions->uPause (40);
|
hd44780_functions->uPause (100);
|
||||||
|
|
||||||
shiftreg (enableLines, 2);
|
shiftreg (enableLines, 2);
|
||||||
hd44780_functions->uPause (40);
|
hd44780_functions->uPause (100);
|
||||||
|
|
||||||
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR);
|
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR);
|
||||||
|
|
||||||
@@ -135,42 +136,59 @@ lcdserLpt_HD44780_senddata (unsigned char displayID, unsigned char flags, unsign
|
|||||||
|
|
||||||
shiftreg (enableLines, portControl | h);
|
shiftreg (enableLines, portControl | h);
|
||||||
shiftreg (enableLines, portControl | l);
|
shiftreg (enableLines, portControl | l);
|
||||||
|
|
||||||
|
// Restore line status for backlight
|
||||||
|
port_out (lptPort, backlight_bit );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
lcdserLpt_HD44780_backlight (unsigned char state)
|
lcdserLpt_HD44780_backlight (unsigned char state)
|
||||||
{
|
{
|
||||||
|
// Store new state
|
||||||
|
backlight_bit = (state?LCDDATA:0);
|
||||||
|
|
||||||
|
// Set line status for backlight
|
||||||
|
port_out (lptPort, backlight_bit );
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char lcdserLpt_HD44780_scankeypad ()
|
unsigned char lcdserLpt_HD44780_scankeypad ()
|
||||||
{
|
{
|
||||||
// Unfortunately just bit shifting does not work with the 2 IC version...
|
// Unfortunately just bit shifting does not work with the 2-wire version...
|
||||||
|
|
||||||
unsigned char keybits;
|
unsigned char keybits;
|
||||||
unsigned int shiftcount;
|
unsigned int shiftcount;
|
||||||
unsigned int shiftingbit;
|
unsigned int shiftingbit;
|
||||||
unsigned char readval, inputs_zero, r;
|
unsigned char readval, inputs_zero;
|
||||||
int i;
|
int i;
|
||||||
unsigned int scancode = 0;
|
unsigned int scancode = 0;
|
||||||
|
|
||||||
|
// While scanning the keypad, the 2-wire version executes the 0xFF
|
||||||
|
// command. This command sets the cursor position, so it's harmless.
|
||||||
|
// I could not prevent this, while staying compatible with both
|
||||||
|
// wiring versions.
|
||||||
|
|
||||||
r = 0xFF; // This command will set the cursor position, so it's harmless
|
// Clear the shiftregister, needed for 3-wire version
|
||||||
|
rawshift(0);
|
||||||
|
hd44780_functions->uPause (2);
|
||||||
|
|
||||||
readval = ~ port_in (lptPort + 1) ^ INMASK;
|
readval = ~ port_in (lptPort + 1) ^ INMASK;
|
||||||
inputs_zero = ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) );
|
inputs_zero = ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) );
|
||||||
|
|
||||||
if( inputs_zero == 0 ) {
|
if( inputs_zero == 0 ) {
|
||||||
|
// No keys were pressed
|
||||||
|
|
||||||
|
// Restore line status for backlight.
|
||||||
|
port_out (lptPort, backlight_bit );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan the keypad while sending the first half of the command (high nibble)
|
// Scan the keypad while sending the first half of the command (high nibble)
|
||||||
for (i = 7; i >= 0; i--) { /* MSB first */
|
for (i = 7; i >= 0; i--) { /* MSB first */
|
||||||
port_out (lptPort, ((r >> i) & 1) * LCDDATA); /*set up data */
|
port_out (lptPort, LCDDATA); /*set up data */
|
||||||
port_out (lptPort, (((r >> i) & 1) * LCDDATA) | LCDCLOCK); /*rising edge of clock */
|
port_out (lptPort, LCDDATA | LCDCLOCK); /*rising edge of clock */
|
||||||
|
|
||||||
hd44780_functions->uPause (2);
|
hd44780_functions->uPause (2);
|
||||||
|
|
||||||
// Do keyscan too !
|
|
||||||
if( !scancode ) {
|
if( !scancode ) {
|
||||||
// Read input line(s)
|
// Read input line(s)
|
||||||
readval = ~ port_in (lptPort + 1) ^ INMASK;
|
readval = ~ port_in (lptPort + 1) ^ INMASK;
|
||||||
@@ -188,12 +206,18 @@ unsigned char lcdserLpt_HD44780_scankeypad ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hd44780_functions->uPause (4);
|
// Wait for 2-wire version to clear the latch...
|
||||||
|
hd44780_functions->uPause (6);
|
||||||
|
|
||||||
// And again for the second half of the command (low nibble)
|
// And again for the second half of the command (low nibble).
|
||||||
rawshift (r);
|
// Needed for 2-wire version.
|
||||||
|
rawshift (0xFF);
|
||||||
|
|
||||||
hd44780_functions->uPause (4);
|
// Wait for 2-wire version to clear the latch...
|
||||||
|
hd44780_functions->uPause (6);
|
||||||
|
|
||||||
|
// Restore line status for backlight.
|
||||||
|
port_out (lptPort, backlight_bit );
|
||||||
|
|
||||||
return scancode;
|
return scancode;
|
||||||
}
|
}
|
||||||
@@ -203,7 +227,6 @@ void
|
|||||||
rawshift (unsigned char r)
|
rawshift (unsigned char r)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
// r |= 0x80; // just to make sure ...
|
|
||||||
|
|
||||||
for (i = 7; i >= 0; i--) { /* MSB first */
|
for (i = 7; i >= 0; i--) { /* MSB first */
|
||||||
port_out (lptPort, ((r >> i) & 1) * LCDDATA); /*set up data */
|
port_out (lptPort, ((r >> i) & 1) * LCDDATA); /*set up data */
|
||||||
@@ -215,9 +238,9 @@ rawshift (unsigned char r)
|
|||||||
void
|
void
|
||||||
shiftreg (unsigned char enableLines, unsigned char r)
|
shiftreg (unsigned char enableLines, unsigned char r)
|
||||||
{
|
{
|
||||||
rawshift (r | 0x80); // highest bit always set to 1 for Clear for wiring with 2 ICs
|
rawshift (r | 0x80); // highest bit always set to 1 for Clear for 2-wire version
|
||||||
port_out (lptPort, enableLines); // latch it, to correct display
|
port_out (lptPort, enableLines); // latch it, to correct display
|
||||||
hd44780_functions->uPause (1);
|
hd44780_functions->uPause (1);
|
||||||
port_out (lptPort, 0); // for wiring with 1 IC
|
port_out (lptPort, 0); // for 3-wire version
|
||||||
hd44780_functions->uPause (3);
|
hd44780_functions->uPause (5); // wait for 2-wire version to clear the latch...
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user