ELECTRONICS AND MATHEMATICS

COME ON MEET A PERSON WHO DIFFERS


A simple Test Pattern for the LCD128x64


It was August 23 2008 as I took the Mao Tse Tung example of the QLS company to program my first test pattern onto the LCD display of the QL200 board.
It was clear for me that every bit of the given data table represented a pixel on the display.

And here the code in C :

//THE experiment is to familiarity the use of 12864LCD   
//the configration of hardware
//Please open RA4 pull UP, will S10'S NO.4 in the "on", jump J14 all connect.  
//all the switch and jumpers must disconnection.     

 #include<pic.h>
 __CONFIG(0x1832);       
//__CONFIG _DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC
 
#define  rs  RA5                      //COMMNAD/DATA SELECT                    
#define  rw  RA4                      //READ/WRITE SELECT                      
#define  e   RA3                      //ENABLE SIGNAL                          
#define  psb RA2                      //PARALLEL/SERIAL SELECT£¨H/L£©          
#define  rst RA0                      //RESET SIGNAL                           
#define  nop()  asm("nop")           

const unsigned char TAB1[ ]={         //define the data table.
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,

  0X10,0XFF,0X00,0XFF,0X00,0XFF,0X0F,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
  0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,
};
 unsigned int lcd_x;               //X address    
 unsigned int lcd_y;               //Y address
  bit busy;                        //busy flag
 
void init();                       //system init.
void lcd_init();                   //LCD init
void clear_p();                    //clear screen
void han_wr2a();                   //
void wr_zb();                      //
void qushu();                      //search table sub.
void send_d(unsigned char x);      //write data sub.
void send_i(unsigned char x);      //write cmd sub.
void chk_busy();                   //check busy sub.
void delay();

//-------------------------------------------
void main()
{
       init();                    //system init.
       lcd_init();                //LCD init.
       clear_p();                 //clear screen.
       han_wr2a();                //write data to LCD
       while(1);                  //stop
}

//-------------------------------------------
void init()
{
  TRISA=0X00;                     //A port as output
  TRISD=0X00;                     //d port as output
  ADCON1=0X06;                    //A port as ordinary i/o
}

//-------------------------------------------
void lcd_init()
{
  rst=0;                         //reset LCD
  delay();                       
  rst=1;                         //LCD normal work.
  nop();       
  psb=1;                         //8 bit as parrallel.
  send_i(0x30);                  //basic operation instruction
  send_i(0x01);                  //off display 
  send_i(0x06);                  //set the cursor's moving direction.
  send_i(0x0c);                  //on display,off cursor,off blink
}

//-------------------------------------------
void han_wr2a()
{
 qushu();                        //search table.
}

//-------------------------------------------
void wr_zb()
{
  send_i(0x34);                  //extend operation instruction.
  send_i(lcd_y);                 //set Y address.
  send_i(lcd_x);                 //set X address.
  send_i(0x30);                  //basic operation instruction.
}

//-------------------------------------------
void clear_p()
{
  send_i(0x1);                   //clear display.
  send_i(0x34);                  //extend operation instruction.
  send_i(0x30);                  //basic operation instruction.
}

//------------------------------------------
void qushu()
{
  int i,j,k,temp,temp1;          //define temp variable.
  temp=0;                        //offset address.
  lcd_x=0x80;                    //X address 80H for upper screen.
  for(i=2;i>0;i--)               //total 2 screen.
     { 
       lcd_y=0x80;               //Y address 80H
       for(j=0x20;j>0;j--)       //32 lines every half screen.
          {
             wr_zb();            //pre-write.
             for(k=0x10;k>0;k--) //
                { 
                   temp1=TAB1[temp]; //
                   send_d(temp1);    //send to lcd display
                   temp++;       //offset added by 1
                }
             lcd_y++;            //next line data.
             send_i(0x36);       //extend instruction. graphic open.
             send_i(0x30);       //basic instruction operation.
          }
//      send_i(0x36);
//      send_i(0x30);
        lcd_x=0X88;              //x address for the 2nd screen.
     }
}

//-------------------------------------------
void send_d(unsigned char x)
{
   chk_busy();                   //check lcd if busy.
   rs=1;                         //data not commnad.
   rw=0;                         //write not read.
   PORTD=x;                      //data to bus.
   e=1;                          //enable.
   nop();
   nop();
   nop();                      
   e=0;                      
}

//--------------------------------------------
void send_i(unsigned char x)

Late in the evening of this Saturday I discovered on how bitmaps could be
inserted into the C code of the QLS company. I made a black and white
picture in paint with the attributes : 128 x 64 and then I wrote a text on that
picture and then I had to mirror it horizontally. I took the winHex editor and
I copied the picture into C code the result was the code that I needed for
my display.


Create a free website at Webs.com