TFT1N5182-V1-E学习

TFT1N5182-V1-E液晶为8位并行、262K色、240(RGB)×400、TFT屏

 

彩屏电路如下,驱动芯片为XPT2046,MCU为STC12C5A60S2

 

TFT1N5182-V1-E学习_第1张图片

 

首先应对驱动芯片初始化,即对相应寄存器位置写入液晶屏参数,此处略去,大家可根据相应手册编写

 


void LCD_SetRamAddr(uint xStart, uint xEnd, uint yStart, uint yEnd)
{
 Reg_Write(0x200, xStart);
    Reg_Write(0x201, yStart);
    Reg_Write(0x0210, xStart);
    Reg_Write(0x0212,yStart);
   
    Reg_Write(0x211,xEnd);
    Reg_Write(0x213,yEnd);

   // LCD_Write(TYPE_LCD_COMMAND,0x022); 
  //  LCD_Write(TYPE_LCD_COMMAND,0x0202);  // 0x22
 LCD_Write(TYPE_LCD_COMMAND,0x0202);
  // delay_ms(500);
}
 

void LCD_Write(uchar type, uint value) 
{
 LCD_CS = 0;
 LCD_RS  = type;      // 0: command    1: data
 
 LCD_WR  = 0;
    DATA  = (uchar)(value>>8) ;
 LCD_WR  = 1;
 _nop_();
 LCD_WR  = 0;
 DATA  = (uchar)value;
    LCD_WR  = 1;
_nop_();
 LCD_CS = 1;
}
 

void LCD_Wirte_Data16(uint value)    // color data
{
 LCD_CS = 0;
    LCD_RS  = 1;
 LCD_WR  = 0;
 //DATA  = (uchar)value;
 DATA  = (uchar)(value>>8) ;
 LCD_WR  = 1;
 LCD_WR  = 0;
 //DATA  = (uchar)(value>>8) ;
 DATA  = (uchar)value;
 LCD_WR  = 1;
 LCD_CS = 1;
}
 

void LCD_ShowChar(uchar x,uchar y,uint For_color,uint Bk_color, char ch)
{      
   uchar temp;
   uchar pos,t;
   uchar  CHAR_W,CHAR_H;
  
   CHAR_W = 8;         //8*16  ,16个字节
   CHAR_H = 16;
   if(x>(LCD_SIZE_X-CHAR_W)||y>(LCD_SIZE_Y-CHAR_H))
   return;
  
   LCD_SetRamAddr(x, x+CHAR_W-1, y,y+CHAR_H-1);
   ch = ch-32; //0x20                      //按照ASCII编码顺序的到相应字母的编码
   for(pos=0;pos
   {
      temp= Font8x16[ch][pos];
     
      for(t=0;t
      {                
     if(temp&0x80) //1000 0000  先写高位
     LCD_Wirte_Data16(For_color);  //textcolor
     else
     LCD_Wirte_Data16(Bk_color);  //backcolor
        temp<<=1;
      }
  
   }
} 

void LCD_ShowString(uchar x,uchar y,uint For_color,uint Bk_color,char *p)
{        
   while(*p!='\0')
   {      
     LCD_ShowChar(x,y,For_color,Bk_color,*p);
     x+=8;
     p++;
   }
}


void ChineseChar(uint x,uint y,int size,uint For_color,uint Bk_color ,char c)
{
   int e=0,i,j;
   int  ed;
  
   uint  ncols;
   uint  nrows;
   uint  nbytes;
   uchar *pfont;
   uchar *pchar;
   uchar *fonttable[]={(uchar *)hz12,(uchar *)hz16,(uchar *)hz24};
  
   pfont=(uchar *)fonttable[size];   //数组开始地址
   if(size==0)
   {
     ncols =12-1;
     nrows =12-1;
     nbytes =24;  //(12*12)/72
   }
   else
   if(size==1)
   {
     ncols =16-1;
     nrows =16-1;
     nbytes =32;  //(16*16)/72
   }
   else
   if(size==2)
   {
     ncols =24-1;
     nrows =24-1;
     nbytes =72;   //(24*24)/72
   }
  
   pchar=pfont + (nbytes*(c-1));  //数组结束地址
   LCD_SetRamAddr(x, x+nrows, y,y+ncols);
  
   for(i=0;i
   {
     ed=*pchar++;
  if(size==0)   //12*12
  {
       if(i%2==0) //双数  此处与字模提取有关 (12位=8+4) 先8后4,即单8双4
       e=8;
       else  
       e=4;   //单数  只写低4为位
  }
  else    //16*16,24*24
  e=8;
     for(j=0;j
 {
  if((ed>>j)&0x01) //位为1写文字
      {
        LCD_Wirte_Data16(For_color);  //textcolor
   }
      else    //位为0写背景颜色
      {
        LCD_Wirte_Data16(Bk_color);  //backcolor
   }
  }
  }
}


你可能感兴趣的:(TFT1N5182-V1-E)