Modifications for a portable and maintable HD44780 lcd driver

This commit is contained in:
blt
2000-02-21 11:23:08 +00:00
parent 8411ee67d1
commit 6cefefd52c
3 changed files with 514 additions and 429 deletions
+7 -1
View File
@@ -2,7 +2,13 @@ noinst_LIBRARIES = libLCDdrivers.a
libLCDdrivers_a_SOURCES = lcd.c lcd.h drv_base.c libLCDdrivers_a_SOURCES = lcd.c lcd.h drv_base.c
EXTRA_libLCDdrivers_a_SOURCES = MtxOrb.c MtxOrb.h text.c text.h \ EXTRA_libLCDdrivers_a_SOURCES = MtxOrb.c MtxOrb.h text.c text.h \
curses_drv.c curses_drv.h drv_base.c drv_base.h \ curses_drv.c curses_drv.h drv_base.c drv_base.h \
hd44780.c hd44780.h port.h joy.c joy.h irmanin.c irmanin.h \ hd44780.c hd44780.h \
hd44780-4bit.c hd44780-4bit.h \
hd44780-ext8bit.c hd44780-ext8bit.h lcd_sem.c lcd_sem.h \
hd44780-serialLpt.c hd44780-serialLpt.h \
hd44780-winamp.c hd44780-winamp.h \
hd44780-low.h hd44780-drivers.h \
port.h joy.c joy.h irmanin.c irmanin.h \
CFontz.c CFontz.h lircin.c lircin.h debug.h CFontz.c CFontz.h lircin.c lircin.h debug.h
libLCDdrivers_a_DEPENDENCIES = @DRIVERS@ libLCDdrivers_a_DEPENDENCIES = @DRIVERS@
libLCDdrivers_a_LIBADD = @DRIVERS@ libLCDdrivers_a_LIBADD = @DRIVERS@
+360 -270
View File
@@ -1,41 +1,33 @@
/* Driver module for Hitachi HD44780 based Optrex DMC-20481 LCD display /*
* The module is operated in it's 4 bit-mode to be connected to a single * Base driver module for Hitachi HD44780 based LCD displays. This is
* 8 bit-port * a modular driver that readily allows support for alternative HD44780
* designs to be added in a flexible and maintainable manner.
* *
* Modified 16-19 Nov 1999 Andrew McMeikan * This driver also supports the aggregation of multiple displays to form
* fixed hard coded geometry issues, finished support for split screens * a single virtual display. e.g., Four 16x2 displays can be combined
* to form a 16x8 display.
* *
* Modified 10 Nov 1999 Andrew McMeikan * To add support for additional HD44780 connections:
* put back in Benjamin Tse's LCD_Pause to avoid timing errors * 1. Add a connection type and mapping to hd44780-drivers.h
* 13 Nov, fixed delay times in old 4 bit code * 2. Call your initialisation routine
* Modified 19-26 Oct 1999 Andrew McMeikan <andrewm@engineer.com> * 3. Create the low-level driver (use hd44780-ext8bit.c as a starting point)
* to support connection via a shift register with keypad * 4. Modify the makefile
* 4094 conection details at http://members.xoom.com/andrewmuck/LCD.htm
* TODO: document connections
* also started mods for two lcd enable lines (40x4) or 2x(2x20)
* *
* Copyright (c) 1998 Richard Rognlie GNU Public License * Modular driver created and generic support for multiple displays added
* <rrognlie@gamerz.net> * Dec 1999, Benjamin Tse <blt@Comports.com>
* *
* Large quantities of this code lifted (nearly verbatim) from * This file is released under the GNU General Public License. Refer to the
* the lcd4.c module of lcdtext. Copyright (C) 1997 Matthias Prinke * COPYING file distributed with this package.
* <m.prinke@trashcan.mcnet.de> and covered by GNU's GPL.
* In particular, this program is free software and comes WITHOUT
* ANY WARRANTY.
* *
* Matthias stole (er, adapted) the code from the package lcdtime by * Copyright (c) 2000, 1999, 1995 Benjamin Tse <blt@Comports.com>
* Benjamin Tse (blt@mundil.cs.mu.oz.au), August/October 1995 * 1999 Andrew McMeikan <andrewm@engineer.com>
* which uses the LCD-controller's 8 bit-mode. * 1998 Richard Rognlie <rrognlie@gamerz.net>
* References: port.h by <damianf@wpi.edu> * 1997 Matthias Prinke <m.prinke@trashcan.mcnet.de>
* Data Sheet LTN211, Philips
* Various FAQs and TXTs about Hitachi's LCD Controller HD44780 -
* www.paranoia.com/~filipg is a good starting point ???
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <termios.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
@@ -47,217 +39,233 @@
#include "hd44780.h" #include "hd44780.h"
#include "drv_base.h" #include "drv_base.h"
#include "hd44780-low.h"
#include "hd44780-drivers.h"
// default parallel port address
#ifndef LPTPORT
#define LPTPORT 0x378
#endif
unsigned int port = LPTPORT;
lcd_logical_driver *HD44780; lcd_logical_driver *HD44780;
HD44780_functions *hd44780_functions;
// default value
static enum connectionType connection = HD_4bit;
static int connIdx = 0;
// spanList[line number] = display line number is in
static int *spanList = NULL;
static int numLines = 0;
// dispVOffset is a cumulative sized array of line numbers for each display.
// use this to determine the vertical positioning on a given display
static int *dispVOffset = NULL;
static int numDisplays = 0;
// dispSizes is the vertical size of each display. This is the same as the
// input span list but is kept to save some cpu cycles.
static int *dispSizes = NULL;
/* shift register code by andrewm@engineer.com * // function declarations
* uncomment the next line if you do want to use * void HD44780_flush();
* a shift register to connect to the LCD */ void HD44780_flush_box(int lft, int top, int rgt, int bot);
//#define USE_SHIFT_REG int HD44780_contrast(int contrast);
void HD44780_backlight(int on);
//#define SPLIT_SCREENS void HD44780_init_vbar();
/* If you are using two LCD Displays or an 8 line or a * void HD44780_init_hbar();
* 40x4 you want to define SPLIT_SCREENS */ void HD44780_vbar(int x, int len);
void HD44780_hbar(int x, int y, int len);
#define FONTSIZE 0 void HD44780_init_num();
// 4= 7line font 0=10 line font (default was 0=10 line andrewm) void HD44780_num(int x, int num);
void HD44780_set_char(int n, char *dat);
#define RW 32 void HD44780_icon(int which, char dest);
#define RS 16 void HD44780_draw_frame(char *dat);
#ifndef USE_SHIFT_REG void HD44780_close();
#define LCDEN 64
#ifdef SPLIT_SCREENS
#define SECONDLCDEN 128
#endif
#endif
#ifdef USE_SHIFT_REG
#define LCDDATA 8
#define LCDCLOCK 16
#define LCDEN 4
#ifdef SPLIT_SCREENS
#define SECONDLCDEN 32
#endif
#endif
#ifndef SECONDLCDEN
#define SECONDLCDEN 0
#endif
#ifndef LPTPORT
unsigned int port = 0x378;
#else
unsigned int port = LPTPORT;
#endif
static int lcd_x=0;
static int lcd_y=0;
static void HD44780_linewrap(int on); static void HD44780_linewrap(int on);
static void HD44780_autoscroll(int on); static void HD44780_autoscroll(int on);
static void HD44780_position(int x, int y);
static int lp; static void common_position(int display, int DDaddr);
static void common_autoscroll(int on);
static void uPause(int delayCalls);
static void HD44780_senddata(unsigned char displayID,
unsigned char flags,
unsigned char ch);
static int parse_span_list(int *spanListArray[], int *spLsize,
// IO delay to avoid a task switch int *dispOffsets[], int *dOffsize,
void LCD_Pause(int delayCalls) int *dispSizeArray[], char *spanlist);
{
int i;
for (i = 0; i < delayCalls; ++i)
port_in(port);
//TODO: put in option for nanosleep rather than dummy I/O call
}
#ifdef USE_SHIFT_REG
static char lastkey=0;
static char HD44780_getkey();
void rawshift (unsigned char r) /* this function sends r out *
* onto the shift register */
{
int i;
for (i=7;i>=0;i--) /* MSB first */
{
port_out(lp,((r>>i)&1)*LCDDATA); /*set up data */
port_out(lp,(((r>>i)&1)*LCDDATA)|LCDCLOCK);/*rising edge of clock */
}
}
void shiftreg (unsigned char displayID, unsigned char r)
{
rawshift(r);
port_out(lp,displayID); //latch it, to correct display
port_out(lp,0);
}
#endif
static void HD44780_senddata(unsigned char displayID, unsigned char flags, unsigned char ch)
{
unsigned char h = ch >> 4;
unsigned char l = ch & 15;
#ifndef USE_SHIFT_REG
port_out(lp, displayID | flags | h);LCD_Pause(1);
port_out(lp, flags | h);
port_out(lp, displayID | flags | l);LCD_Pause(1);
port_out(lp, flags | l);
#else
shiftreg(displayID,flags|h);
shiftreg(displayID,flags|l);
/*all actions take at least 40us to execute TODO:instead of delay read keys here */
#endif
LCD_Pause(50);
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly... // Opens com port and sets baud correctly...
// //
int HD44780_init(lcd_logical_driver *driver, char *args) int HD44780_init(lcd_logical_driver *driver, char *args)
{ {
char *argv[64]; // TODO: remove the two magic numbers below
int argc; // TODO: single point of return
int i; char *argv[64], *str;
char displayID = LCDEN|SECONDLCDEN; int argc, i;
HD44780 = driver; HD44780 = driver;
// get_args inserts \0 into args - nasty !
if (args)
if ((str = (char *) malloc(strlen(args) + 1)))
strcpy(str, args);
else
{
fprintf(stderr, "Error mallocing\n");
return -1;
}
else
str = NULL;
argc = get_args(argv, args, 64); argc = get_args(argv, args, 64);
// arguments are passed in with -d HD44780 "-p 0x278"
// getopt will work well here
for(i=0; i<argc; i++) for(i=0; i<argc; i++)
{ {
//printf("Arg(%i): %s\n", i, argv[i]);
if(0 == strcmp(argv[i], "-p") || if(0 == strcmp(argv[i], "-p") ||
0 == strcmp(argv[i], "--port")) 0 == strcmp(argv[i], "--port"))
{ {
if(i + 1 > argc) { if(i + 1 >= argc) {
fprintf(stderr, "HD44780_init: %s requires an argument\n", fprintf(stderr, "HD44780_init: %s requires an argument\n",
argv[i]); argv[i]);
return -1; return -1;
} else {
int myport;
if (sscanf(argv[i + 1], "%i", &myport) != 1) {
fprintf(stderr, "HD44780_init: Couldn't read port address -"
" using default value 0x%x\n", port);
return -1;
} else {
port = myport;
++i;
}
} }
printf("Sorry, runtime lpt-port switching not yet implemented...\n");
//strcpy(device, argv[++i]);
} }
else if(0 == strcmp(argv[i], "-c") || else if(0 == strcmp(argv[i], "-c") ||
0 == strcmp(argv[i], "--contrast")) 0 == strcmp(argv[i], "--connect"))
{ {
if(i + 1 > argc) { int j = 0;
if(i + 1 >= argc) {
fprintf(stderr, "HD44780_init: %s requires an argument\n", fprintf(stderr, "HD44780_init: %s requires an argument\n",
argv[i]); argv[i]);
return -1; return -1;
} }
printf("Sorry, contrast changing not yet implemented...\n"); // search the next argument for the connection type
//contrast = atoi(argv[++i]); for (j = 0;
strcmp(argv[i + 1], connectionMapping[j].connectionTypeStr) != 0
&& connectionMapping[j].type != HD_unknown;
++j)
;
if (connectionMapping[j].type == HD_unknown)
{
fprintf(stderr,
"HD44780_init: Unknown connection type - using default %s driver\n",
connectionMapping[0].connectionTypeStr);
connection = connectionMapping[0].type;
j = 0;
}
else
connection = connectionMapping[j].type;
connIdx = j;
++i;
}
else if(0 == strcmp(argv[i], "-v") ||
0 == strcmp(argv[i], "--vspan"))
{
int j = 0;
if(i + 1 >= argc) {
fprintf(stderr, "HD44780_init: %s requires an argument\n",
argv[i]);
return -1;
}
if (parse_span_list(&spanList, &numLines,
&dispVOffset, &numDisplays,
&dispSizes, argv[i + 1]) == -1)
{
fprintf(stderr, "HD44780_init: invalid vspan argument\n");
return -1;
}
++i;
} }
else if(0 == strcmp(argv[i], "-h") || else if(0 == strcmp(argv[i], "-h") ||
0 == strcmp(argv[i], "--help")) 0 == strcmp(argv[i], "--help"))
{ {
int i;
printf("LCDproc HD44780 driver\n" printf("LCDproc HD44780 driver\n"
"\t-p\t--port\tSelect the output device to use [0x%x]\n" "\t-p n\t--port n\tSelect the output device to use port n\n"
"\t-c\t--contrast\tSet the initial contrast [default]\n" "\t-c type\t--connect type\tSet the connection type (default 4 bit)\n"
"\t-h\t--help\t\tShow this help information\n", "\t\t\t\ttype = %s", connectionMapping[0].connectionTypeStr);
port); for (i = 1; connectionMapping[i].type != HD_unknown; ++i)
printf(" | %s", connectionMapping[i].connectionTypeStr);
printf("\n\t-v spanlist\t--vspan spanlist\tvertical span n{,m}\n"
"\t-h\t--help\t\tShow this help information\n"
"\n\tNote that the '-t' option should precede the '-d' option\n");
if (connectionMapping[connIdx].type != HD_unknown)
{
printf("\n Parameters for %s driver\n",
connectionMapping[connIdx].connectionTypeStr);
printf("%s", connectionMapping[connIdx].helpMsg);
}
return -1; return -1;
} }
/* ignore invalid arguments as they might be valid to the lower-level init
else else
{ {
printf("Invalid parameter: %s\n", argv[i]); printf("Invalid parameter: %s\n", argv[i]);
} }
*/
} }
// default case for when spans aren't indicated
// - add a sanity check against lcd.hgt ??
// - this only works if the -t option is specified before -d
if (numLines == 0)
{
if ((spanList = (int *) malloc(sizeof(int) * lcd.hgt)))
{
int i;
for (i = 0; i < lcd.hgt; ++i)
{
spanList[i] = 1;
numLines = lcd.hgt;
}
}
else
fprintf(stderr, "Error mallocing for span list\n");
}
if (numDisplays == 0)
{
if ((dispVOffset = (int *) malloc(sizeof(int))) &&
(dispSizes = (int *) malloc(sizeof(int))))
{
dispVOffset[0] = 0;
dispSizes[0] = lcd.hgt;
numDisplays = 1;
}
else
fprintf(stderr, "Error mallocing for display sizes list\n");
}
// Set up io port correctly, and open it... // Set up io port correctly, and open it...
if ((ioperm(port,2,255)) == -1) { if ((ioperm(port, 1, 255)) == -1) {
fprintf(stderr, "HD44780_init: failed (%s)\n", strerror(errno)); fprintf(stderr, "HD44780_init: failed (%s)\n", strerror(errno));
return -1; return -1;
} }
lp = port;
// init HD44780
#ifndef USE_SHIFT_REG
port_out(lp,displayID | 3); LCD_Pause(4100);
port_out(lp,displayID | 3); LCD_Pause(100);
port_out(lp,displayID | 3); LCD_Pause(40);
// now in 8-bit mode... set 4-bit mode
port_out(lp,displayID | 2); LCD_Pause(40);
#else
shiftreg(displayID,3);
LCD_Pause(4100);
shiftreg(displayID,3);
LCD_Pause(100);
shiftreg(displayID,3);
LCD_Pause(40);
shiftreg(displayID,2);
LCD_Pause(40);
#endif
// now in 4-bit mode...
// set display type function set(32) data8/4 (16) set 2 line(8), small char mode(4)
HD44780_senddata(displayID,0, 32 | 8 | FONTSIZE);
//clear
HD44780_senddata(displayID,0, 1);LCD_Pause(1600);
// set lcd on (4), cursor_on (2), and cursor_blink(1)
HD44780_senddata(displayID,0, 8 | 4 | 0 | 0);LCD_Pause(1600);
// Set display-specific stuff..
//HD44780_linewrap(1);
//HD44780_autoscroll(1);
// Make sure the frame buffer is there... // Make sure the frame buffer is there...
if (!HD44780->framebuf) if (!HD44780->framebuf)
HD44780->framebuf = (unsigned char *) malloc(lcd.wid * lcd.hgt); HD44780->framebuf = (unsigned char *) malloc(lcd.wid * lcd.hgt);
@@ -269,7 +277,7 @@ LCD_Pause(40);
// Set the functions the driver supports... // Set the functions the driver supports...
// These are the default HD44780 functions
driver->clear = (void *)-1; driver->clear = (void *)-1;
driver->string = (void *)-1; driver->string = (void *)-1;
driver->chr = (void *)-1; driver->chr = (void *)-1;
@@ -289,15 +297,76 @@ LCD_Pause(40);
driver->set_char = HD44780_set_char; driver->set_char = HD44780_set_char;
driver->icon = HD44780_icon; driver->icon = HD44780_icon;
driver->draw_frame = HD44780_draw_frame; driver->draw_frame = HD44780_draw_frame;
#ifndef USE_SHIFT_REG
driver->getkey = NULL; driver->getkey = NULL;
#else
driver->getkey = HD44780_getkey;
#endif
return lp; if ((hd44780_functions =
(HD44780_functions *) malloc(sizeof(HD44780_functions))) == NULL)
{
return -1;
}
hd44780_functions->uPause = uPause;
hd44780_functions->position = common_position;
hd44780_functions->autoscroll = common_autoscroll;
connectionMapping[connIdx].init_fn(hd44780_functions, driver, str, port);
HD44780_autoscroll(0);
return port;
} }
// common initialisation sequence - sets twoline, small characters (5x8),
// cursor off and not blinking, clear display and homecursor
void common_init(enum ifWidth ifwidth)
{
if (ifwidth == 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);
hd44780_functions->uPause(40);
}
// else 4bit
// senddata can't generate the timings to initialise a four bit device
// properly but it might just work properly anyway ....
// set display type functions
hd44780_functions->senddata(0,
RS_INSTR,
FUNCSET |
((ifwidth == IF_4BIT) ? IF_4BIT : IF_8BIT) |
TWOLINE | SMALLCHAR);
hd44780_functions->uPause(40);
hd44780_functions->senddata(0,
RS_INSTR,
ONOFFCTRL | DISPON | CURSOROFF | CURSORNOBLINK);
hd44780_functions->uPause(40);
hd44780_functions->senddata(0, RS_INSTR, CLEAR);
hd44780_functions->uPause(1600);
hd44780_functions->senddata(0, RS_INSTR, HOMECURSOR);
hd44780_functions->uPause(1600);
}
// IO delay to avoid a task switch
void uPause(int delayCalls)
{
int i;
for (i = 0; i < delayCalls; ++i)
port_in(port);
//TODO: put in option for nanosleep rather than dummy I/O call
}
// displayID - ID of display to use (0 = all displays)
static void HD44780_senddata(unsigned char displayID, unsigned char flags, unsigned char ch)
{
hd44780_functions->senddata(displayID, flags, ch);
hd44780_functions->uPause(40);
}
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -310,30 +379,31 @@ void HD44780_close()
} }
*/ */
// x and y here are for the virtual lcd.hgt x lcd.wid display
static void HD44780_position(int x, int y) static void HD44780_position(int x, int y)
{ {
int val = x + (y%2) * 0x40; int dispID = spanList[y];
if ((y%4)>=2) val += lcd.wid; int relY = y - dispVOffset[dispID - 1];
if (lcd.hgt==1) val += (x%8) * (0x40-8); //cope with 16x1 display int DDaddr;
#ifndef SPLIT_SCREENS
HD44780_senddata(LCDEN,0,128|val);
#else
if (y<(lcd.hgt/2))
{
if (lcd.hgt==2) val += (x%8) * (0x40-8);// two 16x1 displays
HD44780_senddata(LCDEN,0,128|val);
}
else
{
val = x + ((y-(lcd.hgt/2))%2) * 0x40;
if (((y-(lcd.hgt/2))%4)>=2) val += lcd.wid;
if (lcd.hgt==2) val += (x%8) * (0x40-8);// two 16x1 displays
HD44780_senddata(SECONDLCDEN,0,128|val);
}
#endif
lcd_x = x;
lcd_y = y;
// 16x1 is a special case
if (dispSizes[dispID - 1] == 1 && lcd.wid == 16)
if (x >= 8)
{
x -= 8; relY = 1;
}
DDaddr = x + (relY % 2) * 0x40;
if ((relY % 4) >= 2)
DDaddr += lcd.wid;
hd44780_functions->position(dispID, DDaddr);
}
void common_position(int display, int DDaddr)
{
hd44780_functions->senddata(display, RS_INSTR, POSITION | DDaddr);
hd44780_functions->uPause(40);
} }
void HD44780_flush() void HD44780_flush()
@@ -352,19 +422,8 @@ void HD44780_flush_box(int lft, int top, int rgt, int bot)
HD44780_position(lft,y); HD44780_position(lft,y);
//printf("\n%d,%d :",lft,y); //printf("\n%d,%d :",lft,y);
for (x=lft ; x<=rgt ; x++) { for (x=lft ; x<=rgt ; x++) {
if ((lcd.hgt==1)&&(x==8)) HD44780_position(x,y); HD44780_senddata(spanList[y], RS_DATA,
//cope with 16x1 display lcd.framebuf[(y*lcd.wid)+x]);
#ifdef SPLIT_SCREENS
if ((lcd.hgt==2)&&(x==8)) HD44780_position(x,y); //two 16x1's
if (y<(lcd.hgt/2))
HD44780_senddata(LCDEN,RS,lcd.framebuf[(y*lcd.wid)+x]);
else
HD44780_senddata(SECONDLCDEN,RS,lcd.framebuf[(y*lcd.wid)+x]);
//printf("%c",lcd.framebuf[(y*lcd.wid)+x]);
#else
HD44780_senddata(LCDEN,RS,lcd.framebuf[(y*lcd.wid)+x]);
#endif
} }
//write(fd, lcd.framebuf[(y*lcd.wid)+lft, rgt-lft+1]); //write(fd, lcd.framebuf[(y*lcd.wid)+lft, rgt-lft+1]);
} }
@@ -401,8 +460,15 @@ static void HD44780_linewrap(int on)
// //
static void HD44780_autoscroll(int on) static void HD44780_autoscroll(int on)
{ {
HD44780_senddata(LCDEN|SECONDLCDEN,0,4 | on * 2); hd44780_functions->autoscroll(on);
LCD_Pause(1600); //this can take time to do on some displays }
void common_autoscroll(int on)
{
hd44780_functions->senddata(0, RS_INSTR,
ENTRYMODE | E_MOVERIGHT |
((on) ? EDGESCROLL : NOSCROLL));
hd44780_functions->uPause(1600);
} }
@@ -489,7 +555,6 @@ void HD44780_init_vbar()
HD44780_set_char(5,e); HD44780_set_char(5,e);
HD44780_set_char(6,f); HD44780_set_char(6,f);
HD44780_set_char(7,g); HD44780_set_char(7,g);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -621,17 +686,18 @@ void HD44780_set_char(int n, char *dat)
if (n < 0 || n > 7) return; if (n < 0 || n > 7) return;
if (!dat) return; if (!dat) return;
HD44780_senddata(LCDEN|SECONDLCDEN,0, 64 | n*8); HD44780_senddata(0, RS_INSTR, SETCHAR | n*8);
for(row=0; row<lcd.cellhgt; row++) { for(row=0; row < lcd.cellhgt; row++)
{
letter = 0; letter = 0;
for(col=0; col<lcd.cellwid; col++) { for(col=0; col < lcd.cellwid; col++)
{
letter <<= 1; letter <<= 1;
letter |= (dat[(row * lcd.cellwid) + col] > 0); letter |= (dat[(row * lcd.cellwid) + col] > 0);
} }
HD44780_senddata(LCDEN|SECONDLCDEN,RS, letter); HD44780_senddata(0, RS_DATA, letter);
} }
} }
@@ -693,48 +759,72 @@ void HD44780_draw_frame(char *dat)
HD44780_position(0,y); HD44780_position(0,y);
//printf("\n%d :",y); //printf("\n%d :",y);
for (x=0 ; x<lcd.wid ; x++) { for (x=0 ; x<lcd.wid ; x++) {
if ((lcd.hgt==1)&&(x==8)) HD44780_position(x,y);//for 16x1 HD44780_senddata(spanList[y],RS_DATA,dat[(y*lcd.wid)+x]);
#ifdef SPLIT_SCREENS }
if ((lcd.hgt==2)&&(x==8)) HD44780_position(x,y);// two 16x1's }
if (y<(lcd.hgt/2))
HD44780_senddata(LCDEN,RS,dat[(y*lcd.wid)+x]); }
// Parse the span list
// spanListArray - array to store vertical spans
// spLsize - size of spanListArray
// dispOffsets - array to store display offsets
// dOffsize - size of dispOffsets
// dispSizeArray - array of display vertical sizes (= spanlist)
// spanlist - null terminated input span list in comma delimited
// format. All span elements [1-9] e.g. "1,4,2"
// returns number of span elements, -1 on parse error
int
parse_span_list(int *spanListArray[], int *spLsize,
int *dispOffsets[], int *dOffsize,
int *dispSizeArray[], char *spanlist)
{
int j = 0, retVal = 0;
*spLsize = 0;
*dOffsize = 0;
while (j < strlen(spanlist))
{
if (spanlist[j] >= '1' && spanlist[j] <= '9')
{
int spansize = spanlist[j] - '0';
// add spansize lines to the span list, note the offset to
// the previous display and the size of the display
if ((*spanListArray = (int *) realloc(*spanListArray,
sizeof(int) * (*spLsize + spansize)))
&& (*dispOffsets = (int *) realloc(*dispOffsets,
sizeof(int) * (*dOffsize + 1)))
&& (*dispSizeArray = (int *) realloc(*dispSizeArray,
sizeof(int) * (*dOffsize + 1))))
{
int k;
for (k = 0; k < spansize; ++k)
(*spanListArray)[*spLsize + k] = *dOffsize + 1;
(*dispOffsets)[*dOffsize] = *spLsize;
(*dispSizeArray)[*dOffsize] = spansize;
*spLsize += spansize;
++(*dOffsize);
retVal = *dOffsize;
// find the next number (\0 is also outside this range)
for ( ++j; spanlist[j] < '1' || spanlist[j] > '9'; ++j)
;
}
else else
HD44780_senddata(SECONDLCDEN,RS,dat[(y*lcd.wid)+x]);
//printf("%c",dat[(y*lcd.wid)+x]);
#else
HD44780_senddata(LCDEN,RS,dat[(y*lcd.wid)+x]);
#endif
}
}
}
#ifdef USE_SHIFT_REG
char HD44780_getkey()
{ {
// TODO: a keypad scan that does not use shift register fprintf(stderr, "Error reallocing for span list\n");
// define a key table retVal -1;
char keytr[]="ABCDEFGH"; }
int n; }
rawshift(0);LCD_Pause(1); //send all line on shift register low else
if ((port_in(lp+1)&32)==0) //test if line back is low - if not return(0)
{ //else
//start walking a single zero across the eight lines
for(n=7;n>=0;n--)
{ {
rawshift(255 - (1<<n));LCD_Pause(1); fprintf(stderr, "Error reading spansize\n");
retVal = -1;
if ((port_in(lp+1)&32)==0) // check if line back is low if yes debounce
{
if (lastkey==keytr[n])
return(0);
// printf("key is %c %d\n",keytr[n],n);
lastkey=keytr[n];
return(keytr[n]); //return correct key code.
} }
} }
} //else fall out and return(0) [too transient a keypress] return retVal;
lastkey=0;
return(0);
} }
#endif
+12 -23
View File
@@ -1,23 +1,15 @@
/* Driver module for Hitachi HD44780 based Optrex DMC-20481 LCD display /*
* The module is operated in it's 4 bit-mode to be connected to a single * Base driver module for Hitachi HD44780 based LCD displays. This is
* 8 bit-port * a modular driver that allows support for alternative HD44780
* designs to be added in a flexible and maintainable manner.
* *
* Copyright (c) 1998 Richard Rognlie GNU Public License * This file is released under the GNU General Public License. Refer to the
* <rrognlie@gamerz.net> * COPYING file distributed with this package.
* *
* Large quantities of this code lifted (nearly verbatim) from * Copyright (c) 1999, 1995 Benjamin Tse <blt@Comports.com>
* the lcd4.c module of lcdtext. Copyright (C) 1997 Matthias Prinke * 1999 Andrew McMeikan <andrewm@engineer.com>
* <m.prinke@trashcan.mcnet.de> and covered by GNU's GPL. * 1998 Richard Rognlie <rrognlie@gamerz.net>
* In particular, this program is free software and comes WITHOUT * 1997 Matthias Prinke <m.prinke@trashcan.mcnet.de>
* ANY WARRANTY.
*
* Matthias stole (er, adapted) the code from the package lcdtime by
* Benjamin Tse (blt@mundil.cs.mu.oz.au), August/October 1995
* which uses the LCD-controller's 8 bit-mode.
* References: port.h by <damianf@wpi.edu>
* Data Sheet LTN211, Philips
* Various FAQs and TXTs about Hitachi's LCD Controller HD44780 -
* www.paranoia.com/~filipg is a good starting point ???
*/ */
#ifndef HD44780_H #ifndef HD44780_H
@@ -25,10 +17,8 @@
#include "port.h" #include "port.h"
extern lcd_logical_driver *hd44780;
int HD44780_init(struct lcd_logical_driver *driver, char *args); int HD44780_init(struct lcd_logical_driver *driver, char *args);
/* The following methods can all be hidden. They are used through function ptrs
void HD44780_close(); void HD44780_close();
void HD44780_flush(); void HD44780_flush();
void HD44780_flush_box(int lft, int top, int rgt, int bot); void HD44780_flush_box(int lft, int top, int rgt, int bot);
@@ -43,7 +33,6 @@ void HD44780_num(int x, int num);
void HD44780_set_char(int n, char *dat); void HD44780_set_char(int n, char *dat);
void HD44780_icon(int which, char dest); void HD44780_icon(int which, char dest);
void HD44780_draw_frame(char *dat); void HD44780_draw_frame(char *dat);
*/
#endif #endif