各种波形及部分表格都是通过线段来实现的,本文介绍了一种速度较快的画线程序,适合各种TFT系列总线型液晶显示器。
对于VTK系列智能型显示器的用户无需掌握本文内容。
/***********************************************
****硬件连接:P00--P07<===>D0--D7***
****/WR<===>/WR**
****/RD<===>/RD****
****P27<===>/CS****
****P21<===>A1****
****P20<===>A0****
************************************************/
#include<reg51.h>
#include<absacc.h>
#defineX_ADDRXBYTE[0x0000]
#defineY_ADDRXBYTE[0x0100]
#defineCMDXBYTE[0x0200]
#defineDATXBYTE[0x0300]
//声明程序
draw_pixel(unsignedintx,unsignedinty,unsignedcharcolor);//画点
draw_line(unsignedintx1,unsignedinty1,unsignedintx2,unsignedinty2,unsignedcharcolor);//画线
//*************************drawlinestart**********************
//画线开始
draw_line(unsignedintx1,unsignedinty1,unsignedintx2,unsignedinty2,unsignedcharcolor)
{unsignedinti1,j1,k1,l1;
intn1=0;
unsignedchartemp=0;
if(y2<y1)
{i1=x1;
l1=y1;
x1=x2;
y1=y2;
x2=i1;
y2=l1;}
k1=y2-y1;
if(k1==0)
{if(x1>x2)
{i1=x1;
x1=x2;
x2=i1;}
for(i1=x1;i1<=x2;i1++)
draw_pixel(i1,y1,color);
}
else
{if(x2>=x1)
{temp=1;
j1=x2-x1;}
else
j1=x1-x2;
i1=x1;
l1=y1;
draw_pixel(i1,l1,color);
if(temp&&(k1<=j1))
while(i1!=x2)
{if(n1<0)
{i1=i1+1;
n1=n1+(y2-l1);}
else
{i1=i1+1;
l1=l1+1;
n1=n1+(y2-l1)-(x2-i1);}
draw_pixel(i1,l1,color);}
elseif(temp&&(k1>j1))
while(l1!=y2)
{j1=x2-i1;
k1=y2-l1;
if(n1<0)
{i1=i1+1;
l1=l1+1;
n1=n1+k1-j1;}
else
{l1=l1+1;
n1=n1-j1;}
draw_pixel(i1,l1,color);}
elseif(!temp&&(k1<=j1))
while(i1!=x2)
{j1=i1-x2;
k1=y2-l1;
if(n1<0)
{i1=i1-1;
n1=n1+k1;}
else
{i1=i1-1;
l1=l1+1;
n1=n1+k1-j1;}
draw_pixel(i1,l1,color);}
elseif(!temp&&(k1>j1))
while(l1!=y2)
{j1=i1-x2;
k1=y2-l1;
if(n1<0)
{i1=i1-1;
l1=l1+1;
n1=n1+k1-j1;}
else
{l1=l1+1;
n1=n1-j1;}
draw_pixel(i1,l1,color);}
}
}
draw_pixel(unsignedintx,unsignedinty,unsignedcharcolor)
{unsignedchartemp,i;
Y_ADDR=y%256;//行低位地址
Y_ADDR=y/256;//行高位地址
X_ADDR=x%256;//列低位地址
X_ADDR=x/256;//列高位地址
DAT=color;}
//画线结束
//************drawlineend********************
//调用举例
main()
{
draw_line(0,0,150,150,0xe0);//红色(0,0)->(150,150)
}
以上资讯由深圳LCM厂家——迈晶电子搜集整理。