📄 lcd.c
字号:
unsigned char readate()
{
// LCD_Busy();
unsigned char date;
date = lcd_date;
return (date);
}
/*************************************************************/
//数据写
void writedate(unsigned char date)
{
// LCD_Busy();
lcd_date=date;
}
/*************************************************************/
//指令写
void writecommand(unsigned char command)//写有 1 个参数命令
{
// LCD_Busy();
lcd_command=command;
}
void writecommand01(unsigned char date0, unsigned char command)//写有 2 个参数命令
{
writedate(date0);
writecommand(command);
}
void writecommand02(unsigned char date1, unsigned char date2, unsigned char command)//写有 3 个参数命令
{
writedate(date1);
writedate(date2);
writecommand(command);
}
/*************************************************************/
//填充或清零
void full_clr (unsigned int state)
{
unsigned int i,k;
writecommand02(0x00,0x00,dis_address);
writecommand(audo_wr);
for(k=0;k<128;k++)
{
for(i=0;i<30;i++)
{
writedate(state);
}
// state=~state;
}
writecommand(audo_over);
writecommand02(0x00,0x00,dis_address);
//writecommand(0xf8); 位操作
}
/*************************************************************/
// 显示行,列
void display(unsigned char state)
{
unsigned int i,k;
writecommand02(0x00,0x00,dis_address);
writecommand(audo_wr);
for(k=0;k<128;k++)
{
for(i=0;i<30;i++)
{
writedate(state);
}
state=~state;
}
writecommand(audo_over);
writecommand02(0x00,0x00,dis_address);
}
/*************************************************************/
//显示一幅图
void img1()
{
unsigned char i,m,k;
unsigned int j=0;
// writecommand02(0x00,0x00,dis_address);
writecommand(audo_wr);
for(m=0;m<36;m++)
{ writecommand02(0x00+m,0x00,graphics_address);
for(k=0;k<128;k++)
{
for(i=0;i<30;i++)
{
writedate(logo1[j]);
j++;
}
}
writecommand(audo_over);
writecommand02(0x00,0x00,dis_address);
}
}
/*************************************************************/
//反向显示一幅图
void reverseimg1()
{
unsigned char i,k;
unsigned char j;
for(k=0;k<128;k++)
{
for(i=0;i<30;i++)
{
writecommand(zer_rd);
j=readate();
j=~j;
writecommand01(j, 0xc0);
}
}
}
//*****************************************************************
// 通过位操作方式实现绘制点
void dot(unsigned char x,unsigned char y, unsigned char m)
{
unsigned int z;
z=(30*y+(x/8));
if(z<=256)
writecommand02(z,0x00,dis_address);
else
writecommand02(z%256,z/256,dis_address);
if(m)
writecommand(0xf8+7-(x&0x0007));
else
writecommand(0xf0+x%8);
}
//*****************************************************************
//通用方式实现点绘制
void dot1(unsigned char x,unsigned char y, unsigned char m)
{
unsigned int z,y0;
unsigned char n;
z=(30*y+(x/8));
if(z<=256)
writecommand02(z,0x00,dis_address);
else
writecommand02(z%256,z/256,dis_address);
writecommand(zer_rd); /*此处要注意这条指令必须要加上,*/
y0=readate();
if(m)
n=(7-x&0x0007);
y0|=(1<<n);
writecommand01(y0,0xc0);
}
//*****************************************************************
//画线
void line(unsigned int x0,unsigned int y0,unsigned int xt,unsigned int yt, unsigned char m)
{
register unsigned char t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy;
unsigned int row,col;
delta_x = xt-x0;
delta_y = yt-y0;
col = x0;
row = y0;
if(delta_x>0) incx=1;
else
{
if( delta_x==0 ) incx=0;
else {incx=-1;delta_x=-delta_x;}
}
if(delta_y>0) incy=1;
else
{
if( delta_y==0 ) incy=0;
else {incy=-1;delta_y=-delta_y;}
}
if( delta_x > delta_y ) distance=delta_x;
else distance=delta_y;
for( t=0;t <= distance+1; t++ )
{
dot1(col,row,m);
shortdelay(1000);
xerr += delta_x ;
yerr += delta_y ;
if( xerr > distance )
{
xerr-=distance;
col+=incx;
}
if( yerr > distance )
{
yerr-=distance;
row+=incy;
}
}
}
/*************************************************************************/
//画矩形
void pane(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
line(x1,y1,x2,y1,1);
line(x2,y1,x2,y2,1);
line(x2,y2,x1,y2,1);
line(x1,y2,x1,y1,1);
}
/***********************************************************************/
//画圆
void circle(unsigned int Ox,unsigned char Oy,unsigned char Rx,unsigned char m)
{
unsigned int xx,rr,xt,yt,rs,col,row;
yt=Rx;
rr=Rx*Rx+1;
rs=(yt+(yt>>1))>>1; //(*0.75)分开1/8圆弧来画
for (xt=0;xt<=rs;xt++)
{
xx=xt*xt;
while ((yt*yt)>(rr-xx))yt--;
col=Ox+xt; //第一象限
row=Oy-yt;
dot1(col,row,m);
col=Ox-xt; //第二象限
dot1(col,row,m);
row=Oy+yt; //第三象限
dot1(col,row,m);
col=Ox+xt; //第四象限
dot1(col,row,m);
/***************45度镜象画另一半***************/
col=Ox+yt; //第一象限
row=Oy-xt;
dot1(col,row,m);
col=Ox-yt; //第二象限
dot1(col,row,m);
row=Oy+xt; //第三象限
dot1(col,row,m);
col=Ox+yt; //第四象限
dot1(col,row,m);
}
}
/*************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -