HGSC2561283 SPI接口测试程序

发布时间:2019-07-17
   HGSC2561283为4.7寸256*128OLED显示模块,SPI接口测试程序如下:
#include
#include
#include  
#include 
  #define uchar unsigned char
#define uint unsigned int 

#define SPI  

#ifdef SPI  
  sbit SDI = P3^1;
  sbit SCLK = P3^3;
  sbit BUSY = P3^4;   
  sbit REST = P3^5;
  sbit CS = P3^6;
#endif

#define WD 256  
#define HD 128   
#define clear 0x00 
#define time 1000  
#define c_time 50  

uchar code  CHHZ1[]={"清达光电技术有限公司"};
uchar code  CHHZ2[]={"OLED显示模块"}; 
uchar code  CHHZ3[]={"256 * 128 DOT"}; 

uchar code  CHHZ21[]={" ! #$%&'()*=,-./:;<=>?"};
uchar code  CHHZ22[]={"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[ ]^_"};
uchar code  CHHZ23[]={"`abcdefghijklmnopqrstuvwxyz{|}~ "};




};


void delay(uint t)   /* 1.02500 ms */
{ uint i,j;
  for(i=t;i>0;i--)
    for(j=125;j>0;j--);
}


#ifdef SPI

void write(uchar ch)
{ uchar i;
  while(BUSY==1);
  CS=0;
  for(i=0;i<8;i++)
   { 
     if(ch&0x80)
       SDI=1;
     else  
       SDI=0;
     SCLK=0;         
SCLK=1;
     ch<<=1;   
   } 
  CS=1;
}

#endif



void clr(void)

  write(0x58);      
}


void chhzes(uchar x,uchar y,uchar m,uchar n,uchar k,uchar rev,uchar *s)

  uchar i;
  uint j;
  write(0x5A); 
  write(x); 
  write(y); 
  write(m);  
  write(n);  
  write(k);  
  write(rev);  

  for(i=0;i     for(j=0;j<(n+7)/8*m;j++)
      write(*s++); 
}//*/


void INTER_chhzes(uchar x,uchar y,uchar m,uchar n,uchar k,uchar rev,uchar *s)

  uchar i;
  write(0x5B); 
  write(x);  
  write(y);  
  write(m);  
  write(n);  
  write(k);  
  write(rev);  

  while(*s!='0')
    write(*s++);

}//*/


void graph(uchar x,uchar y,uchar m,uchar n,uchar *s)

  uint i;
  write(0x5D); 
  write(x);  
  write(y);  
  write(m);  
  write(n);  

  for(i=0;i<(n+7)/8*m;i++) 
    write(*s++);
}


void point(uchar x,uchar y,uchar z)

  write(0x60); 
  write(x);  
  write(y);  
  write(z);  
}


void show_line(uchar x1,uchar y1,uchar x2,uchar y2,uchar z)

  write(0x61); 
  write(x1);  
  write(y1);  
  write(x2); 
  write(y2); 
  write(z); 
}


void block(uchar x1,uchar y1,uchar x2,uchar y2,uchar z)

  write(0x62); 
  write(x1);  
  write(y1);  
  write(x2);  
  write(y2); 
  write(z);  
}



void draw_circle(uchar x,uchar y,uchar r,uchar fil,uchar z)

  write(0x64); 
  write(x); 
  write(y);  
  write(r);  
  write(fil);  
  write(z); 
}


void cursor(uchar x,uchar y,uchar n,uchar z)

  write(0x70); 
  write(x); 
  write(y);  
  write(n);  
  write(z);  
}


void set()

  #ifdef SPI

  #endif

  delay(100);
  REST=0;
  delay(5);
  REST=1;
  delay(100);
  
  write(0x50);  

  write(0x52);  

  write(0x51);  
  
//  clr();  
}
 

void main()

  uchar i;
  uint j;       

  set();  
  while(1)
   { 
     clr();  
     block(0,0,127,255,1);  
     show_line(0,0,127,255,1); 
     show_line(0,255,127,0,1);
     matrix(16,112,16,143,1);
     matrix(24,128,48,128,1);
     matrix(80,112,111,143,1);  
     draw_circle(64,32,20,0,1);  
     draw_circle(64,216,20,1,1); 
     delay(time);   //*/

     clr();  
     INTER_chhzes(8,32,16,16,12,0,"杭州清达光电技术有限公司");
     INTER_chhzes(28,64,16,16,8,0,"OLED显示模块");
     INTER_chhzes(48,72,16,8,14,0,"256 * 128 DOTS");
     INTER_chhzes(68,0,16,16,16,0,"杭州清达光电技术有限公司显示模块");
     INTER_chhzes(92,40,16,8,22,0,"www.chinalcdmodule.com");
     INTER_chhzes(108,32,16,8,24,1,"www.china-lcdmodules.com");  
     delay(time);  
     block(0,0,127,255,1);  

/*     for(i=0;i<32;i+=16) 
       for(j=0;j<256;j+=16)
        { 
          cursor(i+15,j,16,1);
          delay(c_time);
          cursor(i+15,j,16,0);
        }   //*/     
     delay(time);    //*/

     clr();  
     INTER_chhzes(0,0,16,8,32,0,CHHZ21);
     INTER_chhzes(16,0,16,8,32,0,CHHZ22);
     INTER_chhzes(32,0,16,8,32,0,CHHZ23);
     INTER_chhzes(64+0,0,8,8,32,0,CHHZ21);
     INTER_chhzes(64+16,0,8,8,32,0,CHHZ22);
     INTER_chhzes(64+32,0,8,8,32,0,CHHZ23);
     delay(time);    //*/
     
     clr();  //清屏 
     for(i=0;i        chhzes(i*16,i,16,16,10,0,CCTAB);  
     delay(time);  //*/
     
   }  
//  delay(time);//*/
}



上一篇:海南步进行星减速机PLF60-4...
下一篇:西门子6ES7212-1BE40...