📄 lcd_indirect_pic.c
字号:
#include <reg51.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define uchar unsigned char
uchar cbyte;
uchar column;
uchar page;
bit xy;
sbit CSA=P3^0;
sbit CSB=P3^1;
sbit D_I=P3^2;
sbit R_W=P3^3;
sbit E=P3^4;
sbit BUSY=P1^7;
#define DISPON 0x3f
#define DISPOFF 0x3e
#define DISPFIRST 0xc0
#define SETX 0x40
#define SETY 0xb8
#define MODL 0x40
#define MODR 0x80
#define LCMLIMIT 0xc0
/**********函数列表**********/
void wtcom(void);
void Inquire_Busy_L(void);
void Inquire_Busy_R(void);
void Send_Dat_L(uchar d);
void Send_Dat_R(uchar d);
void Send_Dat_Disp_L(uchar d);
void Send_Dat_Disp_R(uchar d);
void Ini();
void Clear();
void locatexy(uchar col,uchar row1);
void wrdata(uchar col,uchar row1,uchar d);
void point(uchar col,uchar row0);
void lineh(uchar col,uchar row0,uchar length);
void linexy(uchar col,uchar row0,uchar endx,uchar endy);
void rollscreen(uchar x);
void set_startline(uchar i);
void AC_fill(uchar fdata);
void AC_load(uchar *np);
void AC_pageup(uchar *cp,uchar *np,uchar rows,uchar fdata);
void AC_wrapdown(uchar *np);
void AC_wrapup(uchar *np);
void AC_pileup(uchar *np,uchar fdata);
void AC_fadein(uchar *np,uchar fdata);
void AC_fadeout(uchar *cp,uchar fdata);
void AC_shutter(uchar *np,uchar fdata);
void Delay();
uchar code cp[];
uchar code np[];
void wtcom(void)
{
D_I=0;R_W=1;P1=0xff;
while (1) {
E=1;
if (BUSY!=1) break;
E=0;}
E=0;
}
void Inquire_Busy_L(void)
{
CSA=0;CSB=1;
wtcom();
CSA=1;
R_W=1;D_I=1;
}
void Send_Dat_L(uchar d)
{
D_I=0;R_W=0;
CSA=0;CSB=1;
P1=d;
E=1;
E=0;
CSA=1;
R_W=1;D_I=1;
}
void Inquire_Busy_R(void)
{
CSA=1;CSB=0;
wtcom();
CSB=1;
R_W=1;D_I=1;
}
void Send_Dat_R(uchar d)
{
D_I=0;R_W=0;
CSA=1;CSB=0;
P1=d;
E=1;
E=0;
CSB=1;
R_W=1;D_I=1;
}
void Send_Dat_Disp_L(uchar d)
{
D_I=1;R_W=0;
CSA=0;CSB=1;
P1=d;
E=1;
E=0;
CSA=1;
R_W=1;D_I=1;
}
void Send_Dat_Disp_R(uchar d)
{
D_I=1;R_W=0;
CSA=1;CSB=0;
P1=d;
E=1;
E=0;
CSB=1;
R_W=1;D_I=1;
}
void Delay()
{
uchar i,j;
for(i=0;i<255;i++)
{for(j=0;j<255;j++);}
}
void locatexy(uchar col,uchar row1)
{
if(col>=128){CSA=1;CSB=0;} else{CSA=0;CSB=1;}
wtcom();
D_I=0;R_W=0;
P1=row1|0xb8;
E=1;
E=0;
wtcom();
D_I=0;R_W=0;
P1=col&0x3f|0x40;
E=1;
E=0;
P1=0xff;
}
void wrdata(uchar col,uchar row1,uchar d)
{
locatexy(col,row1);
wtcom();
D_I=1;R_W=0;
P1=d;
E=1;
E=0;
P1=0xff;
}
void rollscreen(uchar x)
{
cbyte=DISPFIRST|x;
Inquire_Busy_L();
Send_Dat_L(cbyte);
Inquire_Busy_R();
Send_Dat_R(cbyte);
}
void set_startline(uchar i)
{
i+=0xc0;
Inquire_Busy_L();
Send_Dat_L(i);
Inquire_Busy_R();
Send_Dat_R(i);
}
void Ini()
{
E=0;
D_I=1;
R_W=1;
CSA=1;
CSB=1;
Delay();
cbyte=DISPOFF;
Inquire_Busy_L();
Send_Dat_L(cbyte);
Inquire_Busy_R();
Send_Dat_R(cbyte);
cbyte=DISPON;
Inquire_Busy_L();
Send_Dat_L(cbyte);
Inquire_Busy_R();
Send_Dat_R(cbyte);
cbyte=DISPFIRST;
Inquire_Busy_L();
Send_Dat_L(cbyte);
Inquire_Busy_R();
Send_Dat_R(cbyte);
}
void Clear()
{
uchar i,j,Disp_Page;
for(i=0;i<8;i++)
{
Disp_Page=i;
Disp_Page=Disp_Page|0xb8;
Inquire_Busy_L();
Send_Dat_L(Disp_Page);
Inquire_Busy_L();
Send_Dat_L(0x40);
for(j=0;j<64;j++)
{Send_Dat_Disp_L(0x00);}
}
for(i=0;i<8;i++)
{
Disp_Page=i;
Disp_Page=Disp_Page|0xb8;
Inquire_Busy_R();
Send_Dat_R(Disp_Page);
Inquire_Busy_R();
Send_Dat_R(0x40);
for(j=0;j<64;j++)
{Send_Dat_Disp_R(0x00);}
}
}
void point(uchar col,uchar row0)
{
uchar x1,y1,x,y;
x1=col;
y1=row0;
row0=y1>>3;
y=y1&0x07;
x=0x01;
x=x<<y;
wrdata(col,row0,x);
}
void lineh(uchar col,uchar row0,uchar length)
{
uchar xs,ys;
ys=col;
for(xs=0;xs<length;xs++){
col=ys+xs;
point(col,row0);}
}
void linexy(uchar col,uchar row0,uchar endx,uchar endy)
{
register uchar t;
int xerr,yerr,delta_x,delta_y,distance;
uchar incx,incy;
xerr=0;yerr=0;
delta_x=endx-col;
delta_y=endy-row0;
if(delta_x>0)incx=1;
else if(delta_x==0)incx=0;
else incx=-1;
if(delta_y>0)incy=1;
else if(delta_y==0)incy=0;
else incy=-1;
delta_x=cabs(delta_x);
delta_y=cabs(delta_y);
if(delta_x>delta_y)distance=delta_x;
else distance=delta_y;
/*****开始画线*****/
for(t=0;t<=distance+1;t++){
point(col,row0);
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance){
xerr-=distance;
col+=incx;
}
if(yerr>distance){
yerr-=distance;
row0+=incy;
}
}
}
void AC_fill(uchar fdata) //Fill the full LCD with "fdata"
{
uchar data i,j;
for(i=0;i<8;i++)
{
locatexy(64,i);
for(j=0;j<64;j++)
Send_Dat_Disp_L(fdata);
locatexy(128,i);
for(j=0;j<64;j++)
Send_Dat_Disp_R(fdata);
}
}
void AC_load(uchar *np) //Load the LCD with a 128*64 image,*np is the pointer to the image
{ uchar data i,j;
set_startline(0);
for(i=0;i<8;i++)
{
locatexy(64,i);
for(j=0;j<64;j++)
{
Send_Dat_Disp_L(*np);
np++;
}
locatexy(128,i);
for(j=0;j<64;j++)
{
Send_Dat_Disp_R(*np);
np++;
}
}
}
void AC_pageup(uchar *cp,uchar *np,uchar rows,uchar fdata)
//Roll all of the LCD and replace the Current page(*cp) with the Next(*np),
//"rows" designate how many banks filled with "fdata" will be inserted between the two pages
{
uchar data i,j;
uchar data rbits=0xff;
for(i=0;i<rows*8;i++)
{
set_startline((i+1)%64);
rbits<<=((i%8)+1);
locatexy(64,((i/8)%8));
for(j=0;j<64;j++)
{ Send_Dat_Disp_L(((rbits&(*cp))|((~rbits)&fdata)));
cp++;
}
locatexy(128,(i/8)%8);
for(j=0;j<64;j++)
{ Send_Dat_Disp_R(((rbits&(*cp))|((~rbits)&fdata)));
cp++;
}
rbits=0xff;
cp-=128;
if((i+1)%8==0)
cp+=128;
Delay();
}
for(i=0;i<64;i++)
{
set_startline((i+rows*8+1)%64);
rbits <<=((i%8)+1);
locatexy(64,((i+rows*8)/8)%8);
if((i+rows*8)<64)
{
for(j=0;j<64;j++)
{
Send_Dat_Disp_L(((rbits&(*cp))|((~rbits)&(*np))));
cp++;
np++;
}
}
else
{
for(j=0;j<64;j++)
{
Send_Dat_Disp_L(((rbits&fdata)|((~rbits)&(*np))));
np++;
}
}
locatexy(128,((i+rows*8)/8)%8);
if((i+rows*8)<64)
{
for(j=0;j<64;j++)
{
Send_Dat_Disp_R(((rbits&(*cp))|((~rbits)&(*np))));
cp++;
np++;
}
}
else
{
for(j=0;j<64;j++)
{
Send_Dat_Disp_R(((rbits&fdata)|((~rbits)&(*np))));
np++;
}
}
rbits=0xff;
cp-=128;
np-=128;
if((i+1)%8==0)
{
cp+=128;
np+=128;
}
Delay();
}
}
void AC_wrapdown(uchar *np) //wrap down the full screen the Next page(*np)
{
uchar data i,j;
set_startline(0);
for(i=0;i<8;i++)
{
locatexy(64,i);
for(j=0;j<64;j++)
{
Send_Dat_Disp_L(*np);
np++;
Delay();
}
locatexy(128,i);
for(j=0;j<64;j++)
{
Send_Dat_Disp_R(*np);
np++;
Delay();
}
}
}
void AC_wrapup(uchar *np) //wrap up the full screen the Next page(*np)
{
uchar data i,j;
np+=0x380;
set_startline(0);
for(i=0;i<8;i++)
{
locatexy(64,7-i);
for(j=0;j<64;j++)
{
Send_Dat_Disp_L(*np);
np++;
Delay();
}
locatexy(128,7-i);
for(j=0;j<64;j++)
{
Send_Dat_Disp_R(*np);
np++;
Delay();
}
np-=0x100;
}
}
void AC_pileup(uchar *np,uchar fdata) //Pileup the LCD by falling banks of image(*np) from top to bottom and rest of the LCD filled with "fdata"
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -