HGSC2561283串口DEMO程序

发布时间:2019/7/4 10:05:59

#include<reg51.h>

#include<intrins.h>

#include<string.h>

#include<stdio.h>

#define uchar unsigned char

#define uint unsigned int

 sbit SDI = P3^1;

 sbit SCLK = P3^3;

 sbit BUSY = P3^4;  

 sbit REST = P3^5;

 sbit CS = P3^6;

#define WD 256  /* 显示区宽度 */

#define HD 128  /* 显示区高度 */

#define clear 0x00  /* Clear Display */

#define time 1000  /* 1000延时 1.03895500 s */

#define c_time 50  

uchar code  CHHZ1[]={"清达光电技术有限公司"};

uchar code  CHHZ2[]={"OLED显示模块"};

uchar code  CHHZ3[]={"256 *128 DOT"};

uchar code  

CHHZ21[]={" ! #$%&'()*=,-./0123456789:;<=>?"};

uchar code  

CHHZ22[]={"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[ ]^_"};

uchar code  

CHHZ23[]={"`abcdefghijklmnopqrstuvwxyz{|}~ "};

/******** 中文字符库 *******/

/*--

  提取点阵方向:横向(先左->右, 再上->下)                                 --*/      

uchar code CCTAB[][32]={

/*--  文字:  清  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x80,0x00,0xE0,0x33,0x80,0x10,0xE0,0x03,0x80,0x40,0xFC,0x2F,0x00,0x01,0xE0,

0x12,0x20,0x13,0xA0,0x22,0x20,0x63,0xA0,0x42,0x20,0x02,0x60,0x00,0x20,0x00,0x00,

/*--  文字:  达  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x40,0x00,0x40,0x20,0x40,0x10,0x40,0x00,0x78,0x03,0xC0,0x70,0x40,0x10,0xA0,

0x21,0x10,0x12,0x08,0x10,0x00,0x7C,0x00,0x03,0xFE,0x00,0x38,0x00,0x00,0x00,0x00,

/*--  文字:  光  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x01,0x00,0x01,0x00,0x01,0x20,0x09,0x60,0x05,0x80,0x01,0x00,0x03,0xF0,0x3C,0x80,

0x04,0x80,0x04,0x80,0x08,0x82,0x10,0x82,0x20,0x82,0x40,0x7C,0x00,0x00,0x00,0x00,

/*--  文字:  电  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x02,0x00,0x02,0x00,0x02,0x00,0x03,0xE0,0x3E,0x20,0x22,0x20,0x23,0x20,0x2E,0x20,

0x13,0xC0,0x1E,0x00,0x02,0x04,0x02,0x04,0x02,0x04,0x01,0xF8,0x00,0x00,0x00,0x00,

/*--  文字:  技  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x10,0x40,0x10,0x40,0x10,0x40,0x10,0x70,0x1D,0xC0,0x70,0x40,0x10,0x70,0x19,0x90,

0x30,0x20,0xD1,0x20,0x10,0xC0,0x11,0x20,0x36,0x18,0x10,0x0E,0x00,0x00,0x00,0x00,

/*--  文字:  术  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x02,0x00,0x02,0x20,0x02,0x10,0x02,0x00,0x03,0xE0,0x3E,0x00,0x03,0x00,0x06,0x80,

0x0A,0x40,0x12,0x20,0x22,0x18,0x42,0x0E,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00,

/*--  文字:  有  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x01,0x00,0x01,0x00,0x02,0x7C,0x7F,0x80,0x04,0x00,0x04,0xE0,0x0F,0x20,0x14,0x20,

0x27,0xA0,0x44,0x20,0x87,0xA0,0x04,0x20,0x04,0x20,0x04,0xA0,0x04,0x40,0x00,0x00,

/*--  文字:  限  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x00,0x60,0x3B,0xA0,0x4A,0x20,0x53,0xA0,0x52,0x20,0x4B,0xC0,0x5B,0x10,

0x42,0xA0,0x42,0x40,0x42,0x30,0x42,0x9E,0x43,0x00,0x42,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  公  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x03,0x00,0x00,0x80,0x08,0x80,0x08,0x40,0x10,0x20,0x10,0x18,0x22,0x0E,

0x42,0x00,0x84,0x80,0x08,0x40,0x11,0xE0,0x1E,0x20,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  司  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x01,0xF0,0x0E,0x10,0x00,0x10,0x07,0x10,0x18,0x10,0x03,0x10,0x3D,0x10,

0x21,0x10,0x23,0x10,0x1C,0x10,0x00,0x10,0x00,0x50,0x00,0x20,0x00,0x00,0x00,0x00,

/*--  文字:  O  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x00,0x00,0x03,0x80,0x04,0x40,0x08,0x20,0x10,0x10,0x10,0x10,0x10,0x10,

0x10,0x10,0x10,0x10,0x08,0x20,0x04,0x40,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  L  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x00,0x00,0x0E,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,

0x04,0x00,0x04,0x00,0x04,0x10,0x04,0x10,0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  E  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x00,0x00,0x0F,0xF0,0x04,0x10,0x04,0x08,0x04,0x00,0x04,0x40,0x07,0xC0,

0x04,0x40,0x04,0x00,0x04,0x08,0x04,0x10,0x0F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  D  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x00,0x00,0x0F,0xC0,0x04,0x20,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0x10,

0x04,0x10,0x04,0x10,0x04,0x10,0x04,0x20,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  显  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x01,0xE0,0x1E,0x20,0x11,0xA0,0x0E,0x20,0x09,0xC0,0x0E,0x00,0x04,0x90,

0x04,0x90,0x24,0xA0,0x14,0xC0,0x04,0x80,0x07,0xFC,0xF8,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  示  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x00,0x60,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0xFC,0x7F,0x00,0x01,0x00,

0x11,0x20,0x11,0x18,0x31,0x08,0x21,0x00,0x03,0x00,0x01,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  模  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x10,0x10,0x90,0x10,0xFE,0x11,0x90,0x1C,0x78,0x71,0x88,0x11,0x68,0x19,0x08,

0x34,0xF0,0x50,0x4E,0x93,0xF0,0x10,0x60,0x10,0x90,0x11,0x08,0x16,0x06,0x00,0x00,

/*--  文字:  块  --*/

/*--  楷体_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/

0x00,0x00,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0xF0,0x1B,0x90,0x70,0xA0,0x10,0xFC,

0x1B,0x80,0x30,0x80,0xC1,0x40,0x02,0x20,0x04,0x18,0x18,0x0E,0x00,0x00,0x00,0x00,

};

/********* 时间延时程序 *********/

void delay(uint t)   /* 1.02500 ms */

{ uint i,j;

 for(i=t;i>0;i--)

   for(j=125;j>0;j--);

}

/******** 向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;

}

/******** 清屏显示程序 ********/

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);  //rev=0:正常显示;rev=1:反白显示

 for(i=0;i<k;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);  //rev=0:正常显示;rev=1:反白显示

 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 matrix(uchar x1,uchar y1,uchar x2,uchar y2,uchar z)

{

 write(0x63);

 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);  //fil=0:空心圆;fil=1:实心圆

 write(z);  //绘点或消点

}

/******** 光标显示程序 ********/

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

{

 write(0x70);

 write(x);  //垂直地址

 write(y);  //水平地址

 write(n);  //光标水平点列数

 write(z);  //绘点或消点

}

/******** 初始化程序 ********/

void set()

{

 delay(100);

 REST=0;

 delay(5);

 REST=1;

 delay(100);

 write(0x50);  //Display OFF

 write(0x52);  //Set Contrast Current

 write(0x80);  

 write(0x51);  //Display ON

//  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,10,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,14,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);  //方框

    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<HD/16;i++)

      chhzes(i*16,i,16,16,10,0,CCTAB);  //清达光电技术有限公司

    delay(time);  //*/

  }  

}


上一篇:3.5寸240128OLED显示模块例程 HGS2401281例程
下一篇:HC1621演示程序