- IC型号
企业档案
- 相关证件:
 
- 会员类型:
- 会员年限:12年
- 阿库IM:
- 地址:杭州市余杭区仁和街道永泰路2号22幢
- E-mail:752574498@qq.com
HCS1626测试程序
发布时间: 2018/9/4 13:35:34 | 1023 次阅读
HCS1626参考测试程序如下:
#include<reg51.h>
#include <string.h>
#include <intrins.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
#define P68
#define DATA P1
sbit CD = P3^3; //并行接口;
sbit WR1 = P3^1;
sbit RD1 = P3^0;
sbit SCL =P1^0; //I2C接口;
sbit SDA =P1^1;
sbit SCLK =P1^0; //SPI接口;
sbit SDIN =P1^1;
sbit SDOU =P1^2;
uchar code tab1[]={"Tsingtek-OLED"};
uchar code tab2[]={"HCS1624-Y-EH-I2C"};
uchar code CGR[]={
0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,//隔列1
0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,//隔行1
0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,//隔列2
0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,//隔行2
0xff};
//此程序测试于 24M 晶震,51单片机;
//注意,关与 IS RE SD这3位,起始时是000,我们每次用完命令之后也复位成000;
/******************************************************************
延时子程序
*****************************************************************/
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=124;y>0;y--);
}
void delay_100us(uchar z)
{
z=z*16;
while(z--);
}
/******************************************************************
写入指令和数据
*****************************************************************/
#ifdef P80
void wait(void) // 忙等待;
{
WR1=1; _nop_();
CD=0; _nop_();
RD1=0; _nop_();
while(DATA&0x80); _nop_();
RD1=1; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void wr_data(uchar b) //写数据 ;
{
wait(); _nop_();
RD1=1; _nop_();
CD=1; _nop_();
WR1=0; _nop_();
DATA=b; _nop_();
WR1=1; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void wr_com(uchar b) //写命令;
{
wait(); _nop_();
RD1=1; _nop_();
CD=0; _nop_();
WR1=0; _nop_();
DATA=b; _nop_();
WR1=1; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
uchar rd_data(void) //读数据 ;
{
uchar temp;
wait(); _nop_();
WR1=1; _nop_();
CD=1; _nop_();
DATA=0xff; _nop_();
RD1=0; _nop_();
temp=DATA; _nop_();
RD1=1; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
return temp;
}
#endif
/******************************************************************
写入指令和数据 ,都需要空读,SPI的已经空读好了;
*****************************************************************/
#ifdef P80_4
void wait(void) // 忙等待;
{
WR1=1; _nop_();
CD=0; _nop_();
RD1=0; _nop_();
while(DATA&0x80); _nop_();
RD1=1; _nop_();_nop_();
RD1=0; _nop_();_nop_();
RD1=1; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void wr_data(uchar b) //写数据 ;
{
uchar temp1,temp2;
temp1=b&0xf0;
temp2=b<<4;
wait(); _nop_();
RD1=1; _nop_();
CD=1; _nop_();
WR1=0; _nop_();
DATA=temp1; _nop_();
WR1=1; _nop_();_nop_();
WR1=0; _nop_();
DATA=temp2; _nop_();
WR1=1; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void wr_com(uchar b) //写数据 ;
{
uchar temp1,temp2;
temp1=b&0xf0;
temp2=b<<4;
wait(); _nop_();
RD1=1; _nop_();
CD=0; _nop_();
WR1=0; _nop_();
DATA=temp1; _nop_();
WR1=1; _nop_();_nop_();
WR1=0; _nop_();
DATA=temp2; _nop_();
WR1=1; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
uchar rd_data(void) //读数据 ;
{
uchar temp1,temp2,temp;
wait(); _nop_();
WR1=1; _nop_();
CD=1; _nop_();
DATA=0xff; _nop_();
RD1=0; _nop_();
temp1=DATA; _nop_();
RD1=1; _nop_();_nop_();
RD1=0; _nop_();
temp2=DATA; _nop_();
RD1=1; _nop_();_nop_();
temp=(temp1&0xf0)|(temp2>>4);
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
return temp;
}
#endif
/**/
#ifdef P68
void wait(void) // 忙等待;
{
RD1=0; _nop_();
CD=0; _nop_();
WR1=1; _nop_();
DATA=0xff; _nop_();
RD1=1; _nop_();
while(DATA&0x80); _nop_();
RD1=0; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void wr_data(uchar b) //写数据 ;
{
wait(); _nop_();
CD=1; _nop_();
WR1=0; _nop_();
DATA=b; _nop_();
RD1=1; _nop_();
RD1=0; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void wr_com(uchar b) //写命令;
{
wait(); _nop_();
CD=0; _nop_();
WR1=0; _nop_();
DATA=b; _nop_();
RD1=1; _nop_();
RD1=0; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
uchar rd_data(void) //读数据;
{
uchar temp;
wait(); _nop_();
CD=1; _nop_();
WR1=1; _nop_();
DATA=0xff; _nop_();
RD1=1; _nop_();
temp=DATA; _nop_();
RD1=0; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
return temp;
}
#endif
/**/
#ifdef P68_4
void wait(void) // 忙等待;
{
RD1=0; _nop_();
CD=0; _nop_();
WR1=1; _nop_();
DATA=0xff; _nop_();
RD1=1; _nop_();
while(DATA&0x80); _nop_();
RD1=0; _nop_();_nop_();
RD1=1; _nop_();_nop_();
RD1=0; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void wr_data(uchar b) //写数据 ;
{
uchar temp1,temp2;
temp1=b&0xf0;
temp2=b<<4;
wait(); _nop_();
CD=1; _nop_();
WR1=0; _nop_();
DATA=temp1; _nop_();
RD1=1; _nop_();
RD1=0; _nop_();_nop_();
DATA=temp2; _nop_();
RD1=1; _nop_();
RD1=0; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void wr_com(uchar b) //写数据 ;
{
uchar temp1,temp2;
temp1=b&0xf0;
temp2=b<<4;
wait(); _nop_();
CD=0; _nop_();
WR1=0; _nop_();
DATA=temp1; _nop_();
RD1=1; _nop_();
RD1=0; _nop_();_nop_();
DATA=temp2; _nop_();
RD1=1; _nop_();
RD1=0; _nop_();_nop_();
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
uchar rd_data(void) //读数据,需空读;
{
uchar temp1,temp2,temp;
wait(); _nop_();
CD=1; _nop_();
WR1=1; _nop_();
DATA=0xff; _nop_();
RD1=1; _nop_();
temp1=DATA; _nop_();
RD1=0; _nop_();_nop_();
RD1=1; _nop_();
temp2=DATA; _nop_();
RD1=0; _nop_();_nop_();
temp=(temp1&0xf0)|(temp2>>4);
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
return temp;
}
#endif
/**/
#ifdef SPI
void wait(void) // 忙等待;
{
_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();
}
void del(void)
{
_nop_();_nop_();
}
void wr_byte(uchar b)
{
uchar i;
for(i=0;i<8;i++)
{
SCLK=0;del();
SDIN=b&0x01;del();
b=b>>1;
SCLK=1;del();
}
}
uchar rd_byte(void)
{
uchar i,temp;
for(i=0;i<8;i++)
{
SCLK=0;del();
temp=temp>>1;
if(SDOU) temp|=0x80;
SCLK=1;del();
}
return temp;
}
void wr_data(uchar b) //写数据 ;
{
uchar temp1,temp2;
temp1=b&0x0f;
temp2=b>>4;
wr_byte(0x5f);
wr_byte(temp1);
wr_byte(temp2);
wait();
}
void wr_com(uchar b) //写命令;
{
uchar temp1,temp2;
temp1=b&0x0f;
temp2=b>>4;
wr_byte(0x1f);
wr_byte(temp1);
wr_byte(temp2);
wait();
}
uchar rd_data(void)
{
uchar temp;
wr_byte(0x7f); wait();
temp=rd_byte(); wait();//空读;
temp=rd_byte();wait();
return temp;
}
#endif
/**/
#ifdef I2C
void del(void)
{
_nop_(); _nop_();
}
void start(void)
{
SDA=1;del();
SCL=1;del();
SDA=0;del();
SCL=0;del();
}
void stop(void)
{
SDA=0;del();
SCL=1;del();
SDA=1;del();
}
void ack(void)
{
uchar i=0;
SCL=1;
//while((SDA==1)&&(i<200))i++;
del();
SCL=0;
del();
}
void wr_byte(uchar b)
{
uchar i;
for(i=0;i<8;i++)
{
SCL=0;del();
SDA=b&0x80;del();
b=b<<1;
SCL=1;del();
SCL=0;del();
}
SDA=1;del();
ack();
}
void wr_data(uchar b)
{
start();
wr_byte(0x78);
wr_byte(0x40);
wr_byte(b);
stop();
}
void wr_com(uchar com)
{
start();
wr_byte(0x78);
wr_byte(0x00);
wr_byte(com);
stop();
}
#endif
/******************************************************************
定位地址(一个地址对应5*8字符和)
x--> 水平方向地址数(0~39) ;y--> 垂直方向字符数(0~1);
*****************************************************************/
void dot(uchar x,uchar y)
{
if(y) x|=0x40;
x|=0x80;
wr_com(x);
}
/******************************************************************
清屏;
*****************************************************************/
void clear(void)
{
wr_com(0x01);delay(5);
}
/******************************************************************
字符的输入(5*8)
x--> 水平方向地址数(0~39) ;y--> 垂直方向字符数(0~1);s-->字符代码首地址;
*****************************************************************/
void en_c_r(uchar x,uchar y,uchar code * s)
{
dot(x,y);
while(*s>0&&x<20)
{
wr_data(*s);
s++;
x++;
}
}
/******************************************************************
自定义字符形成;
*****************************************************************/
void CGR_SET(uchar code *s)
{
uchar i=0;
while(*s!=0xff)
{
wr_com(0x40+i);
wr_data(*s);
s++;
i++;
}
}
/******************************************************************
全屏;
*****************************************************************/
void fill(uchar z) //全屏
{
uchar x,y ;
for(y=0;y<2;y++)
for(x=0;x<16;x++)
{
dot(x,y);
wr_data(z);
}
}
/******************************************************************
初始化设置;
*****************************************************************/
void init(void)
{
delay(50);
// RES=1;delay(5);
// RES=1;delay(5);
// RES=1;delay(5);
// 设置电源模式;
wr_com(0x2a);
wr_com(0x71);
wr_data(0x00); /* 设置为3.3V模式 */
wr_com(0x28);
// 显示开关;
wr_com(0x08); /* 关显示 */
// 设置Fosc和DCLK;
wr_com(0x2a);
wr_com(0x79);
wr_com(0xd5);
wr_com(0x70); /* Fosc=7 DCLK=1 */
wr_com(0x78);
wr_com(0x28);
// 设置显示模式;
wr_com(0x2a);
wr_com(0x08); /* 字宽=5 1/2行显示 */
wr_com(0x28);
// 设置地图模式;
wr_com(0x2a);
wr_com(0x06); /* BDC=1(C0-->C31) BDS=0(S99-->S0) (已规定,客户不可自行修改) */
wr_com(0x28);
// 选择内部ROM和CGRAM;
wr_com(0x2a);
wr_com(0x72);
wr_data(0x00); /* ROM=A CGRAM=8 */
wr_com(0x28);
// 设置OLED特性;
wr_com(0x2a);
wr_com(0x79); /* 进入OLED设置 */
wr_com(0xda);
wr_com(0x10); /* SEG硬件结构 (已规定,客户不可自行修改) */
wr_com(0xdc);
wr_com(0x00); /* 内部VSL GPIO输出无效 */
wr_com(0x81);
wr_com(0x7f); /* 共256级对比度,选一半 */
wr_com(0xd9);
wr_com(0xf1); /* P2=15DCLK P1=4DCLK */
wr_com(0xdb);
wr_com(0x30); /* Vcom=0.83Vcc */
wr_com(0x78);
wr_com(0x28); /* 退出OLED设置 */
//准备开显示;
wr_com(0x01); /* 清屏 */
delay(5);
wr_com(0x80); /* 设置DDRAM地址 */
wr_com(0x0c); /* 开显示 */
}
/******************************************************************
主程序;
*****************************************************************/
int main(void)
{
CD=0;
init();
CGR_SET(CGR);
while(1)
{
fill(0x00);delay(700);
fill(0x01);delay(700);
fill(0x02);delay(700);
fill(0x03);delay(700);
clear();
en_c_r(0,0,tab1);
en_c_r(0,1,tab2);delay(700);
}
}
上一篇:HGS128322测试程序
下一篇:HGSC256643应用电路图