File: [local] / funnyos / dev / lcd / 44780_dev.c (download)
Revision 1.1, Mon Jan 7 20:24:48 2008 UTC (16 years, 5 months ago) by nbrk
Branch: MAIN
CVS Tags: HEAD
initial bits of driver for Hitachi HD44780-compatible LCD controllers.
machine dependent part sits in p64lcd.c;
it doesn't initialize LCD properly - missed some timings, i think.
unfortunately, i have fryed my brand-new 16x4 LCD and can't continue work right now..
very sadly, R.I.P :(
|
/*
* $Id: 44780_dev.c,v 1.1 2008/01/07 20:24:48 nbrk Exp $
*/
#include <sys/types.h>
#include <sys/device.h>
#include <sys/gpio.h>
#include <dev/lcd/44780var.h>
#include <dev/lcd/44780reg.h>
/*
* Driver for Hitachi 44780-based LCD.
*/
int h44780_attach(struct device *, uint32_t, uint8_t);
void h44780_write(struct h44780_dd *ddp, uint16_t data);
void h44780_strobe(struct h44780_dd *ddp);
void h44780_init(struct h44780_dd *ddp);
struct driver h44780_dr = {
sizeof(struct h44780_dd),
h44780_attach,
NULL,
NULL
};
int
h44780_attach(struct device *self, uint32_t loc, uint8_t flags)
{
struct h44780_dd *ddp = self->dv_devdata;
ddp->h_bop = self->dv_parent->dv_aux;
printf("Hitachi 44780 LCD controller\n");
h44780_init(ddp);
return(0);
}
void
h44780_write(struct h44780_dd *ddp, uint16_t data)
{
printf("h44780_write: write 0x%x\n", data);
ddp->h_bop->write(ddp->h_bop->selfdd, data);
}
void
h44780_strobe(struct h44780_dd *ddp)
{
ddp->h_bop->strobe(ddp->h_bop->selfdd);
}
void
h44780_init(struct h44780_dd *ddp)
{
h44780_write(ddp, H44780_CMD_IFLEN | H44780_DL | H44780_N | H44780_F);
// h44780_strobe(ddp);
H44780_DELAY;
h44780_write(ddp, H44780_CMD_IFLEN | H44780_DL | H44780_N | H44780_F);
// h44780_strobe(ddp);
H44780_DELAY;
h44780_write(ddp, H44780_CMD_IFLEN | H44780_DL | H44780_N | H44780_F);
// h44780_strobe(ddp);
H44780_DELAY;
h44780_write(ddp, H44780_CMD_ENABLE | H44780_B | H44780_C | H44780_D);
// h44780_strobe(ddp);
H44780_DELAY;
h44780_write(ddp, H44780_CMD_CLS);
// h44780_strobe(ddp);
H44780_DELAY;
h44780_write(ddp, H44780_CMD_SETDIR | H44780_ID | H44780_S);
// h44780_strobe(ddp);
h44780_write(ddp, 0);
// h44780_strobe(ddp);
H44780_DELAY;
h44780_write(ddp, 0x38);
// h44780_strobe(ddp);
H44780_DELAY;
h44780_write(ddp, 0);
// h44780_strobe(ddp);
H44780_DELAY;
h44780_write(ddp, 0x0f);
// h44780_strobe(ddp);
}