杭州清达光电技术有限公司

12年

杭州清达光电技术有限公司

卖家积分:21001分-22000分营业执照:已审核经营模式:原厂制造商所在地区:浙江 杭州

收藏本公司 人气:1127537

企业档案

  • 相关证件:营业执照已审核 
  • 会员类型:
  • 会员年限:12年
  • 卢小姐 QQ:752574498
  • 电话:13506715842
  • 手机:13506715842
  • 阿库IM:
  • 地址:杭州市余杭区仁和街道永泰路2号22幢
  • E-mail:752574498@qq.com

您的当前位置:

杭州清达光电技术有限公司 > 技术资料 > HGS128641测试程序

HGS128641测试程序

发布时间: 2014/12/9 10:12:07 | 1618 次阅读

#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define I80


#define xData P1 // Parallel Data Input
#define RES   P3_5
#define CS    P3_4
#define DC    P3_3
#define WR    P3_1
#define RD    P3_0
#define SCLK P1_0 // Serial Clock Input
#define SDIN P1_1 // Serial Data Input


uchar data_4byte[4];


unsigned  char code tab[4][32]={
 /* 点阵:16x16
   提取点阵方向:横向(先左->右, 再上->下)
   字节掉转:否
   字节方式:C语言 */
0x00,0x40,0x40,0x48,0x37,0xFC,0x10,0x40,    // 清
0x83,0xF8,0x60,0x40,0x2F,0xFE,0x08,0x00,
0x13,0xF8,0x12,0x08,0x63,0xF8,0x22,0x08,
0x23,0xF8,0x22,0x08,0x22,0x28,0x22,0x10,


0x01,0x00,0x41,0x00,0x27,0xE0,0x21,0x00,    // 达
0x1F,0xF0,0x04,0x20,0xE2,0x40,0x2F,0xF0,
0x21,0x00,0x2F,0xE0,0x21,0x00,0x3F,0xF8,
0x21,0x00,0x51,0x00,0x8F,0xFE,0x00,0x00,


0x01,0x00,0x21,0x08,0x11,0x0C,0x09,0x10,    // 光
0x09,0x20,0x01,0x04,0xFF,0xFE,0x04,0x40,
0x04,0x40,0x04,0x40,0x04,0x40,0x08,0x40,
0x08,0x42,0x10,0x42,0x20,0x3E,0x40,0x00,


0x1F,0xF0,0x41,0x04,0x7F,0xFE,0x81,0x02,    // 电
0x3D,0x74,0x01,0x00,0x3D,0x70,0x01,0x00,
0x3F,0xF8,0x21,0x08,0x3F,0xF8,0x21,0x08,
0x3F,0xF8,0x01,0x02,0x01,0x02,0x01,0xFE,
};
uchar code tab88[]={
               0x0e,0x11,0x11,0x11,0x15,0x12,0x0b,0x00,// Q 代码"31"
              0x0e,0x11,0x11,0x11,0x15,0x12,0x0b,0x00,// Q 代码"31"
              0x1f,0x02,0x04,0x02,0x01,0x11,0x0e,0x00,// 3 代码"13"
             0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e,0x00,// 8 代码"18"
0x04,0x0c,0x04,0x04,0x04,0x04,0x0e,0x00,//1 代码"11"
0x04,0x0c,0x04,0x04,0x04,0x04,0x0e,0x00,//1 代码"11"
                0x0e,0x11,0x11,0x0e,0x01,0x02,0x0c,0x00,// 9 代码"19"
0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e,0x00,// 8 代码"18"
0x02,0x06,0x0a,0x12,0x1f,0x02,0x02,0x00,// 4 代码"14"
0x06,0x08,0x10,0x1e,0x11,0x11,0x0e,0x00,// 6 代码"16"
0x02,0x06,0x0a,0x12,0x1f,0x02,0x02,0x00,// 4 代码"14"
        0x0e,0x11,0x13,0x15,0x19,0x11,0x0e,0x00,// 0 代码"10"
0x04,0x0c,0x04,0x04,0x04,0x04,0x0e,0x00,//1 代码"11"
0x0e,0x11,0x01,0x02,0x04,0x08,0x1f,0x00,//2 代码"12"
0x1f,0x02,0x04,0x02,0x01,0x11,0x0e,0x00,// 3 代码"13"
0x02,0x06,0x0a,0x12,0x1f,0x02,0x02,0x00,// 4 代码"14"
0x1f,0x10,0x1e,0x01,0x01,0x11,0x0e,0x00,// 5 代码"15"
0x06,0x08,0x10,0x1e,0x11,0x11,0x0e,0x00,// 6 代码"16"
0x1f,0x01,0x02,0x04,0x04,0x04,0x04,0x00,// 7 代码"17"
0x0e,0x11,0x11,0x0e,0x11,0x11,0x0e,0x00,// 8 代码"18"
0x0e,0x11,0x11,0x0e,0x01,0x02,0x0c,0x00,// 9 代码"19"
        0x0e,0x11,0x11,0x11,0x1f,0x11,0x11,0x00,// A 代码"21"
0x1e,0x09,0x09,0x0e,0x09,0x09,0x1e,0x00,// B 代码"22"
0x0e,0x11,0x10,0x10,0x10,0x11,0x0e,0x00,// C 代码"23"
0x1e,0x09,0x09,0x09,0x09,0x09,0x1e,0x00,// D 代码"24"
0x1f,0x10,0x10,0x1f,0x10,0x10,0x1f,0x00,// E 代码"25"
0x1f,0x10,0x10,0x1e,0x10,0x10,0x10,0x00,// F 代码"26"
0x0e,0x11,0x10,0x13,0x11,0x11,0x0f,0x00,// G 代码"27"
0x11,0x11,0x11,0x1f,0x11,0x11,0x11,0x00,// H 代码"28"
0x0e,0x04,0x04,0x04,0x04,0x04,0x0e,0x00,// I 代码"29"
0x07,0x02,0x02,0x02,0x02,0x12,0x0c,0x00,// J 代码"2A"
        0x00,0x00,0x0e,0x01,0x0f,0x11,0x0f,0x00,// a 代码"41"
0x10,0x10,0x16,0x19,0x11,0x11,0x1e,0x00,// b 代码"42"
0x00,0x00,0x0e,0x11,0x10,0x11,0x0e,0x00,// c 代码"43"
0x01,0x01,0x0d,0x13,0x11,0x11,0x0f,0x00,// d 代码"44"
0x00,0x00,0x0e,0x11,0x1f,0x10,0x0e,0x00,// e 代码"45"
0x02,0x05,0x04,0x0e,0x04,0x04,0x04,0x00,// f 代码"46"
0x00,0x0d,0x13,0x13,0x0d,0x01,0x0e,0x00,// g 代码"47"
0x10,0x10,0x16,0x19,0x11,0x11,0x11,0x00,// h 代码"48"
0x04,0x00,0x0c,0x04,0x04,0x04,0x0e,0x00,// i 代码"49"
0x02,0x00,0x06,0x02,0x02,0x12,0x0c,0x00,// j 代码"4A"
0x08,0x08,0x09,0x0a,0x0c,0x0a,0x09,0x00,//k 代码"4B"
};
uchar code tab816[]={
/*--  文字:  1  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,


/*--  文字:  2  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00,


};
uchar code picture[]={
/*--  调入了一幅图像:d:\我的文档\桌面\04.bmp  --*/
/*--  宽度x高度=128x64  --*/
0x00,0x00,0x2D,0xF5,0xFA,0x55,0xE9,0x6B,0x7D,0x59,0xE0,0xB5,0x3A,0x72,0xF0,0x00,
0x00,0x00,0x5B,0xED,0xF4,0xFB,0xFA,0xAD,0x3D,0x4D,0xE1,0x52,0xBD,0x72,0xE8,0x00,
0x00,0x00,0x37,0xF5,0xFD,0x5F,0xED,0xB5,0xBE,0xA4,0xE1,0xDA,0x1F,0x3A,0x68,0x00,
0x00,0x00,0xEE,0xF7,0xEA,0xEE,0xF5,0x56,0xBE,0xB2,0x70,0x21,0x5E,0x50,0x5C,0x00,
0x00,0x00,0xDD,0xDB,0xBD,0x77,0xFF,0x5A,0x9E,0x52,0x73,0x01,0x5B,0x28,0x34,0x00,
0x00,0x01,0xBD,0xBF,0xFA,0xFF,0xF6,0xDA,0xD7,0x59,0x78,0x01,0x5F,0x10,0x6C,0x00,
0x00,0x01,0xFB,0x7D,0xBB,0x7A,0xF7,0x6B,0x5B,0x89,0x38,0x40,0x9B,0x44,0x34,0x00,
0x00,0x01,0xF7,0x7F,0x6C,0x7F,0xF7,0xB5,0xCB,0xAC,0x3B,0x00,0x4F,0x04,0x36,0x00,
0x00,0x01,0xF6,0xFB,0xB7,0x5C,0x14,0xB7,0x2D,0x44,0x3C,0x10,0xA7,0x42,0xBA,0x00,
0x00,0x00,0xC6,0xF6,0x6F,0x6A,0x14,0xB1,0xAD,0x56,0x1B,0xC0,0x96,0x42,0x56,0x00,
0x00,0x00,0xCE,0xF5,0x3D,0x60,0x14,0xB9,0xA5,0x4A,0x1F,0x58,0xE2,0x4A,0xD6,0x00,
0x00,0x00,0xCD,0xEC,0x75,0x60,0x14,0x90,0xB5,0xEA,0x1D,0xB0,0x85,0x56,0xB6,0x00,
0x00,0x00,0xDD,0xED,0x7F,0x50,0x04,0x98,0xF4,0xAF,0x8E,0xD0,0x05,0x4A,0xF6,0x00,
0x00,0x00,0x99,0xCC,0xF7,0xA8,0x04,0x5B,0x94,0xA9,0x1D,0x90,0x0A,0xDF,0xDC,0x00,
0x00,0x00,0x9B,0xDE,0x77,0xB0,0x00,0x4C,0xD4,0xAD,0x8F,0xEA,0x06,0xDF,0xB8,0x01,
0x00,0x00,0x9B,0x9C,0xB7,0x50,0x00,0x18,0x90,0xA9,0x2F,0xF8,0xBE,0xBF,0xF8,0x00,
0x00,0x01,0x4A,0x9E,0x7B,0x28,0x00,0x18,0x92,0x1C,0x8F,0x8D,0xB5,0xDF,0xB0,0x01,
0x00,0x00,0xFE,0xBA,0xF7,0xA4,0x00,0x20,0x80,0x9D,0x8F,0x04,0x3F,0xBF,0xE0,0x02,
0x00,0x00,0xB3,0x3A,0x7B,0xB2,0x00,0x00,0xA0,0x19,0xA2,0x06,0x7F,0x7F,0x80,0x01,
0x00,0x01,0x7F,0x5C,0xFA,0x91,0x00,0x00,0x8F,0x89,0x8C,0x27,0x7F,0xFF,0x00,0x02,
0x00,0x00,0x97,0x3A,0x5B,0xD0,0x00,0x00,0x3F,0xF2,0xA4,0x43,0xFD,0xFF,0x00,0x00,
0x00,0x00,0x9F,0x5A,0x7B,0x48,0x40,0x04,0xFF,0xFB,0xAC,0x93,0xFF,0xEE,0x00,0x05,
0x00,0x01,0x7F,0x7D,0x59,0xCE,0x30,0x00,0xFF,0x9F,0xA8,0x02,0xFF,0xFD,0x00,0x02,
0x40,0x00,0xF7,0x7A,0x7D,0xB0,0x00,0x02,0xDF,0x97,0xAC,0x83,0x3F,0xF5,0x80,0x01,
0x00,0x00,0xFF,0xBD,0x5E,0xE2,0x00,0x02,0x8F,0xD5,0x2D,0x01,0xEB,0xF2,0xC0,0x01,
0x00,0x00,0xFF,0xFD,0x7D,0xD0,0x00,0x00,0xB7,0xDD,0x28,0x00,0xFF,0xFD,0x40,0x00,
0x00,0x00,0x7F,0xFD,0x3E,0xC0,0x00,0x00,0x97,0xB5,0x68,0x80,0xE7,0xFA,0xA0,0x00,
0x00,0x00,0x7F,0xFB,0x2E,0xE1,0xF8,0x00,0x08,0x27,0x48,0x08,0xE7,0xF6,0x80,0x00,
0x00,0x00,0x3B,0xFF,0xBE,0x73,0xFA,0x00,0x06,0xF5,0x68,0x08,0xE7,0x38,0xC0,0x00,
0x00,0x00,0x39,0xFE,0x97,0x37,0xE4,0x00,0x00,0x06,0xC9,0x1E,0xEF,0x72,0x00,0x10,
0x00,0x00,0x0D,0xFB,0xDF,0x9F,0xE4,0x00,0x00,0x06,0xCA,0x2C,0xBE,0x72,0x00,0x54,
0x00,0x00,0x04,0xFD,0xDF,0xDF,0xF4,0x00,0x00,0x05,0xD8,0x07,0x57,0x70,0x01,0x54,
0x00,0x40,0x02,0x7F,0xEB,0xF5,0xFC,0x00,0x00,0x06,0x9A,0x40,0xE6,0x70,0x00,0xAA,
0xA1,0x40,0x01,0x1F,0xF7,0xED,0x08,0x00,0x00,0x07,0xDA,0xC0,0xE6,0xF0,0x00,0xD5,
0x00,0xC0,0x00,0x01,0xFF,0xF4,0xC8,0x00,0x00,0x07,0xD1,0x80,0x62,0xF2,0x00,0x6A,
0x2A,0xA0,0x00,0x03,0xEF,0xF1,0xF0,0x00,0x00,0x05,0x5A,0xC0,0xC7,0xF0,0x00,0x2A,
0x43,0xA0,0x00,0x02,0xF6,0xF8,0x00,0x00,0x00,0x05,0xB6,0xC0,0xC7,0xB0,0x00,0x1A,
0x12,0xC0,0x18,0x02,0x7B,0x78,0x00,0x00,0x00,0x0B,0xDC,0x40,0xC7,0x30,0x02,0x14,
0x09,0xD4,0xD0,0x12,0x7E,0xD8,0x00,0x00,0x00,0x0B,0x5C,0x60,0x47,0x30,0x00,0x00,
0x0A,0x51,0x61,0x63,0x5B,0x7C,0x00,0x00,0x00,0x17,0x58,0x60,0xC6,0x30,0x00,0x00,
0x02,0xB2,0xC1,0x63,0x7B,0xAC,0x00,0x00,0x00,0x15,0xB8,0x20,0x4A,0x31,0x00,0x00,
0x06,0x43,0x03,0x41,0x3B,0xF6,0x00,0x01,0x80,0x27,0x78,0x30,0xDE,0x31,0x00,0x00,
0x41,0xC2,0x83,0xD1,0x3F,0xEE,0x00,0x0D,0x00,0x0B,0x70,0x38,0x58,0x31,0x00,0x00,
0xA2,0xC6,0x85,0x09,0xFB,0xEF,0x00,0x10,0x00,0x0A,0xB0,0x1D,0x72,0x35,0x04,0x01,
0x42,0x46,0x4E,0x30,0xBB,0xFD,0x80,0x00,0x00,0x07,0x70,0x0F,0xC6,0x76,0x85,0x55,
0x82,0xA2,0xB5,0x80,0xDB,0xD5,0xC0,0x03,0x00,0x16,0xF0,0x02,0xC4,0x25,0x82,0x28,
0x00,0xA1,0xD4,0x00,0x7E,0xDE,0xE0,0x00,0x00,0x16,0xF0,0x00,0x46,0xBA,0x81,0xD4,
0x0C,0x56,0x58,0x00,0x37,0xFB,0xF0,0x00,0x00,0x25,0xE0,0x00,0xC4,0xD6,0x82,0x02,
0x9D,0xAD,0xE1,0x00,0x3B,0xF1,0xFC,0x00,0x00,0x4E,0xF0,0x00,0x46,0xAE,0x41,0x00,
0xA9,0xB3,0x06,0x80,0x2F,0xF0,0xF7,0x00,0x00,0x8D,0x68,0x00,0xD6,0xED,0xC0,0x00,
0xDA,0x64,0x03,0x50,0x2D,0x78,0xFF,0x00,0x01,0x0E,0xEE,0x00,0x57,0xAE,0x40,0x00,
0xB4,0x90,0x0B,0xC1,0x2A,0xF8,0xBE,0x00,0x02,0x0D,0xEF,0x00,0xF9,0xAB,0xA0,0x04,
0x67,0x30,0x3E,0x7F,0x3C,0xF0,0xBE,0x00,0x0C,0x4A,0xEC,0x02,0xDF,0xAF,0x60,0x08,
0xDC,0x40,0x01,0xBE,0x36,0xF8,0xFF,0x00,0x38,0x0D,0xF8,0x03,0x17,0xF8,0xA0,0x0A,
0x31,0x80,0x01,0xFE,0xEA,0xF8,0x6F,0x00,0x59,0x1E,0xE0,0x01,0xBD,0x6A,0x90,0x08,
0x42,0x00,0x0D,0x3B,0x7A,0xE8,0xFF,0x00,0x10,0x39,0xC0,0x80,0xB7,0xC9,0x50,0x00,
0x8C,0x0A,0xFC,0x3F,0xFC,0xE8,0x7F,0x00,0x3D,0xFD,0xE2,0x00,0x6D,0xD6,0x90,0x00,
0x20,0x2F,0xF3,0x1B,0x7B,0xEC,0x7F,0x00,0x3F,0xD5,0xC0,0x00,0x7D,0x89,0x48,0x15,
0x70,0x00,0x71,0x5F,0x78,0x94,0x7F,0x00,0x74,0xDD,0xE4,0x00,0x5D,0x84,0xA8,0x2B,
0xE0,0x00,0x07,0x96,0xB3,0xB6,0xFF,0x00,0xA1,0xDB,0xC0,0x03,0x46,0xAD,0xA8,0x0A,
0x80,0x00,0x1B,0x1E,0xFC,0x2B,0x7F,0x00,0xA7,0x59,0xE0,0x00,0x43,0x42,0x08,0x1E,
0x00,0x09,0x60,0xF4,0xF3,0xEB,0x7F,0x00,0xA4,0x7B,0xC8,0x00,0x69,0x24,0x14,0x16,
0x00,0x0F,0x81,0x55,0x5B,0xFB,0x7F,0x01,0x38,0xDB,0xC0,0x00,0x25,0x24,0x04,0x1F,
0x01,0x1B,0x07,0xD9,0xB1,0xF5,0x7F,0x01,0x7E,0xDB,0xC0,0x00,0x21,0x44,0x04,0x0A,




};


/******************************************************************
      延时子程序
*****************************************************************/
void uDelay(unsigned char l)
{
while(l--);
}




void delay(unsigned char n)
{
unsigned char i,j,k;


for(k=0;k<n;k++)
{
for(i=0;i<120;i++)
{_nop_();}}
}
void delay100ms(unsigned char n)
{
unsigned char i,j,k;


for(k=0;k<n;k++)
{
for(i=0;i<100;i++)
{delay(1);}}
}
#ifdef I80
/*********************************************************************
   写入指令和数据
************************************************************************/
void WriteCommand(unsigned char Data)
{
DC=0;
CS=0;
        xData=Data;
WR=0;
        _nop_();
        _nop_();
WR=1;
        _nop_();
        _nop_();
CS=1;
DC=1;
}
void WriteData(unsigned char Data)
{
DC=1;
CS=0;
        xData=Data;
WR=0;
         _nop_();
        _nop_();
WR=1;
         _nop_();
        _nop_();
CS=1;
DC=1;
}
#endif


#ifdef SPI
void Write_Command(unsigned char Data)
{
unsigned char i;


CS=0;
DC=0;
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}


void Write_Data(unsigned char Data)
{
unsigned char i;


CS=0;
DC=1;
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}
#endif


void Set_Remap_Format(unsigned char d)
{
WriteCommand(0xA0); // Set Re-Map & Data Format
WriteCommand(d); //   Default => 0x00
//     Column Address 0 Mapped to SEG0
//     Disable Nibble Re-Map
//     Horizontal Address Increment
//     Scan from COM0 to COM[N-1]
//     Disable COM Split Odd Even
}
/******************************************************
      写满oled
*************************************************/
void all_screen(uchar m)
{
    uint j,i;
 //Column Address
   WriteCommand(0x15); /* Set Column Address */
   WriteCommand(0x00);  /* Start = 0 */
   WriteCommand(0x3F);  /* End = 127 */
// Row Address
 WriteCommand(0x75); /* Set Row Address */
   WriteCommand(0x00);  /* Start = 0 */
   WriteCommand(0x50);  /* End = 80 */
        for (j=0;j<80;j++) /* 80 row */
         {
      for (i=0;i<64;i++) /* 64*2=128 column  a nibble of command is a dot*/
       {
    WriteData(m);
       }
         }


}
/*****************************************************************
    OLED初始化
*****************************************************************/
 void oled_init()
{
        _nop_();
        RES=0;      //oled reset
        _nop_();  _nop_();
        RES=1;
        _nop_(); _nop_();
/**********************************************************
// OLED HGS128646 Initialization Command
********************************************************/
// Column Address
 WriteCommand(0x15); /* Set Column Address */
 WriteCommand(0x00);  /* Start = 0 */
 WriteCommand(0x3F);  /* End = 127 */


// Row Address
 WriteCommand(0x75); /* Set Row Address */
 WriteCommand(0x0c);  /* Start = 0 */
 WriteCommand(0x4b);  /* End = 63 */


// Contrast Control
 WriteCommand(0x81); /* Set Contrast Control */
 WriteCommand(0x7f);  /* 0 ~ 127 */


// Current Range
WriteCommand(0x86); /* Set Current Range84h:Quarter, 85h:Half,86h:Full*/


// Re-map
 WriteCommand(0xA0); /* Set Re-map */
 WriteCommand(0x52);  /* [0]:MX, [1]:Nibble, [2]:H/Vaddress [4]:MY, [6]:Com Split Odd/Even "1000010"*/


// Display Start Line
 WriteCommand(0xA1); /* Set Display Start Line */
 WriteCommand(0x0c);  /* Top */


// Display Offset
 WriteCommand(0xA2); /* Set Display Offset */
 WriteCommand(0x4c);  /* No offset */


// Display Mode
 WriteCommand(0xA4); /* Set DisplaMode,A4:Normal,A5:All ON, A6: All OFF,A7:Inverse */


// Multiplex Ratio
 WriteCommand(0xA8); /* Set Multiplex Ratio */
 WriteCommand(0x3F);  /* [6:0]16~128, 64 rows=3Fh*/


// Phase Length
 WriteCommand(0xB1); /* Set Phase Length */
// WriteCommand(0x22);  /* [3:0]:Phase 1 period of 1~16clocks */
WriteCommand(0x02);  /* [7:4]:Phase 2 period of 1~16clocks /* POR = 0111 0100 */
// Row Period
 WriteCommand(0xB2); /* Set Row Period */
 WriteCommand(0x46);  /* [7:0]:18~255,K=P1+P2+GS15 (POR:4+7+29)*/


// Display Clock Divide
 WriteCommand(0xB3); /* Set Clock Divide */
 WriteCommand(0x41);  /* [3:0]:1~16, [7:4]:0~16 */
                              /* POR = 0000 0001 */
// VSL
 WriteCommand(0xBF); /* Set VSL */
 WriteCommand(0x0D);  /* [3:0]:VSL */


// CCOMH
 WriteCommand(0xBE); /* Set VCOMH */
 WriteCommand(0x00);  /* [7:0]:VCOMH */


// VP
 WriteCommand(0xBC); /* Set VP */
 WriteCommand(0x0B);  /* [7:0]:VP */


// Gamma
 WriteCommand(0xB8); /* Set Gamma with next 8 bytes*/
 WriteCommand(0x01);  /* L1[2:1] */
 WriteCommand(0x11);  /* L3[6:4], L2[2:0] 0001 0001*/
 WriteCommand(0x22);  /* L5[6:4], L4[2:0] 0010 0010*/
 WriteCommand(0x32);  /* L7[6:4], L6[2:0] 0011 1011*/
 WriteCommand(0x43);  /* L9[6:4], L8[2:0] 0100 0100*/
 WriteCommand(0x54);  /* LB[6:4], LA[2:0] 0101 0101*/
 WriteCommand(0x65);  /* LD[6:4], LC[2:0] 0110 0110*/
 WriteCommand(0x76);  /* LF[6:4], LE[2:0] 1000 0111*/


// Set DC-DC
 WriteCommand(0xAD); /* Set DC-DC */
 WriteCommand(0x02);  /* 03=ON, 02=Off */
          all_screen(0x00);
// Display ON/OFF
 WriteCommand(0xAF); /* AF=ON, AE=Sleep Mode */
}


/**************************************
  转换子程序
****************************************/
void write_4_byte(uchar DATA)
{
  uchar k;
  uchar kk,kkk;
  kk=DATA;
  for(k=0;k<4;k++)   // 一两位的方式写入  2*4=8位
   {
     kkk=kk&0xc0;     //当K=0时 为D7,D6位 当K=1时 为D5,D4位


     /****出现4种可能,16阶色素,一个地址两个像素,一个像素对应4位***/


     switch(kkk)
       {
case 0x00:
           data_4byte[k]=0x00;
         break;
         case 0x40:
           data_4byte[k]=0x0f;
         break;
case 0x80:
           data_4byte[k]=0xf0;
         break;
         case 0xc0:
           data_4byte[k]=0xff;
         break;
      default:
      break;
  }
      kk=kk<<2;                                //左移两位
      WriteData(data_4byte[k]);                /* 8 column  a nibble of command is a dot*/
   }


}
/****************************************************
   写入一个16*16汉字
******************************************************/
void word_1616(uchar x,uchar y,uchar coder)//write chinese word of1616
{
    uint i,j;


for(j=0;j<16;j++)
{
   WriteCommand(0x75); /* Set Row Address */
   WriteCommand(0x0c+y+j);  /* Start = Row */
   WriteCommand(0x0c+y+15);  /* End = Row+16 */
   WriteCommand(0x15); /* Set Column Address */
   WriteCommand(x);  /* Start = Column */
   WriteCommand(x+7);  /* End = Column+16 */
            for (i=0;i<2;i++) /* 2*8 column , a nibble of command is a dot*/
    {
  write_4_byte(tab[coder][(j<<1)+i]);
    }
}
}
/****************************************************
   写入一串16*16汉字
******************************************************/
void hanzi16(uchar x,uchar y,uchar m,uchar endm)
{
  uchar i;
  for(i=m;i<endm;i++)
  {
  word_1616(x,y,i);
  x=x+8;            // 8*2=16间隔一个汉字
  }
}
/****************************************************
   写入一个8*16字母
******************************************************/
void word_816(uchar x,uchar y,uchar coder)//write chinese word of1616
{
    uint i,j;
         for(j=0;j<16;j++)
             {
   WriteCommand(0x75); /* Set Row Address */
   WriteCommand(0x0c+y+j);  /* Start = Row */
   WriteCommand(0x0c+y+15);  /* End = Row+8 */
   WriteCommand(0x15); /* Set Column Address */
   WriteCommand(x);  /* Start = Column */
   WriteCommand(x+3);  /* End = Column+8 */
            write_4_byte(tab816[16*coder+j]);
}


}
/****************************************************
   写入一串8*8字母
******************************************************/
void hanzi816(uchar x,uchar y,uchar m,uchar endm)
{
  uchar i;
  for(i=m;i<endm;i++)
  {
  word_816(x,y,i);
  x=x+4;            // 4*2=8间隔一个字母
  }
}


/****************************************************
   写入一个8*8字母
******************************************************/
void word_88(uchar x,uchar y,uchar coder)//write chinese word of1616
{
    uint i,j;
         for(j=0;j<8;j++)
             {
   WriteCommand(0x75); /* Set Row Address */
   WriteCommand(0x0c+y+j);  /* Start = Row */
   WriteCommand(0x0c+y+7);  /* End = Row+8 */
   WriteCommand(0x15); /* Set Column Address */
   WriteCommand(x);  /* Start = Column */
   WriteCommand(x+3);  /* End = Column+8 */
            write_4_byte(tab88[8*coder+j]);
}


}
/****************************************************
   写入一串8*8字母
******************************************************/
void hanzi8(uchar x,uchar y,uchar m,uchar endm)
{
  uchar i;
  for(i=m;i<endm;i++)
  {
  word_88(x,y,i);
  x=x+4;            // 4*2=8间隔一个字母
  }
}
/************************************************************************************
  无灰度 图片  是单色图片,由转换程序将单色  转为16阶图片显示
**************************************************************************************/
void oled_map()
{
uint j,i;
   WriteCommand(0x15); /* Set Column Address */
   WriteCommand(0x00);  /* Start = 0 */
   WriteCommand(0x3F);  /* End = 127 */
// Row Address
   WriteCommand(0x75); /* Set Row Address */
   WriteCommand(0x0c);  /* Start = 0 */
   WriteCommand(0x4b);  /* End = 63 */
for(j=0;j<64;j++)
{
      for (i=0;i<16;i++) /* 16*8 column  a nibble of command is a dot*/
       {
     write_4_byte(picture[(j<<4)+i]);      // 转换程序 字节取16个字节后换行
       }
}
}
/*************************************************************
 垂直方向是卷动  有F的值来确定卷动方向
*************************************************************/
void Vertical_scroll(uchar f)
{
    uchar i;
    switch(f)
    {
    case 0:
    for(i=0x0c;i<0x4c;i++)
      {
   WriteCommand(0xA1); /* Set start line */
   WriteCommand(i);  /* No offset */
        delay100ms(1);
      }  break;
    case 1:
    for(i=0x0c;i<0x4c;i++)
      {
   WriteCommand(0xA1); /* Set start line */
   WriteCommand(0x4c-i);  /* No offset */
        delay100ms(1);
      }  break;
    default:
    WriteCommand(0xA1); /* Set start line */
    WriteCommand(0x0c);
}}
/*************************************************************
 水平方向是卷动  有a的值来确定卷动方向
 //  Continuous Horizontal Scrolling (Partial or Full Screen)
//
//    a: Set Numbers of Column Scroll per Step
//    b: Set Numbers of Row to Be Scrolled
//    c: Set Time Interval between Each Scroll Step in Terms of Frame Frequency
//    d: Delay Time
*************************************************************/
 void GA_Option(unsigned char f)
{
WriteCommand(0x23); // Graphic Acceleration Command Options
WriteCommand(f); //   Default => 0x01
//     Enable Fill Rectangle
//     Disable Wrap around in Horizontal Direction During Copying & Scrolling
//     Disable Reverse Copy
}


void Horizontal_Scroll(unsigned char a, unsigned char b, unsigned char c, unsigned char d)
{
GA_Option(0x03);
WriteCommand(0x26); // Horizontal Scroll Setup
WriteCommand(a);
WriteCommand(b);
WriteCommand(c);
WriteCommand(0x2F); // Activate Scrolling
delay100ms(d);
}
/*************************************************************
 禁止卷动指令  用于卷动之后重新填写数据   确保正常显示
*************************************************************/
 void Deactivate_Scroll()
{
WriteCommand(0x2E); // Deactivate Scrolling
}




/*************************************************************
 写入矩形
*************************************************************/
void Draw_Rectangle(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e)
{
WriteCommand(0x24); // Draw Rectangle
WriteCommand(a); //   Column Address of Start
WriteCommand(c); //   Row Address of Start
WriteCommand(b); //   Column Address of End (Total Columns Devided by 2)
WriteCommand(d); //   Row Address of End
WriteCommand(e); //   Gray Scale Level
delay(2000);
}
/*************************************************************
 灰阶显示
*************************************************************/


void Fill_Block(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e)
{
GA_Option(0x01);
Draw_Rectangle(a,b,c,d,e);
}


void Grayscale()
{
//   Level 16 => Column 1~8
Fill_Block(0x00,0x03,0x00,0x3F,0xFF);


//   Level 15 => Column 9~16
Fill_Block(0x04,0x07,0x00,0x3F,0xEE);


//   Level 14 => Column 17~24
Fill_Block(0x08,0x0B,0x00,0x3F,0xDD);


//   Level 13 => Column 25~32
Fill_Block(0x0C,0x0F,0x00,0x3F,0xCC);


//   Level 12 => Column 33~40
Fill_Block(0x10,0x13,0x00,0x3F,0xBB);


//   Level 11 => Column 41~48
Fill_Block(0x14,0x17,0x00,0x3F,0xAA);


//   Level 10 => Column 49~56
Fill_Block(0x18,0x1B,0x00,0x3F,0x99);


//   Level 9 => Column 57~64
Fill_Block(0x1C,0x1F,0x00,0x3F,0x88);


//   Level 8 => Column 65~72
Fill_Block(0x20,0x23,0x00,0x3F,0x77);


//   Level 7 => Column 73~80
Fill_Block(0x24,0x27,0x00,0x3F,0x66);


//   Level 6 => Column 81~88
Fill_Block(0x28,0x2B,0x00,0x3F,0x55);


//   Level 5 => Column 89~96
Fill_Block(0x2C,0x2F,0x00,0x3F,0x44);


//   Level 4 => Column 97~104
Fill_Block(0x30,0x33,0x00,0x3F,0x33);


//   Level 3 => Column 105~112
Fill_Block(0x34,0x37,0x00,0x3F,0x22);


//   Level 2 => Column 113~120
Fill_Block(0x38,0x3B,0x00,0x3F,0x11);


//   Level 1 => Column 121~128
Fill_Block(0x3C,0x3F,0x00,0x3F,0x00);
}


/*****************************************************************
    主程序
**************************************************************/
void main()
{
_nop_();
oled_init();
while(1){
 hanzi8(0,16,0,16);hanzi16(16,0,0,4);
 hanzi816(0,24,0,2);
 hanzi8(0,40,16,31);
     delay(5000);


Vertical_scroll(0);
Vertical_scroll(1);
Deactivate_Scroll();


Horizontal_Scroll(0x01,0x40,0x00,5000);             // Rightward
Horizontal_Scroll(0x3f,0x40,0x00,5000);            // Leftward
Deactivate_Scroll();


all_screen(0xf0); delay(1000);
all_screen(0xFF); delay(1000);
all_screen(0x0f); delay(1000);
all_screen(0x00);delay(10);
}
}