HD44780 general:

- Removed 'long p' from keymap

HD44780 serialLpt:
- Backlight support
- Updated documentation
This commit is contained in:
robijn
2001-12-09 14:33:17 +00:00
parent d0511bb7d8
commit 3929662434
3 changed files with 122 additions and 37 deletions
+44 -21
View File
@@ -74,6 +74,7 @@ void shiftreg (unsigned char displayID, unsigned char r);
#define EN2 32
static unsigned int lptPort;
static char backlight_bit = 0;
// Initialisation
int
@@ -91,21 +92,21 @@ hd_init_serialLpt (HD44780_functions * hd44780_functions, lcd_logical_driver * d
hd44780_functions->backlight = lcdserLpt_HD44780_backlight;
hd44780_functions->scankeypad = lcdserLpt_HD44780_scankeypad;
// Clear the shiftregister
rawshift (0);
// setup the lcd in 4 bit mode
shiftreg (enableLines, 3);
hd44780_functions->uPause (4100);
hd44780_functions->uPause (15000);
shiftreg (enableLines, 3);
hd44780_functions->uPause (5000);
shiftreg (enableLines, 3);
hd44780_functions->uPause (100);
shiftreg (enableLines, 3);
hd44780_functions->uPause (40);
hd44780_functions->uPause (100);
shiftreg (enableLines, 2);
hd44780_functions->uPause (40);
hd44780_functions->uPause (100);
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 | l);
// Restore line status for backlight
port_out (lptPort, backlight_bit );
}
void
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 ()
{
// 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 int shiftcount;
unsigned int shiftingbit;
unsigned char readval, inputs_zero, r;
unsigned char readval, inputs_zero;
int i;
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;
inputs_zero = ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) );
if( inputs_zero == 0 ) {
// No keys were pressed
// Restore line status for backlight.
port_out (lptPort, backlight_bit );
return 0;
}
// Scan the keypad while sending the first half of the command (high nibble)
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) | LCDCLOCK); /*rising edge of clock */
for (i = 7; i >= 0; i--) { /* MSB first */
port_out (lptPort, LCDDATA); /*set up data */
port_out (lptPort, LCDDATA | LCDCLOCK); /*rising edge of clock */
hd44780_functions->uPause (2);
// Do keyscan too !
if( !scancode ) {
// Read input line(s)
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)
rawshift (r);
// And again for the second half of the command (low nibble).
// 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;
}
@@ -203,7 +227,6 @@ void
rawshift (unsigned char r)
{
int i;
// r |= 0x80; // just to make sure ...
for (i = 7; i >= 0; i--) { /* MSB first */
port_out (lptPort, ((r >> i) & 1) * LCDDATA); /*set up data */
@@ -215,9 +238,9 @@ rawshift (unsigned char r)
void
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
hd44780_functions->uPause (1);
port_out (lptPort, 0); // for wiring with 1 IC
hd44780_functions->uPause (3);
port_out (lptPort, 0); // for 3-wire version
hd44780_functions->uPause (5); // wait for 2-wire version to clear the latch...
}