LCDInfo.com

http://www.lcdinfo.com
It is currently Thu Nov 21, 2024 22:11

All times are UTC + 2 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Nov 03, 2004 5:51 
Offline

Joined: Wed Nov 03, 2004 5:24
Posts: 1
Hello everybody,

I bought a 128x128 LCD manufatured by Xiamen (PN above) and all that I got was the LCD and a single-page "datasheet" describing interface pins and a drawing.

I've tried several ways (via LPT port, PIC uC, using LCDPower, LCDInfo, CBuilder, VB...) to drive the LCD. I could only initialize (I can barely see the display clearing). I'd like help to show something controlled (a text, a pixel...), but all others routines aren't working!!!

I'm using the PowerLCD wiring, the LCD board has a 32kb SRAM memory and I selected 8x8 font. I'm using this posted code to drive the LCD:

Code:

#define G_BASE 0x0300   
#define T_BASE 0x0000   
#define BYTES_PER_ROW 16

#define BASE 0x378     

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(unsigned short Data)
{

   WaitDisplayReady();
    DlPortWritePortUshort(BASE, Data);
    DlPortWritePortUshort(BASE + 2, 0);   // 0111 C/D low
    DlPortWritePortUshort(BASE + 2, 2);   // 0011 WR low
    DlPortWritePortUshort(BASE + 2, 3);   // 0010 CE low
    DlPortWritePortUshort(BASE + 2, 2);   // 0011 CE high
    DlPortWritePortUshort(BASE + 2, 0);   // 0111 WR high

   
}

void WriteCtrl(unsigned short 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
}

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<2048;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<2048;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/8);
  WriteData(addr & 0xFF);
  WriteData(addr >> 8);
  WriteCtrl(0x24);
  WriteCtrl(0xf8 | (7-(x % 8)));
}

void ClearLCDPixel(int x, int y)
{
  int addr;

  addr = G_BASE + (y*BYTES_PER_ROW) + (x/8);
  WriteData(addr & 0xFF);
  WriteData(addr >> 8);
  WriteCtrl(0x24);
  WriteCtrl(0xf0 | (7-(x % 8)));
}


void main(void)
{
  InitLCD();
  ClearLCDText();
  ClearLCDGraph();
  SetLCDXY(2,7);
  PrintLCDText("Text");

}


Thanks a lot!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 2 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group