This code worked fine for me with 240x128 display using the powerlcd wiring:
Code:
#define G_BASE 0x0300 // grafiikkamuistin base address
#define T_BASE 0x0000 // tekstimuistin base address
#define BYTES_PER_ROW 40 // merkkiä rivillä
#define BASE 0x378 // lpt portin osoite
void WaitDisplayReady(void)
// reads the display status byte and checks
// that the display is ready before writing
// doesn't have any check in case the status byte
// can't be read so this situation may cause a lockup
{
int Tmp;
Tmp = DlPortReadPortUshort(BASE + 0x402);
Tmp = Tmp & 0x1F;
Tmp = Tmp | 0x20;
DlPortWritePortUshort(BASE + 0x402, Tmp);
do{
DlPortWritePortUshort(BASE + 2, 0x20 + 4 + 2); //In, CD=1, CS=0, Wr=1
DlPortWritePortUshort(BASE + 2, 0x20 + 4 + 2 + 8); //In, CD=1, CS=0, Wr=1, Rd=0
Tmp = DlPortReadPortUshort(BASE);
DlPortWritePortUshort(BASE + 2, 0x20 + 4 + 2); //In, CD=1, CS=0, Wr=1
}while ((Tmp & 3) != 3 );
DlPortWritePortUshort(BASE + 2, 0);
}
void WriteData(USHORT Data)
{
/* pollin
WaitDisplayReady();
DlPortWritePortUshort(BASE + 2, 0); // 0111 C/D low
DlPortWritePortUshort(BASE + 2, 2); // 0011 WR low
DlPortWritePortUshort(BASE, Data);
DlPortWritePortUshort(BASE + 2, 3); // 0010 CE low
DlPortWritePortUshort(BASE + 2, 2); // 0011 CE high
DlPortWritePortUshort(BASE + 2, 0); // 0111 WR high
*/
/* powerlcd */
DlPortWritePortUshort(BASE + 2, 0x0c); // 0111 C/D low
DlPortWritePortUshort(BASE + 2, 0x08); // 0011 WR low
DlPortWritePortUshort(BASE, Data);
DlPortWritePortUshort(BASE + 2, 0x09); // 0010 CE low
DlPortWritePortUshort(BASE + 2, 0x08); // 0011 CE high
DlPortWritePortUshort(BASE + 2, 0x0c); // 0111 WR high
}
void WriteCtrl(USHORT Command)
{
/*
WaitDisplayReady();
DlPortWritePortUshort(BASE, Command);
DlPortWritePortUshort(BASE + 2, 4); // 1111 C/D high
DlPortWritePortUshort(BASE + 2, 4+2); // 1011 WR low
DlPortWritePortUshort(BASE + 2, 4+3); // 1010 CE low
DlPortWritePortUshort(BASE + 2, 4+2); // 1011 CE high
DlPortWritePortUshort(BASE + 2, 0); // 0111 C/D low
*/
/* powerlcd */
DlPortWritePortUshort(BASE + 2, 0x04); // 1111 C/D high
DlPortWritePortUshort(BASE + 2, 0x00); // 1011 WR low
DlPortWritePortUshort(BASE, Command);
DlPortWritePortUshort(BASE + 2, 0x01); // 1010 CE low
DlPortWritePortUshort(BASE + 2, 0x00); // 1011 CE high
DlPortWritePortUshort(BASE + 2, 0x0c); // 0111 C/D low
}
void InitLCD(void)
{
// Display init
WriteData(T_BASE & 0xFF); // Data1: LowAddress
WriteData(T_BASE >> 8); // Data2: HighAddress
WriteCtrl(0x40); // Command: 0x40 -> 01000000
WriteData(BYTES_PER_ROW); // Data1: Colums
WriteData(0); // Data2: 0
WriteCtrl(0x41); // Command: 0x41 -> 01000001
WriteData(G_BASE & 0xFF); // Data1: LowAddress
WriteData(G_BASE >> 8); // Data2: HighAddress
WriteCtrl(0x42); // Command: 0x42 -> 01000010
WriteData(BYTES_PER_ROW); // Data1: Colums
WriteData(0); // Data2: 0
WriteCtrl(0x43); // Command: 0x43 -> 01000011
// Internal CGROM Mode, OR Mode
WriteCtrl(0x80); // OR Mode // 80->10000000
WriteCtrl(0xa7); // cursor is 8 lines high
WriteData(0x00);
WriteData(0x00);
WriteCtrl(0x21); // put cursor at (x,y)
// DisplayMode
WriteCtrl(0x9D);
}
void SetLCDXY(int x, int y)
{
int addr;
addr = T_BASE + (y * BYTES_PER_ROW) + x;
WriteData(addr & 0xFF);
WriteData(addr >> 8);
WriteCtrl(0x24);
}
void SetLCDCursor(int x, int y)
{
WriteData(x);
WriteData(y);
WriteCtrl(0x21);
}
void ClearLCDText(void)
{
int i;
WriteData(T_BASE & 0xFF);
WriteData(T_BASE >> 8);
WriteCtrl(0x24); // address pointer to T_BASE
for (i=0;i<640;i++) {
WriteData(0); WriteCtrl(0xc0); // write data and inc ptr
}
}
void ClearLCDGraph(void)
{
int i;
WriteData(G_BASE & 0xFF);
WriteData(G_BASE >> 8);
WriteCtrl(0x24); // address pointer to G_BASE
for (i=0;i<5120;i++){
WriteData(0); WriteCtrl(0xc0); // write data and inc ptr
}
}
void PrintLCDText(char *string)
{
unsigned int i;
char c;
for (i=0;i<strlen(string);i++){
c = string[i] - 0x20; // conversion from ASCII to LCD characters
if (c<0) c=0;
WriteData(c);
WriteCtrl(0xc0);
}
}
void SetLCDPixel(int x, int y)
{
int addr;
addr = G_BASE + (y*BYTES_PER_ROW) + (x/6);
WriteData(addr & 0xFF);
WriteData(addr >> 8);
WriteCtrl(0x24);
WriteCtrl(0xf8 | (5-(x % 6)));
}
void ClearLCDPixel(int x, int y)
{
int addr;
addr = G_BASE + (y*BYTES_PER_ROW) + (x/6);
WriteData(addr & 0xFF);
WriteData(addr >> 8);
WriteCtrl(0x24);
WriteCtrl(0xf0 | (5-(x % 6)));
}
void main(void)
{
InitLCD();
ClearLCDText();
ClearLCDGraph();
SetLCDXY(2,7);
PrintLCDText("Text juttu lisaa");
for(int i=0;i<240;i++)
for(int j=10;j<50;j++)
SetLCDPixel(i,j);
for(int k=110;k<150;k++)
for(int l=20;l<30;l++)
ClearLCDPixel(k,l);
for(int m=10;m<20;m++)
for(int n=20;n<30;n++)
ClearLCDPixel(m,n);
}