国内销售专线:0755-83573112 / 0755-81790748
产品类别
  • 联系方式
  • 在线QQ咨询:在线QQ咨询
    拨打销售专线
    0755-83573112 / 0755-81790748
    联系邮箱
    xyhlcd02@xyhlcd.com、service01@xyhlcd.com
    公司传真
    0755-81790647

TFT系列总线型液晶显示器画线函数的编写方法!

发布来源:www.xyhlcd.com   发布时间:2010-5-27

 各种波形及部分表格都是通过线段来实现的,本文介绍了一种速度较快的画线程序,适合各种TFT系列总线型液晶显示器。
    对于VTK系列智能型显示器的用户无需掌握本文内容。
/***********************************************
****硬件连接: P00--P07  <===>  D0--D7***
****          /WR     <===>  /WR       **
****          /RD     <===>  /RD      ****
****          P27     <===>  /CS      ****
****          P21     <===>  A1       ****
****           P20     <===>  A0      ****          
************************************************/

#include <reg51.h>
#include <absacc.h>
#define X_ADDR XBYTE[0x0000]
#define Y_ADDR XBYTE[0x0100]
#define CMD XBYTE[0x0200]
#define DAT XBYTE[0x0300]

//声明程序
draw_pixel(unsigned int x,unsigned int y, unsigned char color); //画点
draw_line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2, unsigned char color); //画线

//*************************draw line start**********************
//画线开始
draw_line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2, unsigned char color)
{ unsigned int i1,j1,k1,l1;
int n1=0;
unsigned char temp=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);}
      else if(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);}
      else if(!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);}
      else if(!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(unsigned int x,unsigned int y, unsigned char color)
{ unsigned char temp,i;
Y_ADDR = y%256;//行低位地址
Y_ADDR = y/256;//行高位地址
X_ADDR = x%256;//列低位地址
X_ADDR = x/256;//列高位地址
DAT=color;}
//画线结束
//************draw line end********************


//调用举例
main()
{
draw_line(0,0,150,150,0xe0);//红色(0,0)->(150,150)
}

以上资讯由深圳LCM厂家——兴宇合电子搜集整理。

Copyright© 2001-2017 深圳市兴宇合电子有限公司 [拥有十几年经验的液晶屏液晶模组液晶模块背光源led数码管生产厂家!]
国内销售专线:0755-83573112 / 0755-83570678 前台电话:0755-83404646 地址:深圳市宝安区石岩镇宏发工业园16栋5楼
传真:0755-81790647 粤ICP备11030976号   网站地图


分享到: