- IC型号
企业档案
- 相关证件: 
- 会员类型:
- 会员年限:12年
- 阿库IM:
- 地址:杭州市余杭区仁和街道永泰路2号22幢
- E-mail:752574498@qq.com
HGS2561281参考程序
发布时间: 2016/9/23 13:26:43 | 743 次阅读
#include<reg51.h>
#include<intrins.h>
#include<string.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define I80 /* I80(Intel8080) 、SPI4线(串口) 、SPI3线(串口) */
//#define SPI4
//#define SPI3
#ifdef I80 //Inter8080接口定义
#define data P0
sbit DC = P3^1;
sbit WR1 = P2^6;
sbit RD1 = P3^3;
sbit CS1 = P3^4;
sbit CS2 = P3^5;
sbit REST = P3^6;
sbit BS0 = P3^7;
sbit BS1 = P2^0;
#endif
#ifdef SPI4 //SPI4线接口定义
#define data P0
sbit SCLK = P0^0;
sbit SDI = P0^1;
sbit DC = P3^1;
sbit WR1 = P2^6;
sbit RD1 = P3^3;
sbit CS1 = P3^4;
sbit CS2 = P3^5;
sbit REST = P3^6;
sbit BS0 = P3^7;
sbit BS1 = P2^0;
#endif
#ifdef SPI3 //SPI3线接口定义
#define data P0
sbit SCLK = P0^0;
sbit SDI = P0^1;
sbit DC = P3^1;
sbit WR1 = P2^6;
sbit RD1 = P3^3;
sbit CS1 = P3^4;
sbit CS2 = P3^5;
sbit REST = P3^6;
sbit BS0 = P3^7;
sbit BS1 = P2^0;
#endif
#define WD 256 /* 显示区宽度 */
#define HD 128 /* 显示区高度 */
#define clear 0x00 /* Clear Display */
#define time 750 /* 1000延时 1.03895500 s */
/******** 西文字符库 *******/
/*--
提取点阵方向:横向(先左->右, 再上->下)
--*/
uchar code CTAB[][16]={
/*-- 文字: O --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
/*-- 文字: L --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xFE,0x00,0x00,
/*-- 文字: E --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x40,0x7C,0x40,0x40,0x40,0x40,0x7E,0x00,0x00,
/*-- 文字: D --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0xF8,0x84,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x84,0xF8,0x00,0x00,
/*-- 文字: 2 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x40,0x7E,0x00,0x00,
/*-- 文字: 5 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x7E,0x40,0x40,0x7C,0x42,0x02,0x02,0x02,0x42,0x42,0x3C,0x00,0x00,
/*-- 文字: 6 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x1C,0x22,0x42,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00,
/*-- 文字: * --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x10,0x10,0xD6,0x38,0x38,0xD6,0x10,0x10,0x00,0x00,0x00,0x00,
/*-- 文字: 1 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x30,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: 2 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x40,0x7E,0x00,0x00,
/*-- 文字: 8 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x22,0x1C,0x22,0x41,0x41,0x22,0x1C,0x00,0x00,
/*-- 文字: --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: d --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: o --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x44,0x38,0x00,0x00,
/*-- 文字: t --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x7E,0x10,0x10,0x10,0x10,0x10,0x0E,0x00,0x00,
};
uchar code CTAB2[][16]={
/*-- 文字: w --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x92,0x92,0xAA,0xAA,0xAA,0x44,0x44,0x00,0x00,
/*-- 文字: w --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x92,0x92,0xAA,0xAA,0xAA,0x44,0x44,0x00,0x00,
/*-- 文字: w --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x92,0x92,0xAA,0xAA,0xAA,0x44,0x44,0x00,0x00,
/*-- 文字: . --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,
/*-- 文字: c --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x80,0x80,0x80,0x42,0x3C,0x00,0x00,
/*-- 文字: h --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x42,0x42,0x00,0x00,
/*-- 文字: i --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x10,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: n --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5C,0x62,0x42,0x42,0x42,0x42,0x42,0x00,0x00,
/*-- 文字: a --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x02,0x3E,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: l --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: c --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x80,0x80,0x80,0x42,0x3C,0x00,0x00,
/*-- 文字: d --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: m --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x92,0x92,0x92,0x92,0x92,0x92,0x00,0x00,
/*-- 文字: o --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x44,0x38,0x00,0x00,
/*-- 文字: d --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: u --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x42,0x42,0x42,0x42,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: l --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: e --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x82,0xFE,0x80,0x42,0x3C,0x00,0x00,
/*-- 文字: . --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,
/*-- 文字: c --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x80,0x80,0x80,0x42,0x3C,0x00,0x00,
/*-- 文字: o --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x44,0x38,0x00,0x00,
/*-- 文字: m --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x92,0x92,0x92,0x92,0x92,0x92,0x00,0x00,
};
/******** 中文字符库 *******/
/*--
提取点阵方向:横向(先左->右, 再上->下)
--*/
uchar code CCTAB[][32]={
/*-- 文字: 杭 --*/
/*-- 楷体_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x00,0x10,0x40,0x10,0x20,0x10,0x00,0x1C,0x78,0x73,0x80,0x10,0x00,0x18,0xE0,
0x35,0x20,0x51,0x20,0x91,0x22,0x11,0x22,0x12,0x1E,0x14,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 州 --*/
/*-- 楷体_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x08,0x08,0x88,0x08,0x88,0x08,0x88,0x2A,0xC8,0x2A,0xA8,0x2A,0xA8,
0x48,0x88,0x08,0x88,0x10,0x88,0x10,0x88,0x20,0x08,0x40,0x08,0x00,0x00,0x00,0x00,
/*-- 文字: 清 --*/
/*-- 楷体_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,
/*-- 文字: 显 --*/
/*-- 楷体_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--);
}
#ifdef I80
/******** 写“指令”程序 ********/
void write_com1(uchar com) //上半屏
{
CS1=0;CS2=1;
DC=0;
RD1=1;
data=com;
WR1=0;
WR1=1;
CS1=1;CS2=1;
}
void write_com2(uchar com) //下半屏
{
CS1=1;CS2=0;
DC=0;
RD1=1;
data=com;
WR1=0;
WR1=1;
CS1=1;CS2=1;
}
/******** 写“数据”程序 ********/
void write_data1(uchar dat) //上半屏
{
CS1=0;CS2=1;
DC=1;
RD1=1;
data=dat;
WR1=0;
WR1=1;
CS1=1;CS2=1;
}
void write_data2(uchar dat) //下半屏
{
CS1=1;CS2=0;
DC=1;
RD1=1;
data=dat;
WR1=0;
WR1=1;
CS1=1;CS2=1;
}
/******** 读“数据”程序 ********/
uchar read_data1(void) //上半屏
{ uchar temp;
data=0xff;
CS1=0;CS2=1;
DC=1;
WR1=1;
RD1=0;
temp=data;
RD1=1;
CS1=1;CS2=1;
return temp;
}
uchar read_data2(void) //下半屏
{ uchar temp;
data=0xff;
CS1=1;CS2=0;
DC=1;
WR1=1;
RD1=0;
temp=data;
RD1=1;
CS1=1;CS2=1;
return temp;
}
#endif
#ifdef SPI4
/******** 写“8bit”程序 ********/
void write_8bit(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
dat<<=1;
SDI=CY;
SCLK=0;
SCLK=1;
}
}
/******** 写“指令”程序 ********/
void write_com1(uchar com) //上半屏
{
CS1=0;CS2=1;
DC=0;
write_8bit(com);
CS1=1;CS2=1;
}
void write_com2(uchar com) //下半屏
{
CS1=1;CS2=0;
DC=0;
write_8bit(com);
CS1=1;CS2=1;
}
/******** 写“数据”程序 ********/
void write_data1(uchar dat) //上半屏
{
CS1=0;CS2=1;
DC=1;
write_8bit(dat);
CS1=1;CS2=1;
}
void write_data2(uchar dat) //下半屏
{
CS1=1;CS2=0;
DC=1;
write_8bit(dat);
CS1=1;CS2=1;
}
#endif
#ifdef SPI3
/******** 写“8bit”程序 ********/
void write_8bit(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
dat<<=1;
SDI=CY;
SCLK=0;
SCLK=1;
}
}
/******** 写“指令”程序 ********/
void write_com1(uchar com) //上半屏
{
CS1=0;CS2=1;
SDI=0;
SCLK=0;
SCLK=1;
write_8bit(com);
CS1=1;CS2=1;
}
void write_com2(uchar com) //下半屏
{
CS1=1;CS2=0;
SDI=0;
SCLK=0;
SCLK=1;
write_8bit(com);
CS1=1;CS2=1;
}
/******** 写“数据”程序 ********/
void write_data1(uchar dat) //上半屏
{
CS1=0;CS2=1;
SDI=1;
SCLK=0;
SCLK=1;
write_8bit(dat);
CS1=1;CS2=1;
}
void write_data2(uchar dat) //下半屏
{
CS1=1;CS2=0;
SDI=1;
SCLK=0;
SCLK=1;
write_8bit(dat);
CS1=1;CS2=1;
}
#endif
/******** 窗口设置程序 ********/
void window(uchar row0,uchar row1,uint col0,uint col1)
{
if(row0<HD/2 && row1<HD/2) //上半屏
{
write_com1(0x15);
write_data1(0x1c+col0); //Column Start Address
write_data1(0x1c+col1); //Column End Address
write_com1(0x75);
write_data1(row0); //Row Start Address
write_data1(row1); //Row End Address
}
else
if(row0<HD/2 && row1>=HD/2) //上下半屏
{
write_com1(0x15);
write_data1(0x1c+col0); //Column Start Address
write_data1(0x1c+col1); //Column End Address
write_com1(0x75);
write_data1(row0); //Row Start Address
write_data1(HD/2-1); //Row End Address
write_com2(0x15);
write_data2(0x1c+col0); //Column Start Address
write_data2(0x1c+col1); //Column End Address
write_com2(0x75);
write_data2(0); //Row Start Address
write_data2(row1-HD/2); //Row End Address
}
else
if(row0>=HD/2 && row1>=HD/2) //下半屏
{
write_com2(0x15);
write_data2(0x1c+col0); //Column Start Address
write_data2(0x1c+col1); //Column End Address
write_com2(0x75);
write_data2(row0-HD/2); //Row Start Address
write_data2(row1-HD/2); //Row End Address
}
}
/******** 全屏显示程序********/
void fill(uchar dat)
{
uchar i,j,temp1,temp2;
temp1=WD/4;
temp2=2*temp1; //输入2个8bit数,写入1个地址、控制4个点
window(0,HD-1,0,temp1-1); //窗口
write_com1(0x5c); //写指令
write_com2(0x5c); //写指令
for(i=0;i<HD;i++)
{
if(i<HD/2) //上半屏
for(j=0;j<temp2;j++)
write_data1(dat);
else //下半屏
for(j=0;j<temp2;j++)
write_data2(dat);
}
}
/******** 隔行隔点显示程序 ********/
void fill_jg(uchar dat1,uchar dat2)
{ uchar i,j,temp1,temp2;
temp1=WD/4;
temp2=2*temp1; //输入2个8bit数,写入1个地址、控制4个点
window(0,HD-1,0,temp1-1); //窗口
write_com1(0x5c); //写指令
write_com2(0x5c); //写指令
for(i=0;i<HD;i++)
{
if(i<HD/2) //上半屏
{ for(j=0;j<temp2;j++)
if(i%2==0)
write_data1(dat1);
else
write_data1(dat2);
}
else //下半屏
{ for(j=0;j<temp2;j++)
if(i%2==0)
write_data2(dat1);
else
write_data2(dat2);
}
}
}
/******** 数据转换显示程序 ********/
void conv_write(uchar dat,uchar n,uchar row)
{
uchar i,j,temp[4];
for(i=0;i<n/2;i++)
{
switch(dat&0xc0)
{
case 0x00: temp[i]=0x00; break;
case 0x40: temp[i]=0x0f; break;
case 0x80: temp[i]=0xf0; break;
case 0xc0: temp[i]=0xff; break;
default: break;
}
dat<<=2; //左移2位
}
if(row<HD/2) //上半屏
for(i=0;i<n/2;i++)
write_data1(temp[i]); //写入转换后的8bit数据
else //下半屏
for(i=0;i<n/2;i++)
write_data2(temp[i]); //写入转换后的8bit数据
}
/******** 字符显示程序 ********/
/* 取模方式:横向(先左->右, 再上->下) */
void chhzes(uchar x,uchar y,uchar m,uchar n,uchar kk,uchar *s)
{
uchar i,j,k,temp,sum=0;
temp=n/8; //计算8bit转换次数,即每行有多少个8bit数需要转换
for(k=y;k<WD/4&&sum<kk;k+=n/4,sum++)
{
window(x,x+m-1,k,k+n/4-1); //窗口
write_com1(0x5c); //写指令
write_com2(0x5c); //写指令
for(i=0;i<m;i++)
for(j=0;j<temp;j++)
{
if(n%8==0)
{ conv_write(*s++,8,x+i);} //写入转换后的8bit数据
else
if(j<temp-1)
conv_write(*s++,8,x+i);
else
conv_write(*s++,n%8,x+i);
}
}
}
/******** 初始化程序 ********/
void set()
{/* 此处空格必须 */
#ifdef I80
BS0=0; BS1=1;
#endif
#ifdef SPI4
BS0=0; BS1=0; data=0x00; WR1=0;RD1=1;
#endif
#ifdef SPI3
BS0=1; BS1=0; data=0x00; WR1=0;RD1=1;
#endif
delay(15);
REST=0;
delay(1);
REST=1;
delay(150);
/************* 上半屏初始化 *************/
// 准备接受命令;
write_com1(0xFD);
write_data1(0x12); /* 12H接受,16H拒绝 */
//休眠开关;
write_com1(0xAE); /* AEH开休眠,AF关休眠 */
// 设置列窗口;
write_com1(0x15);
write_data1(0x1c);
write_data1(0x5b); /*256列 */
//设置行窗口;
write_com1(0x75);
write_data1(0x00);
write_data1(0x3f); /*64行 */
// 设置可逆地图;
write_com1(0xA0);
write_data1(0x04); /* 选高字节在前,COM扫描反向 ,水平地址模式 */
write_data1(0x11); //*/ /*选双屏模式 */
// 设置起始行;
write_com1(0xA1);
write_data1(0x00); /* 0 */
// 设置显示分支;
write_com1(0xA2);
write_data1(0x00); /* 无分支 */
// 设置显示模式;
write_com1(0xA6); /* A4H全关,A5H全开,A6H正常,A7H反显 */
// 设置反显;
write_com1(0xA6); /* 不反显 */
// 设置部分显示;
write_com1(0xA9); /* A8H进入部分显示,A9H退出 */
// Vdd来源;
write_com1(0xAB);
write_data1(0x01); /* 00H为外部,01H为内部 */
// 设置P1 P2 ;
write_com1(0xB1); /*P1=29,P2=7 */
write_data1(0xE7);
// 设置D和Fosc;
write_com1(0xB3);
write_data1(0xf1); /*F=9,D=1 */
// 设置显示质量和Vsl来源;
write_com1(0xB4);
write_data1(0xA0); /* A0H为外部Vsl,A2H为内部Vsl */
write_data1(0xfd); /*FDH为提高质量,B5H为正常 */
//设置GPIO;
write_com1(0xB5);
write_data1(0x00);
//设置Tp3
write_com1(0xB6);
write_data1(0x08);
//设置灰度值;
write_com1(0xB8);
write_data1(0x0c);
write_data1(0x18);
write_data1(0x24);
write_data1(0x30);
write_data1(0x3c);
write_data1(0x48);
write_data1(0x54);
write_data1(0x60);
write_data1(0x6c);
write_data1(0x78);
write_data1(0x84);
write_data1(0x90);
write_data1(0x9c);
write_data1(0xa8);
write_data1(0xb4);
//使能灰阶;
// write_com1(0x00);
//设置Vp2;
write_com1(0xBB);
write_data1(0x1F);
// 设置Vcomh;
write_com1(0xBE);
write_data1(0x07); /* Vcomh=0.86Vcc */
//设置对比度;
write_com1(0xC1);
write_data1(0x7F); /* 共256级选第128级 */
//设置SEG电流范围;
write_com1(0xC7);
write_data1(0x0F); /* 满范围 */
//设置显示行;
write_com1(0xCA);
write_data1(0x3F); /* 64 */
//设置显示质量;
write_com1(0xD1);
write_data1(0xA2);
write_data1(0x20);
write_com1(0xAF); /* 开显示 */
/************* 下半屏初始化 *************/
// 准备接受命令;
write_com2(0xFD);
write_data2(0x12); /* 12H接受,16H拒绝 */
//休眠开关;
write_com2(0xAE); /* AEH开休眠,AF关休眠 */
// 设置列窗口;
write_com2(0x15);
write_data2(0x1c);
write_data2(0x5b); /*256列 */
//设置行窗口;
write_com2(0x75);
write_data2(0x00);
write_data2(0x3f); /*64行 */
// 设置可逆地图;
write_com2(0xA0);
write_data2(0x16); /* 选高字节在前,COM扫描反向 ,水平地址模式 */
write_data2(0x11); /*选双屏模式 */
// 设置起始行;
write_com2(0xA1);
write_data2(0x00); /* 0 */
// 设置显示分支;
write_com2(0xA2);
write_data2(0x00); /* 无分支 */
// 设置显示模式;
write_com2(0xA6); /* A4H全关,A5H全开,A6H正常,A7H反显 */
// 设置反显;
write_com2(0xA6); /* 不反显 */
// 设置部分显示;
write_com2(0xA9); /* A8H进入部分显示,A9H退出 */
// Vdd来源;
write_com2(0xAB);
write_data2(0x01); /* 00H为外部,01H为内部 */
// 设置P1 P2 ;
write_com2(0xB1); /*P1=29,P2=7 */
write_data2(0xE7);
// 设置D和Fosc;
write_com2(0xB3);
write_data2(0xf1); /*F=9,D=1 */
// 设置显示质量和Vsl来源;
write_com2(0xB4);
write_data2(0xA0); /* A0H为外部Vsl,A2H为内部Vsl */
write_data2(0xfd); /*FDH为提高质量,B5H为正常 */
//设置GPIO;
write_com2(0xB5);
write_data2(0x00);
//设置Tp3
write_com2(0xB6);
write_data2(0x08);
//设置灰度值;
write_com2(0xB8);
write_data2(0x0c);
write_data2(0x18);
write_data2(0x24);
write_data2(0x30);
write_data2(0x3c);
write_data2(0x48);
write_data2(0x54);
write_data2(0x60);
write_data2(0x6c);
write_data2(0x78);
write_data2(0x84);
write_data2(0x90);
write_data2(0x9c);
write_data2(0xa8);
write_data2(0xb4);
//使能灰阶;
// write_com2(0x00);
//设置Vp2;
write_com2(0xBB);
write_data2(0x1F);
// 设置Vcomh;
write_com2(0xBE);
write_data2(0x07); /* Vcomh=0.86Vcc */
//设置对比度;
write_com2(0xC1);
write_data2(0x7F); /* 共256级选第128级 */
//设置SEG电流范围;
write_com2(0xC7);
write_data2(0x0F); /* 满范围 */
//设置显示行;
write_com2(0xCA);
write_data2(0x3F); /* 64 */
//设置显示质量;
write_com2(0xD1);
write_data2(0xA2);
write_data2(0x20);
write_com2(0xAF); /* 开显示 */
}
/********* 主函数 *********/
void main()
{
set();
while(1)
{
fill(clear); //清屏
chhzes(4,8,16,16,12,CCTAB); //杭州清达光电技术有限公司
chhzes(20,20,16,8,4,CTAB); //OLED
chhzes(20,28,16,16,4,CCTAB+12); //显示模块
chhzes(36,21,16,8,11,CTAB+4); //256*128 dot
chhzes(56,0,16,16,16,CCTAB); //杭州清达光电技术有限公司显示模块
chhzes(76,28,16,8,4,CTAB); //OLED
chhzes(92,10,16,8,22,CTAB2); //www.chinalcdmodule.com
delay(2*time);//*/
}
}
#include<intrins.h>
#include<string.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define I80 /* I80(Intel8080) 、SPI4线(串口) 、SPI3线(串口) */
//#define SPI4
//#define SPI3
#ifdef I80 //Inter8080接口定义
#define data P0
sbit DC = P3^1;
sbit WR1 = P2^6;
sbit RD1 = P3^3;
sbit CS1 = P3^4;
sbit CS2 = P3^5;
sbit REST = P3^6;
sbit BS0 = P3^7;
sbit BS1 = P2^0;
#endif
#ifdef SPI4 //SPI4线接口定义
#define data P0
sbit SCLK = P0^0;
sbit SDI = P0^1;
sbit DC = P3^1;
sbit WR1 = P2^6;
sbit RD1 = P3^3;
sbit CS1 = P3^4;
sbit CS2 = P3^5;
sbit REST = P3^6;
sbit BS0 = P3^7;
sbit BS1 = P2^0;
#endif
#ifdef SPI3 //SPI3线接口定义
#define data P0
sbit SCLK = P0^0;
sbit SDI = P0^1;
sbit DC = P3^1;
sbit WR1 = P2^6;
sbit RD1 = P3^3;
sbit CS1 = P3^4;
sbit CS2 = P3^5;
sbit REST = P3^6;
sbit BS0 = P3^7;
sbit BS1 = P2^0;
#endif
#define WD 256 /* 显示区宽度 */
#define HD 128 /* 显示区高度 */
#define clear 0x00 /* Clear Display */
#define time 750 /* 1000延时 1.03895500 s */
/******** 西文字符库 *******/
/*--
提取点阵方向:横向(先左->右, 再上->下)
--*/
uchar code CTAB[][16]={
/*-- 文字: O --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
/*-- 文字: L --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xFE,0x00,0x00,
/*-- 文字: E --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x40,0x7C,0x40,0x40,0x40,0x40,0x7E,0x00,0x00,
/*-- 文字: D --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0xF8,0x84,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x84,0xF8,0x00,0x00,
/*-- 文字: 2 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x40,0x7E,0x00,0x00,
/*-- 文字: 5 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x7E,0x40,0x40,0x7C,0x42,0x02,0x02,0x02,0x42,0x42,0x3C,0x00,0x00,
/*-- 文字: 6 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x1C,0x22,0x42,0x40,0x5C,0x62,0x42,0x42,0x42,0x22,0x1C,0x00,0x00,
/*-- 文字: * --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x10,0x10,0xD6,0x38,0x38,0xD6,0x10,0x10,0x00,0x00,0x00,0x00,
/*-- 文字: 1 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x30,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: 2 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x02,0x04,0x08,0x10,0x20,0x40,0x7E,0x00,0x00,
/*-- 文字: 8 --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x22,0x1C,0x22,0x41,0x41,0x22,0x1C,0x00,0x00,
/*-- 文字: --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: d --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: o --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x44,0x38,0x00,0x00,
/*-- 文字: t --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x7E,0x10,0x10,0x10,0x10,0x10,0x0E,0x00,0x00,
};
uchar code CTAB2[][16]={
/*-- 文字: w --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x92,0x92,0xAA,0xAA,0xAA,0x44,0x44,0x00,0x00,
/*-- 文字: w --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x92,0x92,0xAA,0xAA,0xAA,0x44,0x44,0x00,0x00,
/*-- 文字: w --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x92,0x92,0xAA,0xAA,0xAA,0x44,0x44,0x00,0x00,
/*-- 文字: . --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,
/*-- 文字: c --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x80,0x80,0x80,0x42,0x3C,0x00,0x00,
/*-- 文字: h --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x42,0x42,0x00,0x00,
/*-- 文字: i --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x10,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: n --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5C,0x62,0x42,0x42,0x42,0x42,0x42,0x00,0x00,
/*-- 文字: a --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x02,0x3E,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: l --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: c --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x80,0x80,0x80,0x42,0x3C,0x00,0x00,
/*-- 文字: d --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: m --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x92,0x92,0x92,0x92,0x92,0x92,0x00,0x00,
/*-- 文字: o --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x44,0x38,0x00,0x00,
/*-- 文字: d --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: u --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x42,0x42,0x42,0x42,0x42,0x46,0x3A,0x00,0x00,
/*-- 文字: l --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
/*-- 文字: e --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x82,0xFE,0x80,0x42,0x3C,0x00,0x00,
/*-- 文字: . --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,
/*-- 文字: c --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x80,0x80,0x80,0x42,0x3C,0x00,0x00,
/*-- 文字: o --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x44,0x38,0x00,0x00,
/*-- 文字: m --*/
/*-- 黑体12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x92,0x92,0x92,0x92,0x92,0x92,0x00,0x00,
};
/******** 中文字符库 *******/
/*--
提取点阵方向:横向(先左->右, 再上->下)
--*/
uchar code CCTAB[][32]={
/*-- 文字: 杭 --*/
/*-- 楷体_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x00,0x10,0x40,0x10,0x20,0x10,0x00,0x1C,0x78,0x73,0x80,0x10,0x00,0x18,0xE0,
0x35,0x20,0x51,0x20,0x91,0x22,0x11,0x22,0x12,0x1E,0x14,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 州 --*/
/*-- 楷体_GB231212; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x08,0x08,0x88,0x08,0x88,0x08,0x88,0x2A,0xC8,0x2A,0xA8,0x2A,0xA8,
0x48,0x88,0x08,0x88,0x10,0x88,0x10,0x88,0x20,0x08,0x40,0x08,0x00,0x00,0x00,0x00,
/*-- 文字: 清 --*/
/*-- 楷体_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,
/*-- 文字: 显 --*/
/*-- 楷体_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--);
}
#ifdef I80
/******** 写“指令”程序 ********/
void write_com1(uchar com) //上半屏
{
CS1=0;CS2=1;
DC=0;
RD1=1;
data=com;
WR1=0;
WR1=1;
CS1=1;CS2=1;
}
void write_com2(uchar com) //下半屏
{
CS1=1;CS2=0;
DC=0;
RD1=1;
data=com;
WR1=0;
WR1=1;
CS1=1;CS2=1;
}
/******** 写“数据”程序 ********/
void write_data1(uchar dat) //上半屏
{
CS1=0;CS2=1;
DC=1;
RD1=1;
data=dat;
WR1=0;
WR1=1;
CS1=1;CS2=1;
}
void write_data2(uchar dat) //下半屏
{
CS1=1;CS2=0;
DC=1;
RD1=1;
data=dat;
WR1=0;
WR1=1;
CS1=1;CS2=1;
}
/******** 读“数据”程序 ********/
uchar read_data1(void) //上半屏
{ uchar temp;
data=0xff;
CS1=0;CS2=1;
DC=1;
WR1=1;
RD1=0;
temp=data;
RD1=1;
CS1=1;CS2=1;
return temp;
}
uchar read_data2(void) //下半屏
{ uchar temp;
data=0xff;
CS1=1;CS2=0;
DC=1;
WR1=1;
RD1=0;
temp=data;
RD1=1;
CS1=1;CS2=1;
return temp;
}
#endif
#ifdef SPI4
/******** 写“8bit”程序 ********/
void write_8bit(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
dat<<=1;
SDI=CY;
SCLK=0;
SCLK=1;
}
}
/******** 写“指令”程序 ********/
void write_com1(uchar com) //上半屏
{
CS1=0;CS2=1;
DC=0;
write_8bit(com);
CS1=1;CS2=1;
}
void write_com2(uchar com) //下半屏
{
CS1=1;CS2=0;
DC=0;
write_8bit(com);
CS1=1;CS2=1;
}
/******** 写“数据”程序 ********/
void write_data1(uchar dat) //上半屏
{
CS1=0;CS2=1;
DC=1;
write_8bit(dat);
CS1=1;CS2=1;
}
void write_data2(uchar dat) //下半屏
{
CS1=1;CS2=0;
DC=1;
write_8bit(dat);
CS1=1;CS2=1;
}
#endif
#ifdef SPI3
/******** 写“8bit”程序 ********/
void write_8bit(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
dat<<=1;
SDI=CY;
SCLK=0;
SCLK=1;
}
}
/******** 写“指令”程序 ********/
void write_com1(uchar com) //上半屏
{
CS1=0;CS2=1;
SDI=0;
SCLK=0;
SCLK=1;
write_8bit(com);
CS1=1;CS2=1;
}
void write_com2(uchar com) //下半屏
{
CS1=1;CS2=0;
SDI=0;
SCLK=0;
SCLK=1;
write_8bit(com);
CS1=1;CS2=1;
}
/******** 写“数据”程序 ********/
void write_data1(uchar dat) //上半屏
{
CS1=0;CS2=1;
SDI=1;
SCLK=0;
SCLK=1;
write_8bit(dat);
CS1=1;CS2=1;
}
void write_data2(uchar dat) //下半屏
{
CS1=1;CS2=0;
SDI=1;
SCLK=0;
SCLK=1;
write_8bit(dat);
CS1=1;CS2=1;
}
#endif
/******** 窗口设置程序 ********/
void window(uchar row0,uchar row1,uint col0,uint col1)
{
if(row0<HD/2 && row1<HD/2) //上半屏
{
write_com1(0x15);
write_data1(0x1c+col0); //Column Start Address
write_data1(0x1c+col1); //Column End Address
write_com1(0x75);
write_data1(row0); //Row Start Address
write_data1(row1); //Row End Address
}
else
if(row0<HD/2 && row1>=HD/2) //上下半屏
{
write_com1(0x15);
write_data1(0x1c+col0); //Column Start Address
write_data1(0x1c+col1); //Column End Address
write_com1(0x75);
write_data1(row0); //Row Start Address
write_data1(HD/2-1); //Row End Address
write_com2(0x15);
write_data2(0x1c+col0); //Column Start Address
write_data2(0x1c+col1); //Column End Address
write_com2(0x75);
write_data2(0); //Row Start Address
write_data2(row1-HD/2); //Row End Address
}
else
if(row0>=HD/2 && row1>=HD/2) //下半屏
{
write_com2(0x15);
write_data2(0x1c+col0); //Column Start Address
write_data2(0x1c+col1); //Column End Address
write_com2(0x75);
write_data2(row0-HD/2); //Row Start Address
write_data2(row1-HD/2); //Row End Address
}
}
/******** 全屏显示程序********/
void fill(uchar dat)
{
uchar i,j,temp1,temp2;
temp1=WD/4;
temp2=2*temp1; //输入2个8bit数,写入1个地址、控制4个点
window(0,HD-1,0,temp1-1); //窗口
write_com1(0x5c); //写指令
write_com2(0x5c); //写指令
for(i=0;i<HD;i++)
{
if(i<HD/2) //上半屏
for(j=0;j<temp2;j++)
write_data1(dat);
else //下半屏
for(j=0;j<temp2;j++)
write_data2(dat);
}
}
/******** 隔行隔点显示程序 ********/
void fill_jg(uchar dat1,uchar dat2)
{ uchar i,j,temp1,temp2;
temp1=WD/4;
temp2=2*temp1; //输入2个8bit数,写入1个地址、控制4个点
window(0,HD-1,0,temp1-1); //窗口
write_com1(0x5c); //写指令
write_com2(0x5c); //写指令
for(i=0;i<HD;i++)
{
if(i<HD/2) //上半屏
{ for(j=0;j<temp2;j++)
if(i%2==0)
write_data1(dat1);
else
write_data1(dat2);
}
else //下半屏
{ for(j=0;j<temp2;j++)
if(i%2==0)
write_data2(dat1);
else
write_data2(dat2);
}
}
}
/******** 数据转换显示程序 ********/
void conv_write(uchar dat,uchar n,uchar row)
{
uchar i,j,temp[4];
for(i=0;i<n/2;i++)
{
switch(dat&0xc0)
{
case 0x00: temp[i]=0x00; break;
case 0x40: temp[i]=0x0f; break;
case 0x80: temp[i]=0xf0; break;
case 0xc0: temp[i]=0xff; break;
default: break;
}
dat<<=2; //左移2位
}
if(row<HD/2) //上半屏
for(i=0;i<n/2;i++)
write_data1(temp[i]); //写入转换后的8bit数据
else //下半屏
for(i=0;i<n/2;i++)
write_data2(temp[i]); //写入转换后的8bit数据
}
/******** 字符显示程序 ********/
/* 取模方式:横向(先左->右, 再上->下) */
void chhzes(uchar x,uchar y,uchar m,uchar n,uchar kk,uchar *s)
{
uchar i,j,k,temp,sum=0;
temp=n/8; //计算8bit转换次数,即每行有多少个8bit数需要转换
for(k=y;k<WD/4&&sum<kk;k+=n/4,sum++)
{
window(x,x+m-1,k,k+n/4-1); //窗口
write_com1(0x5c); //写指令
write_com2(0x5c); //写指令
for(i=0;i<m;i++)
for(j=0;j<temp;j++)
{
if(n%8==0)
{ conv_write(*s++,8,x+i);} //写入转换后的8bit数据
else
if(j<temp-1)
conv_write(*s++,8,x+i);
else
conv_write(*s++,n%8,x+i);
}
}
}
/******** 初始化程序 ********/
void set()
{/* 此处空格必须 */
#ifdef I80
BS0=0; BS1=1;
#endif
#ifdef SPI4
BS0=0; BS1=0; data=0x00; WR1=0;RD1=1;
#endif
#ifdef SPI3
BS0=1; BS1=0; data=0x00; WR1=0;RD1=1;
#endif
delay(15);
REST=0;
delay(1);
REST=1;
delay(150);
/************* 上半屏初始化 *************/
// 准备接受命令;
write_com1(0xFD);
write_data1(0x12); /* 12H接受,16H拒绝 */
//休眠开关;
write_com1(0xAE); /* AEH开休眠,AF关休眠 */
// 设置列窗口;
write_com1(0x15);
write_data1(0x1c);
write_data1(0x5b); /*256列 */
//设置行窗口;
write_com1(0x75);
write_data1(0x00);
write_data1(0x3f); /*64行 */
// 设置可逆地图;
write_com1(0xA0);
write_data1(0x04); /* 选高字节在前,COM扫描反向 ,水平地址模式 */
write_data1(0x11); //*/ /*选双屏模式 */
// 设置起始行;
write_com1(0xA1);
write_data1(0x00); /* 0 */
// 设置显示分支;
write_com1(0xA2);
write_data1(0x00); /* 无分支 */
// 设置显示模式;
write_com1(0xA6); /* A4H全关,A5H全开,A6H正常,A7H反显 */
// 设置反显;
write_com1(0xA6); /* 不反显 */
// 设置部分显示;
write_com1(0xA9); /* A8H进入部分显示,A9H退出 */
// Vdd来源;
write_com1(0xAB);
write_data1(0x01); /* 00H为外部,01H为内部 */
// 设置P1 P2 ;
write_com1(0xB1); /*P1=29,P2=7 */
write_data1(0xE7);
// 设置D和Fosc;
write_com1(0xB3);
write_data1(0xf1); /*F=9,D=1 */
// 设置显示质量和Vsl来源;
write_com1(0xB4);
write_data1(0xA0); /* A0H为外部Vsl,A2H为内部Vsl */
write_data1(0xfd); /*FDH为提高质量,B5H为正常 */
//设置GPIO;
write_com1(0xB5);
write_data1(0x00);
//设置Tp3
write_com1(0xB6);
write_data1(0x08);
//设置灰度值;
write_com1(0xB8);
write_data1(0x0c);
write_data1(0x18);
write_data1(0x24);
write_data1(0x30);
write_data1(0x3c);
write_data1(0x48);
write_data1(0x54);
write_data1(0x60);
write_data1(0x6c);
write_data1(0x78);
write_data1(0x84);
write_data1(0x90);
write_data1(0x9c);
write_data1(0xa8);
write_data1(0xb4);
//使能灰阶;
// write_com1(0x00);
//设置Vp2;
write_com1(0xBB);
write_data1(0x1F);
// 设置Vcomh;
write_com1(0xBE);
write_data1(0x07); /* Vcomh=0.86Vcc */
//设置对比度;
write_com1(0xC1);
write_data1(0x7F); /* 共256级选第128级 */
//设置SEG电流范围;
write_com1(0xC7);
write_data1(0x0F); /* 满范围 */
//设置显示行;
write_com1(0xCA);
write_data1(0x3F); /* 64 */
//设置显示质量;
write_com1(0xD1);
write_data1(0xA2);
write_data1(0x20);
write_com1(0xAF); /* 开显示 */
/************* 下半屏初始化 *************/
// 准备接受命令;
write_com2(0xFD);
write_data2(0x12); /* 12H接受,16H拒绝 */
//休眠开关;
write_com2(0xAE); /* AEH开休眠,AF关休眠 */
// 设置列窗口;
write_com2(0x15);
write_data2(0x1c);
write_data2(0x5b); /*256列 */
//设置行窗口;
write_com2(0x75);
write_data2(0x00);
write_data2(0x3f); /*64行 */
// 设置可逆地图;
write_com2(0xA0);
write_data2(0x16); /* 选高字节在前,COM扫描反向 ,水平地址模式 */
write_data2(0x11); /*选双屏模式 */
// 设置起始行;
write_com2(0xA1);
write_data2(0x00); /* 0 */
// 设置显示分支;
write_com2(0xA2);
write_data2(0x00); /* 无分支 */
// 设置显示模式;
write_com2(0xA6); /* A4H全关,A5H全开,A6H正常,A7H反显 */
// 设置反显;
write_com2(0xA6); /* 不反显 */
// 设置部分显示;
write_com2(0xA9); /* A8H进入部分显示,A9H退出 */
// Vdd来源;
write_com2(0xAB);
write_data2(0x01); /* 00H为外部,01H为内部 */
// 设置P1 P2 ;
write_com2(0xB1); /*P1=29,P2=7 */
write_data2(0xE7);
// 设置D和Fosc;
write_com2(0xB3);
write_data2(0xf1); /*F=9,D=1 */
// 设置显示质量和Vsl来源;
write_com2(0xB4);
write_data2(0xA0); /* A0H为外部Vsl,A2H为内部Vsl */
write_data2(0xfd); /*FDH为提高质量,B5H为正常 */
//设置GPIO;
write_com2(0xB5);
write_data2(0x00);
//设置Tp3
write_com2(0xB6);
write_data2(0x08);
//设置灰度值;
write_com2(0xB8);
write_data2(0x0c);
write_data2(0x18);
write_data2(0x24);
write_data2(0x30);
write_data2(0x3c);
write_data2(0x48);
write_data2(0x54);
write_data2(0x60);
write_data2(0x6c);
write_data2(0x78);
write_data2(0x84);
write_data2(0x90);
write_data2(0x9c);
write_data2(0xa8);
write_data2(0xb4);
//使能灰阶;
// write_com2(0x00);
//设置Vp2;
write_com2(0xBB);
write_data2(0x1F);
// 设置Vcomh;
write_com2(0xBE);
write_data2(0x07); /* Vcomh=0.86Vcc */
//设置对比度;
write_com2(0xC1);
write_data2(0x7F); /* 共256级选第128级 */
//设置SEG电流范围;
write_com2(0xC7);
write_data2(0x0F); /* 满范围 */
//设置显示行;
write_com2(0xCA);
write_data2(0x3F); /* 64 */
//设置显示质量;
write_com2(0xD1);
write_data2(0xA2);
write_data2(0x20);
write_com2(0xAF); /* 开显示 */
}
/********* 主函数 *********/
void main()
{
set();
while(1)
{
fill(clear); //清屏
chhzes(4,8,16,16,12,CCTAB); //杭州清达光电技术有限公司
chhzes(20,20,16,8,4,CTAB); //OLED
chhzes(20,28,16,16,4,CCTAB+12); //显示模块
chhzes(36,21,16,8,11,CTAB+4); //256*128 dot
chhzes(56,0,16,16,16,CCTAB); //杭州清达光电技术有限公司显示模块
chhzes(76,28,16,8,4,CTAB); //OLED
chhzes(92,10,16,8,22,CTAB2); //www.chinalcdmodule.com
delay(2*time);//*/
}
}
上一篇:HG192641V4测试程序
下一篇:HGS128641参考程序