#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
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;
void INT()
{
RES=0;
uDelay(20);
RES=1;
uDelay(20);
Writecom(0xae);/////////关显示
Writecom(0xd5);/////////设定显示频率
Writecom(0xa0);
Writecom(0xa8);/////设定占空比 1/32
Writecom(0x1f);
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(0x08);///////////
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);
clear(0x00);
display_8(0,2);
display_8(0,3);
display_16(0,0);
while(1);
}