HD44780 keypad update. (second try)

This commit is contained in:
robijn
2001-10-05 21:01:24 +00:00
parent 4829ed367f
commit 16cce2fe2d
4 changed files with 355 additions and 141 deletions
+72 -20
View File
@@ -4,16 +4,19 @@
* PC parallel port.
*
* Copyright (c) 1999 Andrew McMeikan <andrewm@engineer.com>
* modular driver 1999-2000 Benjamin Tse <blt@Comports.com>
* modular driver 1999-2000 Benjamin Tse <blt@Comports.com>
*
* Modified July 2000 by Charles Steinkuehler for enhanced
* performance and reduced CPU usage
* - provided required setup time for RS valid to E high
* - 1 uS call to uPause removed as it is unnecessary
*
* 2001 Joris Robijn <joris@robijn.net>
* - Keypad support
*
* The connections are:
* printer port LCD
* D0 (2) D0 (7)
* printer port LCD
* D0 (2) D0 (7)
* D1 (3) D1 (8)
* D2 (4) D2 (9)
* D3 (5) D3 (10)
@@ -26,6 +29,26 @@
* INIT (16) RS (4)
* nSEL (17) EN2 (6 - LCD 2) (optional)
*
* Keypad connection (optional):
* Some diodes and resistors are needed, see further documentation.
* printer port keypad
* D0 (2) Y0
* D1 (3) Y1
* D2 (4) Y2
* D3 (5) Y3
* D4 (6) Y4
* D5 (7) Y5
* D6 (7) Y6
* D7 (7) Y7
* nLF (14) Y8
* INIT (16) Y9
* nSEL (17) Y10
* nACK (10) X0
* BUSY (11) X1
* PAPEREND (12) X2
* SELIN (13) X3
* nFAULT (15) X4
*
* Created modular driver Dec 1999, Benjamin Tse <blt@Comports.com>
*
* This file is released under the GNU General Public License. Refer to the
@@ -33,25 +56,30 @@
*/
#include "hd44780-winamp.h"
#include "port.h"
#include "hd44780.h"
#include "port.h"
#include "shared/str.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
void lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch);
#include "port.h"
#define EN1 STRB
#define EN2 SEL
#define EN3 LF
#define RS INIT
void lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch);
unsigned char lcdwinamp_HD44780_readkeypad (unsigned int YData);
#define EN1 STRB
#define EN2 SEL
#define EN3 LF
#define RS INIT
static unsigned char EnMask[] = { EN1, EN2, EN3 };
static int EnMaskSize = sizeof (EnMask) / sizeof (unsigned char);
static int extIF = 0; // non-zero if extended interface
static unsigned int lptPort;
static int extIF = 0; // non-zero if extended interface
static char stuckinputs = 0; // if an input line is stuck, it will be ignored
// initialise the driver
int
@@ -62,22 +90,32 @@ hd_init_winamp (HD44780_functions * hd44780_functions, lcd_logical_driver * driv
int argc;
int i;
hd44780_functions->senddata = lcdwinamp_HD44780_senddata;
// Reserve the port registers
lptPort = port;
port_access(lptPort);
port_access(lptPort+1);
port_access(lptPort+2);
hd44780_functions->senddata = lcdwinamp_HD44780_senddata;
hd44780_functions->readkeypad = lcdwinamp_HD44780_readkeypad;
// parse command-line arguments
argc = get_args (argv, args, 64);
for (i = 0; i < argc; ++i)
for (i = 0; i < argc; ++i) {
if (strcmp (argv[i], "-e") == 0 || strcmp (argv[i], "--extended") == 0)
extIF = 1;
if (port_access (lptPort + 2) || port_access (lptPort)) {
fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno));
return -1;
}
common_init (IF_8bit);
// setup the lcd in 8 bit mode
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT);
hd44780_functions->uPause (4100);
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT);
hd44780_functions->uPause (100);
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT | TWOLINE | SMALLCHAR);
hd44780_functions->uPause (40);
common_init ();
return 0;
}
@@ -100,12 +138,12 @@ lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsign
// 40 nS setup time for RS valid to EN high, so set RS
port_out (lptPort + 2, portControl ^ OUTMASK);
// then set EN high
port_out (lptPort + 2, (dispID | portControl) ^ OUTMASK);
// Output the actual data
port_out (lptPort, ch);
// then set EN high
port_out (lptPort + 2, (dispID | portControl) ^ OUTMASK);
// 80 nS setup from valid data to EN low will be met without any delay
// unless you are running a REALLY FAST ISA bus (like 75 MHZ!)
// 230 nS minimum E high time provided by ISA bus delays as well...
@@ -115,3 +153,17 @@ lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsign
// 10 nS data hold time provided by the length of ISA write for EN
}
unsigned char lcdwinamp_HD44780_readkeypad (unsigned int YData)
{
unsigned char readval;
// 10 bits output
// Convert the positive logic to the negative logic on the LPT port
port_out (lptPort, ~YData & 0x00FF );
port_out (lptPort + 2, ( ((~YData & 0x0100) >> 7) | ((~YData & 0x0200) >> 7 )) ^ OUTMASK);
// And convert it back.
readval = ~ port_in (lptPort + 1) ^ INMASK;
return ( (readval >> 4 & 0x03) | (readval >> 5 & 0x04) | (readval >> 3 & 0x08) | (readval << 1 & 0x10) ) & ~stuckinputs;
}