ELECTRONICS AND MATHEMATICS

COME ON MEET A PERSON WHO DIFFERS


Here I have been programming a counter with the 128x64 display in C++

24 August 2008

Today I had enough of waiting for somebody else and I was programming a simple counter in C++ for the 128 x 64 display of the QL200 board.
And here the source code :

//THE experiment is to familiarity the use of 12864LCD
//12864LCD with the lib of chinese     
//program to display company's logo and tel.
//the configration of hardware  
//Tip:Please open RA4 pull UP, will S10'S NO.4 in the "on"   ,Jump J14 all connect,

 #include<pic.h>
 #include<math.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")          //nop func

//ÉîÛÚǬÁúÊ¢µç×Ó
const unsigned char TAB1A[ ]={0xC9,0xEE,0xDB,0xDA,0xC7,0xAC,0xC1,0xFA,0xCA,0xA2,0xB5,0xE7,0xD7,0xD3};
//WWW.PIC16.COM
const unsigned char TAB1D[ ]={'P', 'A', 'V', 'L', 'E', ' ', 'D', 'J', 'U', 'K','A', 'N', 'O', 'V', 'I', 'C'};     
//TEL0755-28187975
const unsigned char TAB1C[ ]={'T', 'E', 'L' ,'+' ,'4', '9' ,'7','1', '4', '6','/', '6' ,'9','4' ,'1',' '};   
//FAX0755-28187976    
//const unsigned char TAB1D[ ]={48, 49, 50, 51, 52, 53, 54, 55,56, 57,58, 59, 60, 61, 62, 63};      
 unsigned int lcd_x;                //X address   
 unsigned int lcd_y;                //Y address   
  bit busy;                         //busy flag 
int i; 

void init();                        //system init.  
void lcd_init();                    //LCD init      
void clear_p();                     //clear screen  
void han_wr2a(int i);                    //company name.
void han_wr2b();                    //company website.
void han_wr2c();                    //company tel.
void han_wr2d();                    //company fax.
void wr_zb();                       //display setting mode.
void flash();                       //lcd blink func.
void qushu(int counts,const unsigned char *ps);       //search table.
void send_d(unsigned char x);       //send data
void send_i(unsigned char x);       //send command.
void chk_busy();                    //check busy sub.
void delay();                       //delay func, decide the speed of display.
void delay1();                      //delay func, decide the speed of blink.

//-------------------------------------------
//main
void main()
{ i = 0;

       init();                      //system init.
       lcd_init();                  //   
       clear_p();                   //
   while(1)
     {
     
     
       i++;   
       han_wr2a(i);                  //company name.       
       han_wr2b();                  //company website.    
       han_wr2c();                  //company tel.    
       han_wr2d();                  //company fax.    
       delay();                     //
       //flash();                     //
      // clear_p();                   //
     }
}

//-------------------------------------------
//I/O¿Ú setting func.
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
}

//-------------------------------------------
//company name.
void han_wr2a(int i)
{
  int ch;
 
  send_i(0x80);                     //set display position

  ch = (i/1000000000000000)%10;
  send_d(48+ch);

  ch = (i/100000000000000)%10;
  send_d(48+ch);

 
  ch = (i/10000000000000)%10;
  send_d(48+ch);

  ch = (i/1000000000000)%10;
  send_d(48+ch);

  ch = (i/100000000000)%10;
  send_d(48+ch);

  ch = (i/10000000000)%10;
  send_d(48+ch);

  ch = (i/1000000000)%10;
  send_d(48+ch);

  ch = (i/100000000)%10;
  send_d(48+ch);

  ch = (i/10000000)%10;
  send_d(48+ch);

  ch = (i/1000000)%10;
  send_d(48+ch);

  ch = (i/100000)%10;
  send_d(48+ch);

  ch = (i/10000)%10;
  send_d(48+ch);


  ch = (i/1000)%10;
  send_d(48+ch);


  ch = (i/100)%10;
  send_d(48+ch);


  ch = (i/10)%10;
  send_d(48+ch);

  ch = i % 10; // % = Modulo
  send_d(48+ch);





 
  //qushu(0xe,TAB1A);                 //get data from table
 
  //send_d(49);
}

//-------------------------------------------
//company website.
void han_wr2b()
{
  send_i(0x90);                    //set display position 
  qushu(0xe,TAB1A);                 //get data from table

 // qushu(0x10,TAB1B);               //get data from table  

 
//-------------------------------------------
//company tel.
void han_wr2c()
{
  send_i(0x88);                   //set display position 
  qushu(0X10,TAB1C);              //get data from table  
}

//-------------------------------------------
//company fax.
void han_wr2d()
{
  send_i(0x98);                  //set display position 
  qushu(0X10,TAB1D);             //get data from table  
}

//display setting.
void wr_zb()
{
  send_i(lcd_y);
  send_i(lcd_x);
}

//-------------------------------------------
//blink
void flash()
{
  send_i(0x08);                  //off display.
  delay1();                      //delay
  send_i(0x0c);                  //on display
  delay1();
  delay1();                      //delay
  send_i(0x08);                  //off
  delay1();
  send_i(0x0c);                  //on
  delay1();
  delay1();
  send_i(0x08);                  //off
  delay1();
  send_i(0x0c);                  //on
  delay1();
  delay1();
}

//-------------------------------------------
//clear screen
void clear_p()
{
  send_i(0x1);                   //clear all
  send_i(0x34);                  //extend.
  send_i(0x30);                  //basic
}

//------------------------------------------
//search.
void qushu(int counts,const unsigned char *ps)
{
  int i;                         //define loop count.
  for(i=counts;i>0;i--)          //
     { 
        send_d(*ps);             //
        delay();                 //
        ps++;                    //get next.
     }
}

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

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

//-------------------------------------------
//check lcd busy.
void chk_busy()

   busy=1;                      //set busy signal                  
   TRISD=0XFF;                  //change the bus to input.         
   rs=0;                        //command not data.                
   rw=1;                        //read not write.                  
   while(busy)                 
      {
         nop();
         nop();
         nop();
         e=1;                   //enable.
         nop();
         nop();
         nop();
         if(!RD7) busy=0;       //
         nop();
         nop();
         nop();
         e=0;                   //DISABLE.
      }
   e=0;                         //DISABLE.
   TRISD=0X00;                  //bus as output.
 }

//-------------------------------------------
//delay
void delay()
{
    int i;
    for(i=0;i<10;i++)
       {;}
}

//-------------------------------------------
//delay1
void delay1()
{
    int i;
    for(i=0;i<10;i++)
      {
        delay();               //call delay.
      }
}

A programmable counter (16 digits)

Here I extended the former version of a simple counter to a programmable 16 digit counter. You can reallize with that counter what ever you want. You can bake bread for example and the oven is going to turn off after a certain programmed period.

and here the code :

//THE experiment is to familiarity the use of 12864LCD
//12864LCD with the lib of chinese     
//program to display company's logo and tel.
//the configration of hardware  
//Tip:Please open RA4 pull UP, will S10'S NO.4 in the "on"   ,Jump J14 all connect,

 #include<pic.h>
 #include<math.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")          //nop func

//深圳乾龙盛电子
const unsigned char TAB1A[ ]={0xC9,0xEE,0xDB,0xDA,0xC7,0xAC,0xC1,0xFA,0xCA,0xA2,0xB5,0xE7,0xD7,0xD3};
//WWW.PIC16.COM
const unsigned char TAB1D[ ]={'P', 'A', 'V', 'L', 'E', ' ', 'D', 'J', 'U', 'K','A', 'N', 'O', 'V', 'I', 'C'};     
//TEL0755-28187975
const unsigned char TAB1C[ ]={'T', 'E', 'L' ,'+' ,'4', '9' ,'7','1', '4', '6','/', '6' ,'9','4' ,'1',' '};   
//FAX0755-28187976    
//const unsigned char TAB1D[ ]={48, 49, 50, 51, 52, 53, 54, 55,56, 57,58, 59, 60, 61, 62, 63};      
 unsigned int lcd_x;                //X address   
 unsigned int lcd_y;                //Y address   
  bit busy;                         //busy flag 


long int i; //the counted count
long int u;

long int v; //the programmed count
long int w;


int J1,J2,J3,J4,J5,J6,J7,J8,J9;
int J10,J11,J12,J13,J14,J15,J16;

int  Z;
int  result;
int chx;

void init();                        //system init.  
void lcd_init();                    //LCD init      
void clear_p();                     //clear screen  
void han_wr2a(long int i);                    //company name.
void han_wr2b();                    //company website.
void han_wr2c();                    //company tel.
void han_wr2d();                    //company fax.
void wr_zb();                       //display setting mode.
void flash();                       //lcd blink func.
void qushu(int counts,const unsigned char *ps);       //search table.
void send_d(unsigned char x);       //send data
void send_i(unsigned char x);       //send command.
void chk_busy();                    //check busy sub.
void delay();                       //delay func, decide the speed of display.
void delay1();                      //delay func, decide the speed of blink.
void  scan();                       //scan the push buttons on port b

//-------------------------------------------
//main
void main()
{ i = 0;
  u = 0;
  Z=1;
       init();                      //system init.
       lcd_init();                  //   
       clear_p();                   //
   while(1)
     { 
       scan();  
       han_wr2a(i);                  //company name.       
       han_wr2b();                  //company website.    
       han_wr2c();                  //company tel.    
       han_wr2d();                  //company fax. 
       if(u>0);i++;
       if(i > v) {i = 0;                           u++;  }
       if(u > w) u = 0;
       delay();                     //
       //flash();                     //
      // clear_p();                   //
     }
}

//-------------------------------------------
//I/O口 setting func.
void init()
{
  TRISA=0X00;                       //A port as output        
  TRISD=0X00;                       //d port as output        
  ADCON1=0X06;                      //A port as ordinary i/o
  TRISB=0X0F;                       //B PORT low 5 bits INPUT    
}

//-------------------------------------------
//-------------------------------------------
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
}

//-------------------------------------------
//company name.
void han_wr2a(long int i)
{
  int ch;
 
  send_i(0x80);                     //set display position

 

  ch = (u/1000000)%10;
  send_d(48+ch);

  ch = (u/ 100000)%10;
  send_d(48+ch);

  ch = (u/10000)%10;
  send_d(48+ch);

  ch = (u/1000)%10;
  send_d(48+ch);

  ch = (u/100)%10;
  send_d(48+ch);

  ch = (u/10)%10;
  send_d(48+ch);

  ch =  u%10;
  send_d(48+ch);


  ch = (i/100000000)%10;
  send_d(48+ch);

  ch = (i/10000000)%10;
  send_d(48+ch);

  ch = (i/1000000)%10;
  send_d(48+ch);

  ch = (i/100000)%10;
  send_d(48+ch);

  ch = (i/10000)%10;
  send_d(48+ch);


  ch = (i/1000)%10;
  send_d(48+ch);


  ch = (i/100)%10;
  send_d(48+ch);


  ch = (i/10)%10;
  send_d(48+ch);

  ch = i % 10; // % = Modulo
  send_d(48+ch);

 

  //send_d(49);
}

//-------------------------------------------
//company website.
void han_wr2b()
{
 
  send_i(0x90);                    //set display position
 
  //qushu(0xe,TAB1A);                 //get data from table

   if (result==5){chx++;
                  for(i= 0;i<1000;i++) delay();
                  if (chx>9) chx = 0;
                  }
   if (result==6){chx--;
                  for(i= 0;i<1000;i++) delay();
                  if (chx<0) chx = 9;
                  }
 // send_d(48+chx);

   if (result==4){Z++;
                  for(i= 0;i<1000;i++) delay();
                  if (Z >16)Z = 1;
                  chx=9;
                  }

   if(result==7){ v = J1+J2*10+J3*100+J4*1000+J5*10000+J6*100000+J7*1000000+J8*10000000 + J9*100000000;                          
                  w = J10+J11*10+J12*100+J13*1000+J14*10000+J15*100000+J16*1000000;// v and w the programmed number
                  }
   //send_d(48+Z); 

   if (Z==16) J16 = chx;
   if (Z==15) J15 = chx;
   if (Z==14) J14 = chx;
   if (Z==13) J13 = chx;
   if (Z==12) J12 = chx;
   if (Z==11) J11 = chx;
   if (Z==10) J10 = chx;
   if (Z==9) J9 = chx;
   if (Z==8) J8 = chx;
   if (Z==7) J7 = chx;
   if (Z==6) J6 = chx;
   if (Z==5) J5 = chx;
   if (Z==4) J4 = chx;  
   if (Z==3) J3 = chx;
   if (Z==2) J2 = chx;
   if (Z==1) J1 = chx;
  

   send_d(48+J16);
   send_d(48+J15);
   send_d(48+J14);
   send_d(48+J13);
   send_d(48+J12);
   send_d(48+J11);
   send_d(48+J10);
   send_d(48+J9);
   send_d(48+J8);
   send_d(48+J7);
   send_d(48+J6);
   send_d(48+J5);
   send_d(48+J4);
   send_d(48+J3);
   send_d(48+J2);
   send_d(48+J1);
 
 // qushu(0x10,TAB1B);               //get data from table  

 
//-------------------------------------------
//company tel.
void han_wr2c()
{
  send_i(0x88);                   //set display position 
  qushu(0X10,TAB1C);              //get data from table  
}

//-------------------------------------------
//company fax.
void han_wr2d()
{
  send_i(0x98);                  //set display position 
  qushu(0X10,TAB1D);             //get data from table  
}

//display setting.
void wr_zb()
{
  send_i(lcd_y);
  send_i(lcd_x);
}

//-------------------------------------------
//blink
void flash()
{
  send_i(0x08);                  //off display.
  delay1();                      //delay
  send_i(0x0c);                  //on display
  delay1();
  delay1();                      //delay
  send_i(0x08);                  //off
  delay1();
  send_i(0x0c);                  //on
  delay1();
  delay1();
  send_i(0x08);                  //off
  delay1();
  send_i(0x0c);                  //on
  delay1();
  delay1();
}

//-------------------------------------------
//clear screen
void clear_p()
{
  send_i(0x1);                   //clear all
  send_i(0x34);                  //extend.
  send_i(0x30);                  //basic
}

//------------------------------------------
//search.
void qushu(int counts,const unsigned char *ps)
{
  int i;                         //define loop count.
  for(i=counts;i>0;i--)          //
     { 
        send_d(*ps);             //
        delay();                 //
        ps++;                    //get next.
     }
}

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

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

//-------------------------------------------
//check lcd busy.
void chk_busy()

   busy=1;                      //set busy signal                  
   TRISD=0XFF;                  //change the bus to input.         
   rs=0;                        //command not data.                
   rw=1;                        //read not write.                  
   while(busy)                 
      {
         nop();
         nop();
         nop();
         e=1;                   //enable.
         nop();
         nop();
         nop();
         if(!RD7) busy=0;       //
         nop();
         nop();
         nop();
         e=0;                   //DISABLE.
      }
   e=0;                         //DISABLE.
   TRISD=0X00;                  //bus as output.
 }

//-------------------------------------------
//delay
void delay()
{
    int i;
    for(i=0;i<10;i++)
       {;}
}

//-------------------------------------------
//delay1
void delay1()
{
    int i;
    for(i=0;i<10;i++)
      {
        delay();               //call delay.
      }
}

void  scan()
 {
   result=0x8;             //initialize key scan result  

   if(RB0==0)              //judge if B0 press    
      result=0x4;                                 
   if(RB1==0)              //judge if B1 press    
      result=0x5;                                 
   if(RB2==0)              //judge if B2 press    
      result=0x6;                                 
   if(RB3==0)              //judge if B3 press    
      result=0x7;                                 
  }           

A programmable second counter with the LCD display

Friday, September 5, 2008 Today I implemented a delay routine which was delaying approximately 0,001 seconds on my display. I was disappointed as I reallized that I couldn't use the real time clock of the board because I have been using the pin RB0 and the real time clock needed that pin.

and here the code for the time counter :

//THE experiment is to familiarity the use of 12864LCD
//12864LCD with the lib of chinese     
//program to display company's logo and tel.
//the configration of hardware  
//Tip:Please open RA4 pull UP, will S10'S NO.4 in the "on"   ,Jump J14 all connect,

 #include<pic.h>
 #include<math.h>
 #include"delay.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")          //nop func


//深圳乾龙盛电子
const unsigned char TAB1A[ ]={0xC9,0xEE,0xDB,0xDA,0xC7,0xAC,0xC1,0xFA,0xCA,0xA2,0xB5,0xE7,0xD7,0xD3};
//WWW.PIC16.COM
const unsigned char TAB1D[ ]={'P', 'A', 'V', 'L', 'E', ' ', 'D', 'J', 'U', 'K','A', 'N', 'O', 'V', 'I', 'C'};     
//TEL0755-28187975
const unsigned char TAB1C[ ]={'T', 'E', 'L' ,'+' ,'4', '9' ,'7','1', '4', '6','/', '6' ,'9','4' ,'1',' ',' '};   
//FAX0755-28187976    
//const unsigned char TAB1D[ ]={48, 49, 50, 51, 52, 53, 54, 55,56, 57,58, 59, 60, 61, 62, 63};      
 unsigned int lcd_x;                //X address   
 unsigned int lcd_y;                //Y address   
  bit busy;                         //busy flag 


long int i; //the counted count
long int u;

long int v; //the programmed count
long int w;


int J1,J2,J3,J4,J5,J6,J7,J8,J9;
int J10,J11,J12,J13,J14,J15,J16;

int  Z;
int  result;
int chx;

void init();                        //system init.  
void lcd_init();                    //LCD init      
void clear_p();                     //clear screen  
void han_wr2a(long int i);                    //company name.
void han_wr2b();                    //company website.
void han_wr2c();                    //company tel.
void han_wr2d();                    //company fax.
void wr_zb();                       //display setting mode.
void flash();                       //lcd blink func.
void qushu(int counts,const unsigned char *ps);       //search table.
void send_d(unsigned char x);       //send data
void send_i(unsigned char x);       //send command.
void chk_busy();                    //check busy sub.
                   
void DelayMs(unsigned char cnt);
void  scan();                       //scan the push buttons on port b

//-------------------------------------------
//main
void main()
{
  i = 0;
  u = 0;
  Z=1;
       //TMR0 = 0xFF;
       WDTEN;
       TMR0IE = 1;
       init();                      //system init.
       lcd_init();                  //   
       clear_p();                   //
   while(1)
     { //DelayMs(89);  // Delay for 10 ms smaller because LCD needs time
    
       // // RB7 = 1 (HIGH); 
       scan();  
       han_wr2a(i);                  //company name.       
       han_wr2b();                  //company website.    
       han_wr2c();                  //company tel.    
       han_wr2d();                  //company fax. 
      
       if(u>0); i++;

      
       //if (TMR0IF ==0){TMR0=0xFF;} // Interrupt is set
       //TMR0IF = 0;
      
      // RB7 =0;
       if(i > v ) {i = 0;  u++;        
                  }

       if(u > w) u = 0;

      
        
       //DelayMs(5);                 //
       //flash();                   //
      // clear_p();                   //
     }
}

//-------------------------------------------
//I/O口 setting func.
void init()
{
  TRISA=0X00;                       //A port as output        
  TRISD=0X00;                       //d port as output        
  ADCON1=0X06;                      //A port as ordinary i/o
  TRISB=0X0F;                       //B PORT low 5 bits INPUT    
}

//-------------------------------------------
//-------------------------------------------
void lcd_init()
{
  rst=0;                         //reset LCD
  DelayMs(10);                
  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
}

//-------------------------------------------
//company name.
void han_wr2a(long int i)
{
  int ch;
 
  send_i(0x80);                     //set display position

 

  ch = (u/1000000)%10;
  send_d(48+ch);

  ch = (u/ 100000)%10;
  send_d(48+ch);

  ch = (u/10000)%10;
  send_d(48+ch);

  ch = (u/1000)%10;
  send_d(48+ch);

  ch = (u/100)%10;
  send_d(48+ch);

  ch = (u/10)%10;
  send_d(48+ch);

  ch =  u%10;
  send_d(48+ch);


  ch = (i/100000000)%10;
  send_d(48+ch);

  ch = (i/10000000)%10;
  send_d(48+ch);

  ch = (i/1000000)%10;
  send_d(48+ch);

  ch = (i/100000)%10;
  send_d(48+ch);

  ch = (i/10000)%10;
  send_d(48+ch);


  ch = (i/1000)%10;
  send_d(48+ch);


  ch = (i/100)%10;
  send_d(48+ch);


  ch = (i/10)%10;
  send_d(48+ch);

  ch = i % 10; // % = Modulo
  send_d(48+ch);

 

  //send_d(49);
}

//-------------------------------------------
//company website.
void han_wr2b()
{
 
  send_i(0x90);                    //set display position
 
  //qushu(0xe,TAB1A);                 //get data from table

   if (result==5){chx++;
                  DelayMs(500);
                  if (chx>9) chx = 0;
                  }
   if (result==6){chx--;
                  DelayMs(500);
                  if (chx<0) chx = 9;
                  }
 // send_d(48+chx);

   if (result==4){Z++;
                  DelayMs(500);
                  if (Z >16)Z = 1;
                  chx=9;
                  }

   if(result==7){ v = J1+J2*10+J3*100+J4*1000+J5*10000+J6*100000+J7*1000000+J8*10000000 + J9*100000000;                          
                  w = J10+J11*10+J12*100+J13*1000+J14*10000+J15*100000+J16*1000000;// v and w the programmed number
                  }
   //send_d(48+Z); 

   if (Z==16) J16 = chx;
   if (Z==15) J15 = chx;
   if (Z==14) J14 = chx;
   if (Z==13) J13 = chx;
   if (Z==12) J12 = chx;
   if (Z==11) J11 = chx;
   if (Z==10) J10 = chx;
   if (Z==9) J9 = chx;
   if (Z==8) J8 = chx;
   if (Z==7) J7 = chx;
   if (Z==6) J6 = chx;
   if (Z==5) J5 = chx;
   if (Z==4) J4 = chx;  
   if (Z==3) J3 = chx;
   if (Z==2) J2 = chx;
   if (Z==1) J1 = chx;
  

   send_d(48+J16);
   send_d(48+J15);
   send_d(48+J14);
   send_d(48+J13);
   send_d(48+J12);
   send_d(48+J11);
   send_d(48+J10);
   send_d(48+J9);
   send_d(48+J8);
   send_d(48+J7);
   send_d(48+J6);
   send_d(48+J5);
   send_d(48+J4);
   send_d(48+J3);
   send_d(48+J2);
   send_d(48+J1);

   // send_d(48+TMR0%10);
   // send_d(48+(TMR0/10)%10);
   // send_d(48+(TMR0/100)%10);
   // send_d(48+TMR0%1000);
   // send_d(48+(TMR0/10000)%10);
   // send_d(48+TMR0IF);


  
 
 // qushu(0x10,TAB1B);               //get data from table  

 
//-------------------------------------------
//company tel.
void han_wr2c()
{
  send_i(0x88);                   //set display position 
  //qushu(0X10,TAB1C);              //get data from table 
  send_d(48+TMR0IF);
 
}

//-------------------------------------------
//company fax.
void han_wr2d()
{
  send_i(0x98);                  //set display position 
  qushu(0X10,TAB1D);             //get data from table  
 
}

//display setting.
void wr_zb()
{
  send_i(lcd_y);
  send_i(lcd_x);
}



//-------------------------------------------
//clear screen
void clear_p()
{
  send_i(0x1);                   //clear all
  send_i(0x34);                  //extend.
  send_i(0x30);                  //basic
}

//------------------------------------------
//search.
void qushu(int counts,const unsigned char *ps)
{
  int i;                         //define loop count.
  for(i=counts;i>0;i--)          //
     { 
        send_d(*ps);             //
        DelayMs(4);             //
        ps++;                    //get next.
     }
}

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

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

//-------------------------------------------
//check lcd busy.
void chk_busy()

   busy=1;                      //set busy signal                  
   TRISD=0XFF;                  //change the bus to input.         
   rs=0;                        //command not data.                
   rw=1;                        //read not write.                  
   while(busy)                 
      {
         nop();
         nop();
         nop();
         e=1;                   //enable.
         nop();
         nop();
         nop();
         if(!RD7) busy=0;       //
         nop();
         nop();
         nop();
         e=0;                   //DISABLE.
      }
   e=0;                         //DISABLE.
   TRISD=0X00;                  //bus as output.
 }



void DelayMs(unsigned char cnt)
{
#if    XTAL_FREQ <= 2MHZ
    do {
        DelayUs(996);
    } while(--cnt);
#endif

#if    XTAL_FREQ > 2MHZ   
    unsigned char    i;
    do {
        i = 4;
        do {
            DelayUs(255);  //250 initial value
        } while(--i);
    } while(--cnt);
#endif
}

void  scan()
 {
   result=0x8;             //initialize key scan result  

   if(RB0==0)              //judge if B0 press    
      result=0x4;                                 
   if(RB1==0)              //judge if B1 press    
      result=0x5;                                 
   if(RB2==0)              //judge if B2 press    
      result=0x6;                                 
   if(RB3==0)              //judge if B3 press    
      result=0x7;                                 
  }           


Create a free website at Webs.com