网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61IC中国电子在线 >> DSP >> 代码示例 >> TI DSP代码示例 >> C2000 >> 文章正文
  利用TMS320F2812DSP芯片和汇编语言实现LCD的显示(LCD)         ★★★ 【字体:
利用TMS320F2812DSP芯片和汇编语言实现LCD的显示(LCD)
作者:61IC    文章来源:本站原创    点击数:    更新时间:2007-1-17    

利用TMS320F2812DSP芯片和汇编语言实现LCD的现实,利用该例程可方便的实现LCD的界面化显示

#include "DSP28_Device.h"
extern const  Uint16 LIB32x33[];
extern const  Uint16 LIB16x24[];
extern const  Uint16 LIB24x24[];
extern const  Uint16 LIB16x16[];
extern const  Uint16 LIB8x16[];
extern const  Uint16 LIB64[];

extern const  Uint16 *WhiteList[];
extern const  Uint16 *WordList0[];
extern const  Uint16 *WordList1[];
extern const  Uint16 *WordList2[];
extern const  Uint16 *IconList[]; 

//LCD初始化
void lcd_init(void)
  {
   LCD_COM = 0x40;
   LCD_DAT = 0x30;
   LCD_DAT = 0x87;
   LCD_DAT = 0x07;
   LCD_DAT = 0x27;
   LCD_DAT = 0x2B;
   LCD_DAT = 0xEF;
   LCD_DAT = 0x29;
   LCD_DAT = 0x00;
   
   LCD_COM = 0x44;
   LCD_DAT = 0x00;
   LCD_DAT = 0x00;
   LCD_DAT = 0xF0;
   LCD_DAT = 0x00;
   LCD_DAT = 0x2A;
   LCD_DAT = 0xF0;
   LCD_DAT = 0x00;
   LCD_DAT = 0x54;
   LCD_DAT = 0x00;
   LCD_DAT = 0x00;
   
   LCD_COM = 0x5A;
   LCD_DAT = 0x00;
   
   LCD_COM = 0x5B;
   LCD_DAT = 0x1C;
      
   LCD_COM = 0x59;
   LCD_DAT = 0x54;
   
  }
//清除第一显示缓冲区  
void clearscr1(void)
  {
   Uint16 i;
   LCD_COM = 0x46;
   LCD_DAT = 0x00;
   LCD_DAT = 0x00;
   LCD_COM = 0x4c;
   LCD_COM = 0x42;
   for (i=0;i<0x2A00;i++) LCD_DAT=0x00;
  }

//清除第二显示缓冲区  
void clearscr2(void)
  {
   Uint16 i;
   LCD_COM = 0x46;
   LCD_DAT = 0x00;
   LCD_DAT = 0x2A;
   LCD_COM = 0x4c;
   LCD_COM = 0x42;
   for (i=0x2A00;i<0x5400;i++) LCD_DAT=0x00;
  }
//清除第三显示缓冲区  
void clearscr3(void)
  {
   Uint16 i;
   LCD_COM = 0x46;
   LCD_DAT = 0x00;
   LCD_DAT = 0x54;
   LCD_COM = 0x4c;
   LCD_COM = 0x42;
   for (i=0x5400;i<0x8000;i++) LCD_DAT=0x00;
  }

void clearline(Uint16 x1, Uint16 y1,Uint16  x2, Uint16  y2, Uint16 partition)
  {
   union
    {
     Uint16 total;
     struct
      {
       Uint16 low:8;
       Uint16 high:8;
      }e;
    }d;
   Uint16 i,k;
   if (x1>x2) {i=x1;x1=x2;x2=i;}
            if (y1>y2) {i=y1;y1=y2;y2=i;}
            k = x2-x1 ;
      while(y1<y2)
       {
        d.total=x1+y1*41;
                 if (partition==2) d.total=d.total+0x2a00;
            if (partition==3) d.total=d.total+0x5400;
     LCD_COM = 0x46;
     LCD_DAT = d.e.low;
     LCD_DAT = d.e.high;
     LCD_COM = 0x4c;
     LCD_COM = 0x42;
           for (i=0;i<k;i++) LCD_DAT = 0x00;
                 y1++;
           }
       }
//画点
void dot(Uint16 x, Uint16 y, Uint16  partition)
  {
   union
    {
     Uint16 total;
     struct
      {
       Uint16 low:8;
       Uint16 high:8;
      }e;
    }d;
   Uint16 i,j,dot1;
        d.total=(y-1)*41+(x-1)/8;
        dot1=(x-1)%8;
        if (partition==2) d.total=d.total+0x2a00;
        if (partition==3) d.total=d.total+0x5400;
        LCD_COM = 0x46;
        LCD_DAT = d.e.low;
        LCD_DAT = d.e.high;
   LCD_COM = 0x43;
   i = LCD_COM;
   j = 0x8000;
   j = j>>(dot1+8);
   i = i|j;
   LCD_COM = 0x46;
   LCD_DAT = d.e.low;
   LCD_DAT = d.e.high;
   LCD_COM = 0x42;
   LCD_DAT = i;
       }
//消点       
void NoDot(Uint16 x, Uint16 y, Uint16  partition)
  {
   union
    {
     Uint16 total;
     struct
      {
       Uint16 low:8;
       Uint16 high:8;
      }e;
    }d;
   Uint16 i,j,dot1;
        d.total=(y-1)*41+(x-1)/8;
        dot1=(x-1)%8;
        if (partition==2) d.total=d.total+0x2a00;
        if (partition==3) d.total=d.total+0x5400;
        LCD_COM = 0x46;
        LCD_DAT = d.e.low;
        LCD_DAT = d.e.high;
   LCD_COM = 0x43;
   i = LCD_COM;
   j = 0x8000;
   j = j>>(dot1+8);
   i = i & ~j;
   LCD_COM = 0x46;
   LCD_DAT = d.e.low;
   LCD_DAT = d.e.high;
   LCD_COM = 0x42;
   LCD_DAT = i;
       }
//画横线(实线)       
void drawabscissa(Uint16  y, Uint16 x1, Uint16 x2, Uint16  partition)
  {
   Uint16 i;
   if (x1>x2) { i=x1; x1=x2; x2=i;}       
      if (x2>320) x2=320;
      if (y>240) y=240;
      for( i=x1;i<=x2;i++) dot(i,y,partition);
     } 
//画横线(虚线)
void drawabscissa1(Uint16  y,Uint16  x1, Uint16  x2, Uint16  space, Uint16  partition)
  {
   Uint16 i;
   if (x1>x2) { i=x1; x1=x2; x2=i;}       
      if (x2>320) x2=320;
      if (y>240) y=240;
      for( i=x1;i<=x2;i+=space) dot(i,y,partition);
     } 
//画竖线(实线)
void drawordinate(Uint16 x, Uint16 y1, Uint16  y2, Uint16 partition)
  {
   Uint16 i;
   if (y1>y2) { i=y1; y1=y2; y2=i;} 
      if (x>320) x=320;
      if (y2>240) y2=240;
      for(i=y1;i<=y2;i++) dot(x,i,partition);
     }
//画竖线(虚线线)
void drawordinate1(Uint16 x, Uint16 y1, Uint16  y2, Uint16  space,Uint16 partition)
  {
   Uint16 i;
   if (y1>y2) { i=y1; y1=y2; y2=i;} 
      if (x>320) x=320;
      if (y2>240) y2=240;
      for(i=y1;i<=y2;i+=space) dot(x,i,partition);
     }
//画矩形
void  drawarea(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint16 partition)
   {    
       drawabscissa(y1,x1,x2,partition);
       drawordinate(x1,y1,y2,partition);
      drawordinate(x2,y1,y2,partition);
       drawabscissa(y2,x1,x2,partition);
   }

//画曲线
void liner(Uint16 x1,Uint16 y1,Uint16 x2,Uint16 y2, Uint16  Dsp,Uint16 partition)
  {
   int dx,dy;
   int t1,t2;
   int e,i;
   int x,y;
   int sx,sy;
   dx=abs(x2-x1);
   dy=abs(y2-y1);
   if (x2 > x1)
    sx=1;
    else
    sx=-1;
   if (y2 > y1)
    sy=1;
    else
    sy=-1;

   x=x1;
   y=y1;
   if (dx > dy) {
    t1=2*dy;
    t2=2*(dy-dx);
    e=2*dy-dx;
    for ( i=0;i<dx;i++)
      {
          if (Dsp) dot(x,y,partition);
          else  NoDot(x,y,partition);
          x=x+sx;
          if ( e>=0 )
      {
         y=y+sy;
         e=e+t2;
       }
          else
       e=e+t1;
        }
        }
         else{
         t1=2*dx;
         t2=2*(dx-dy);
         e=2*dx-dy;
         for(i=0;i<dy;i++)
    {
        if (Dsp) dot(x,y,partition);
        else  NoDot(x,y,partition);
         y=y+sy;
         if (e>=0)
     {
        x=x+sx;
        e=e+t2;
      }
          else { e=e+t1;}
      }
     }
   }

//画条形图
void DrawBar(Uint16 x, Uint16 y,Uint16  high, Uint16  partition)
  {
   union{
     Uint16 total;
     struct{
       Uint16 low:8;
       Uint16 high:8;
        }e;
     }d;
   Uint16 j;
         d.total=x+(y-high)*41;
            if (partition==2) d.total=d.total+0x2a00;
         if (partition==3) d.total=d.total+0x5400;
            LCD_COM = 0x4F;
         LCD_COM = 0x46;
   LCD_DAT = d.e.low;
   LCD_DAT = d.e.high;
   LCD_COM = 0x42;
         for (j=0;j<high;j++)  LCD_DAT=0x78;
  }  
//清条形图
void ClearBar(Uint16  x, Uint16 y, Uint16 high, Uint16  partition)
  {
   union{
     Uint16 total;
     struct{
       Uint16 low:8;
       Uint16 high:8;
        }e;
     }d;
   Uint16 j;
         d.total=x+(y-high)*41;
            if (partition==2) d.total=d.total+0x2a00;
         if (partition==3) d.total=d.total+0x5400;
            LCD_COM = 0x4F;
         LCD_COM = 0x46;
   LCD_DAT = d.e.low;
   LCD_DAT = d.e.high;
   LCD_COM = 0x42;
         for (j=0;j<high;j++)  LCD_DAT=0x00;
  }  
//==============================================================================
//************************* PAGE  2 ********************************************
//==============================================================================
// 显示32x33点阵字
void  display0(Uint16 dsp,Uint16 x, Uint16  y,Uint16 condition,Uint16 partition)
      {
         union
             {
                   Uint16 total;
                   struct
                    {
                        Uint16 low:8;
                        Uint16 high:8;
                    }e;
             }d;
     
        Uint16  dspah;
        Uint16 i,j,k;
        
        const Uint16  *word;

            if(dsp<500) k=2,word=LIB16x24,dspah=dsp*48;
            else k=4,word=LIB32x33,dspah=(dsp-500)*132; 

             for(i=0;i<k;i++)
               {
                   d.total=x+y*41+i;
                   if (partition==2) d.total=d.total+0x2a00;
                if (partition==3) d.total=d.total+0x5400;

                        LCD_COM = 0x4F;
                  LCD_COM = 0x46;
      LCD_DAT = d.e.low;
      LCD_DAT = d.e.high;
      LCD_COM = 0x42;
                 
//                temp = tempLow = tempHigh = 0x0000;
                    for (j=0;j<33;j++)
                     {
                    dsp=word[dspah+j*k+i];
                    if (condition==0) LCD_DAT = dsp;
                      else LCD_DAT = ~dsp;
                     } 
               }
            }
// 显示16x16点阵字
void  display1(Uint16 dsp,Uint16 x, Uint16  y,Uint16 condition,Uint16 partition)
      {
         union
             {
                   Uint16 total;
                   struct
                    {
                        Uint16 low:8;
                        Uint16 high:8;
                    }e;
             }d;
     
        Uint16  dspah;
        Uint16 i,j,k;

        const Uint16  *word;

            if(dsp<500) k=3,word=LIB24x24,dspah=dsp*72;
            else k=2,word=LIB16x16,dspah=(dsp-500)*32;

             for(i=0;i<k;i++)
               {
                   d.total=x+y*41+i;
                   if (partition==2) d.total=d.total+0x2a00;
                if (partition==3) d.total=d.total+0x5400;

                        LCD_COM = 0x4F;
                  LCD_COM = 0x46;
      LCD_DAT = d.e.low;
      LCD_DAT = d.e.high;
      LCD_COM = 0x42;
                 

                    for (j=0;j<16;j++)
                     {
                    dsp=word[dspah+j*k+i];
                    if (condition==0) LCD_DAT = dsp;
                      else LCD_DAT = ~dsp;
                     } 
               }
            }

//显示8x16点汉字
void  display2(Uint16 dsp,Uint16 x, Uint16  y,Uint16 condition,Uint16 partition) /*显示16x24点阵,24X24点阵*/
      {
         union
             {
                   Uint16 total;
                   struct
                    {
                        Uint16 low:8;
                        Uint16 high:8;
                    }e;
             }d;
     
        Uint16  dspah;
        Uint16 i,j,k;
        const Uint16  *word;

            if(dsp<500) k=2,word=LIB16x16,dspah=dsp*32;
            else    k=1,word=LIB8x16,dspah=(dsp-500)*16;  

              for(i=0;i<k;i++)
               {
                   d.total=x+y*41+i;
                   if (partition==2) d.total=d.total+0x2a00;
                if (partition==3) d.total=d.total+0x5400;

                        LCD_COM = 0x4F;
                  LCD_COM = 0x46;
      LCD_DAT = d.e.low;
      LCD_DAT = d.e.high;
      LCD_COM = 0x42;
                
                    for (j=0;j<16;j++)

                     {
                    dsp=word[dspah+j*k+i];
                    if (condition==0) LCD_DAT = dsp;
                      else LCD_DAT = ~dsp;
                     } 
               }
            }

void  display64(Uint16 dsp,Uint16 x, Uint16  y,Uint16 condition,Uint16 partition)
      {
         union
             {
                   Uint16 total;
                   struct
                    {
                        Uint16 low:8;
                        Uint16 high:8;
                    }e;
             }d;
     
        Uint16  dspah;
        Uint16 i,j;
        const Uint16  *word;

            word=LIB64,dspah=dsp*512;

              for(i=0;i<8;i++)
               {
                   d.total=x+y*41+i;
                   if (partition==2) d.total=d.total+0x2a00;
                if (partition==3) d.total=d.total+0x5400;

                        LCD_COM = 0x4F;
                  LCD_COM = 0x46;
      LCD_DAT = d.e.low;
      LCD_DAT = d.e.high;
      LCD_COM = 0x42;
                
                    for (j=0;j<64;j++)
                     {
                    dsp=word[dspah+j*8+i];
                    if (condition==0) LCD_DAT = dsp;
                      else LCD_DAT = ~dsp;
                     } 
               }
            }


void  ShowWord(Uint16 menunum,Uint16 partition )
     {
      Uint16 a,b,m=0;
      const Uint16 *mnum; 
     
         if(menunum<500) mnum=WordList1[menunum];
      else  mnum=WordList2[menunum-500];
     
      while (mnum[m]!=last)
          {
              
                a=mnum[m],m++; 
                b=mnum[m],m++;                
      while (mnum[m]!= end)    
                    {
                       if(menunum<500) display1(mnum[m],a,b,0,partition),a++;
                          else display2(mnum[m],a,b,0,partition);
                          if (mnum[m]>=500) a++;
                          m++;
                          }
               m++;
               }            
 
    } 

void  ShowIcon(Uint16 menunum,Uint16 partition )
     {
      Uint16 a,b,m=0;
      const Uint16 *mnum; 
     
         mnum=IconList[menunum];
     
      while (mnum[m]!=last)
          {
              
                a=mnum[m],m++; 
                b=mnum[m],m++;                
       while (mnum[m]!= end)    
                    {
                       display64(mnum[m],a,b,0,partition),a++,a++,a++,a++;
                          m++;
                       }
                m++;
              }            
 
     } 

void  ShowChar(Uint16 menunum,Uint16 Num,Uint16 partition )
     {
      Uint16 a,b,m=0;
      Uint16 TempNum=0;
      const Uint16 *mnum; 
     
         if(menunum<500) mnum=WordList1[menunum];
      else  mnum=WordList2[menunum-500];
      while (TempNum != Num)
          {
        while (mnum[m]!= end)    
               {
                      m++;
                  }
              TempNum++;      
              m++;
              if (mnum[m] == last) return;
             }            
             a=mnum[m],m++; 
             b=mnum[m],m++;                
       while (mnum[m]!= end)    
           {
               if(menunum<500) display1(mnum[m],a,b,0,partition),a++;
                     else display2(mnum[m],a,b,0,partition),a++;
                     if (mnum[m]>=500) a++;
                      m++;
                 }
                m++;
  } 
          
//***********************************************************************
//======================================================================
//=====================  PAGE  3 =========================================
//=======================================================================
//***********************************************************************
void  WhiteNum(Uint16 num,Uint16 white,Uint16 partition)
      {
         union
             {
                   Uint16  total;
                   struct
                     {
                         Uint16 low:8;
                         Uint16 high:8;
                         }e;
              }d;
      
         Uint16  i,j;
         const Uint16  *mnum; 
      mnum=WhiteList[num];
       
         white=4*white;
         for (i=0;i<mnum[white+2];i++)
               {
                  for(j=0;j<mnum[white+3];j++)
                        {
                           d.total=(i+mnum[white])+(mnum[white+1]+j)*41;/*字符在显存中的地址int型*/
                             if (partition==2) d.total=d.total+0x2a00;
                             if (partition==3) d.total=d.total+0x5400;   
                            
                             LCD_COM = 0x46;
                             LCD_DAT = d.e.low;
                            LCD_DAT = d.e.high;
                            LCD_COM = 0x43;
                            num = LCD_COM;
                            num=~num;
                            LCD_COM = 0x46;      
                            LCD_DAT = d.e.low;
                            LCD_DAT = d.e.high;
                             LCD_COM = 0x42;
                             LCD_DAT = num;              

                        }
                }
       }

  
//***********************************************************************
//======================================================================
//=====================  PAGE  4  =======================================
//=======================================================================
//***********************************************************************

void Smenu(void)
  {
      drawarea(1,1,320,240,2);
    drawarea(2,2,319,239,2);
    drawabscissa(19,1,320,2);
    drawabscissa(20,1,320,2);
    drawabscissa(219,1,320,2);
    drawabscissa(220,1,320,2);

    ShowWord(0,2);
    /*ShowIcon(0,2);*/
    ShowWord(500,2);
   
   
  }

//===============================================================

               欢迎点击进入:TI德州中文网   (国内唯一针对TI应用的中文技术网站)    文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    TMS320F2812的SPWM原程序
    基于LabVIEW和TMS320F2812的…
    TMS320F2812的CAN调试成功经…
    基于TMS320F2812和μC/OS II…
    TMS320F2812 全局汇编函数
    TMS320F2812 CMD 文件各段含…
    基于TMS320F2812集中供电系统…
    TMS320F2812的CMD文件配置详…
    基于TMS320F2812的多轴伺服控…
    利用TMS320F2812 DSP&DRV592…
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    站长:61IC 湘ICP备05002478号