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

12年

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

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

收藏本公司 人气:1127567

企业档案

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

您的当前位置:

杭州清达光电技术有限公司 > 技术资料 > HGS128647(I2C)演示程序

HGS128647(I2C)演示程序

发布时间: 2016/10/13 13:16:09 | 737 次阅读

HGS128647(I2C)演示程序

#include <reg52.h>
#include <intrins.h>
#include <math.h>
#include <stdio.h>


#define   lcddata P1
#define   uchar  unsigned char
#define   uint   unsigned char
//#define I80
//#define SPI
//#define M68
#define I2C
   sbit  RW=P3^1;
   sbit  E=P3^3;
   sbit  _WR=P3^1;   
   sbit  _RD=P3^3;
   sbit  CS=P3^4;
   sbit  DC=P3^0;
   sbit  RES=P3^5;
   sbit  SCLK=P1^0;
   sbit  SDIN=P1^1;
   
   sbit  SCL=P1^0;
   sbit  SDA=P1^1;
   
uchar code tab8[][8]={
                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"
0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00,    /*"0"=10h*/
0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,    /*"1"=11h*/
0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00,    /*"2"=12h*/
0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00,    /*"3"=13h*/
0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,    /*"4"=14h*/
0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00,    /*"5"=15h*/
0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00,    /*"6"=16h*/
0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00,    /*"7"=17h*/
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,    /*"8"=18h*/
0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00,    /*"9"=19h*/
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,    /*":"=1Ah*/
0x00,0x00,0x56,0x36,0x00,0x00,0x00,0x00,    /*";"=1Bh*/
0x00,0x7E,0x11,0x11,0x11,0x7E,0x00,0x00,    /*"A"=21h*/
0x00,0x41,0x7F,0x49,0x49,0x36,0x00,0x00,    /*"B"=22h*/
0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00,    /*"C"=23h*/
0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00,    /*"D"=24h*/
0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00,    /*"E"=25h*/
0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00,    /*"F"=26h*/
0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00,    /*"G"=27h*/
0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00,    /*"h"=28h*/
0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00,    /*"I"=29h*/
};
uchar code tab16[][32]={
/* 点阵:16x16
   提取点阵方向:纵向
   字节掉转:是
   字节方式:C语言 */
0x10,0x22,0x64,0x0C,0xC0,0x44,0x54,0x54,    // 清
0x54,0x7F,0x54,0x54,0xD6,0x44,0x40,0x00,
0x04,0x04,0xFE,0x01,0x00,0x00,0xFF,0x15,
0x15,0x15,0x55,0x95,0x7F,0x01,0x00,0x00,


0x40,0x42,0xCC,0x00,0x20,0x20,0x20,0xA0,    // 达
0x7F,0x20,0x20,0x20,0x30,0x20,0x00,0x00,
0x40,0x20,0x1F,0x20,0x50,0x48,0x46,0x41,
0x40,0x41,0x42,0x4C,0x58,0x60,0x20,0x00,


0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F,    // 光
0x40,0xC0,0x50,0x48,0x46,0x64,0x40,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,
0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,


0x00,0x00,0xC0,0x40,0x40,0x40,0x7F,0x48,    // 点
0x48,0x48,0x48,0xE8,0x4C,0x08,0x00,0x00,
0x80,0x40,0x37,0x04,0x14,0x64,0x04,0x14,
0x24,0x64,0x04,0x17,0x20,0xC0,0x00,0x00,


0x10,0x22,0x64,0x0C,0x80,0x04,0xC4,0x34,    // 液
0x05,0xC6,0xBC,0x24,0x24,0xE6,0x04,0x00,
0x04,0x04,0xFE,0x01,0x02,0x01,0xFF,0x42,
0x21,0x16,0x08,0x15,0x23,0x60,0x20,0x00,


0x00,0x00,0x00,0x00,0xFF,0x49,0x49,0x49,    // 晶
0x49,0x49,0xFF,0x00,0x00,0x80,0x00,0x00,
0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,
0xFF,0x49,0x49,0x49,0x49,0xFF,0x01,0x00,


0x10,0x10,0xD0,0xFF,0x94,0x14,0xE4,0xBF,    // 模
0xA4,0xA4,0xA4,0xBF,0xF4,0x26,0x04,0x00,
0x04,0x03,0x00,0xFF,0x08,0x89,0x8B,0x4A,
0x2A,0x1E,0x2A,0x2A,0x4B,0xC8,0x48,0x00,


0x20,0x20,0x20,0xFF,0x20,0x20,0x10,0x10,    // 块
0xFF,0x10,0x10,0x10,0xF8,0x10,0x00,0x00,
0x08,0x18,0x08,0x0F,0x84,0x46,0x22,0x1A,
0x07,0x0A,0x12,0x22,0x43,0xC2,0x42,0x00,
};
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<131;i++)
{
for(j=0;j<15;j++)
{
uDelay(80);
}
}
}
}
#ifdef M68 // 8-bit 68XX Parallel
void Writecom(unsigned char Data)
{
DC=0;
CS=0;
RW=0;
E=1;
lcddata=Data;
E=0;
RW=1;
CS=1;
DC=1;
}




void Writedata(unsigned char Data)
{
DC=1;
CS=0;
RW=0;
E=1;
lcddata=Data;
E=0;
RW=1;
CS=1;
DC=1;
}
#endif
#ifdef I80 // 8-bit 80XX Parallel
void  Writecom(uchar com)
{
DC=0;
CS=0;


_WR=0;
        _nop_();
 lcddata=com;
        _nop_();
_WR=1;
        _nop_();
        _nop_();
CS=1;
DC=1;
}
void Writedata(uchar dat)
{
DC=1;
CS=0;


_WR=0;
         _nop_();
     lcddata=dat;
        _nop_();
_WR=1;
         _nop_();
        _nop_();
CS=1;
DC=1;
}
uchar Readcom()
{
       uchar com;
DC=0;
CS=0;
        lcddata=0xff;
_RD=0;
        _nop_();
        _nop_();
         com=lcddata;
_RD=1;
        _nop_();
        _nop_();
CS=1;
DC=1;
        return com;
}
uchar Readdata()
{
       uchar dat;
DC=1;
CS=0;
        lcddata=0xff;
_RD=0;
         _nop_();
        _nop_();
        dat= lcddata;
_RD=1;
         _nop_();
        _nop_();
CS=1;
DC=1;
        return dat;
}
#endif


#ifdef SPI // 4-wire SPI
void Writecom(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 Writedata(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


#ifdef I2C // I2C
void uDelay(unsigned char l)
{
while(l--);
}




void I2C_O(unsigned char mcmd)
{
unsigned char length = 8; // Send Command


while(length--)
{
if(mcmd & 0x80)
{
SDA=1;
}
else
{
SDA=0;
}
uDelay(3);
SCL=1;
uDelay(3);
SCL=0;
uDelay(3);
mcmd = mcmd << 1;
}
}




void I2C_Ack()
{
SDA=1;
uDelay(3);
SCL=1;
uDelay(3);
SCL=0;
uDelay(3);
}




void I2C_NAck()
{
SDA=0;
uDelay(3);
SCL=1;
uDelay(3);
SCL=0;
uDelay(3);
}




void I2C_Start()
{
SDA=0;
uDelay(3);
SCL=1;
uDelay(3);
SCL=0;
uDelay(3);
I2C_O(0x78);
I2C_Ack();
}




void I2C_Stop()
{
SCL=1;
uDelay(5);
SDA=0;
uDelay(5);
SDA=1;
uDelay(5);
}




void Writecom(unsigned char Data)
{
I2C_Start();
I2C_O(0x00);
I2C_Ack();
I2C_O(Data);
I2C_Ack();
I2C_Stop();
}




void Writedata(unsigned char Data)
{
I2C_Start();
I2C_O(0x40);
I2C_Ack();
I2C_O(Data);
I2C_Ack();
I2C_Stop();
}


#endif




void startline(uchar line)
{
 line=line&0x3f;///定义低5位
 line=line|0x40;///行或
 Writecom(line);
}


void startpage(uchar page)
{
 page=page&0x0f;///定义低4位
 page=page|0xb0;///页
 Writecom(page);
}
/*The beginning of seg is 0x1000*/
void startcolumn(uchar column)
{
 uchar temp;
 temp=column;
 column=column&0x0f;   ///定义A3-A0;
 column=column|0x00;
 Writecom(column);
 column=temp/16;      ////////////// >>4
 column=column&0x0f;  ///定义A7-A4;
 column=column|0x10;
Writecom(column);
}


void clear(uchar m)
{uchar i,j;
for(i=0;i<8;i++)
{
Writecom(0xb0+i);                //startpage(i)
Writecom(0x00);Writecom(0x10);  //startcolumn(0)
for(j=0;j<128;j++)
{Writedata(m);
}}
}


void reset(uchar m)
{
unsigned char i,j;
for(i=0;i<8;i++)
{ startpage(i);
startcolumn(0x00);
          for(j=0;j<64;j++)
{ Writedata(m);
Writedata(~m);
}}}


void INT()
{
RES=0;
uDelay(20);
RES=1;
uDelay(20);


Writecom(0xae);/////////关显示
Writecom(0xd5);/////////设定显示频率
Writecom(0xa0);


Writecom(0xa8);/////设定占空比 1/32
Writecom(0x3f);


Writecom(0xd3);////////设定显示范围 COM
Writecom(0x00);


Writecom(0x40);///////起始行
Writecom(0x00);


Writecom(0xad);/////内部dc-dc
Writecom(0x8e);


Writecom(0x20);/////接口方式 页方式
Writecom(0x02);


Writecom(0xa1);/////seg方向 132-0
Writecom(0xc8);/////com方向 63-0


Writecom(0xda);////Set COM Pins Hardware Configuration
Writecom(0x12);///


Writecom(0x81);////////////对比度调节
Writecom(0xbf);/////////////对比度为中


Writecom(0xdb);////////////倍压调节
Writecom(0x34);///////////


Writecom(0xa4);////////////Entire Display ON
Writecom(0xa6);////////////Normal display
clear(0x00);
Writecom(0xaf);////////////开显示
}
void display88(uchar x,uchar y,uchar coder)
{
   uchar i;


   for(i=0;i<8;i++)
   {
    startpage(y);
   startcolumn(x);
   Writedata(tab8[coder][i]);x++;}
}
void display_8(uchar x,uchar y)
{
  uchar i;
  for(i=0;i<16;i++)
  {display88(x,y,i);x=x+8;}
}
void display16(uchar x,uchar y,uchar coder)
{
    uint j,i;
    uchar n;
    n=x;
    i=0;
loop:


    for(j=i;j<i+16;j++)
    {
    startpage(y);
    startcolumn(x);
    Writedata(tab16[coder][j]);x++;}


   if(i==0)
   {i=16;
    y++;
    x=n;
    if(y==4)
    return;
    else goto loop;}
}
void display_16(uchar x,uchar y)
{
  uchar i;
  for(i=0;i<8;i++)
  {display16(x,y,i);x=x+16;}
}
/****************************************************
竖直卷动
a=0x00,向上卷动  a=0x01,向下卷动
//    b: Set Top Fixed Area
//    c: Set Vertical Scroll Area
//    d: Set Numbers of Row Scroll per Step
//    e: Set Time Interval between Each Scroll Step
**************************************************/
void Vertical_Scroll(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e)
{
unsigned int i,j;


Writecom(0xA3); // Set Vertical Scroll Area
Writecom(b); //   Default => 0x00 (Top Fixed Area)
Writecom(c); //   Default => 0x40 (Vertical Scroll Area)


switch(a)
{
case 0:
for(i=0;i<c;i+=d)
{
startline(i);
for(j=0;j<e;j++)
{
uDelay(200);
}
}
break;
case 1:
for(i=0;i<c;i+=d)
{
startline(c-i);
for(j=0;j<e;j++)
{
uDelay(200);
}
}
break;
}
startline(0x00);
}
/******************************************************
水平卷动
a=0x00,向右卷动  a=0x01,向左卷动
//    b: Set Numbers of Column Scroll per Step
//    c: Define Start Page Address
//    d: Define End Page Address
//    e: Set Time Interval between Each Scroll Step in Terms of Frame Frequency
//    f: Delay Time
*******************************************************/
void Horizontal_Scroll(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e, unsigned char f)
{
Writecom(0x26|a); // Horizontal Scroll Setup
Writecom(b);
Writecom(c);
Writecom(e);
Writecom(d);
Writecom(0x2F); // Activate Scrolling
delay(f);
}
/*************
  主程序
***************/
void main(void)
{
    INT();


        clear(0xff);
delay(1);
clear(0x55);
delay(1);
clear(0xaa);
delay(1);
reset(0x55);
delay(1);
reset(0xaa);
delay(1);
        reset(0xff);
delay(1);
        reset(0x00);
delay(1);
clear(0x00);
display_8(0,2);
        display_8(0,3);
display_16(0,0);
        display_16(0,4);
        display_16(0,6);
while(1);
}