⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcddrive.c

📁 基于zlg SmartARM2300平台的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
uint8  TftSetWindow(uint16 x0, uint16 y0, uint16 x1, uint16 y1)  
{  uint16  hea_hsa;

   // 参数过滤
   if(x1>239) x1 = 239;
   if(y1>319) y1 = 319;
   if((x1<=x0) || (y1<=y0)) return(FALSE);         
   
   // 设置数据填充窗口大小
   hea_hsa = (x1<<8) | x0;
   TftSendCom(SET_WINDOW_SX_EX);		
   TftSendDat(hea_hsa);   
   TftSendCom(SET_WINDOW_SY);		
   TftSendDat(y0);
     
   TftSendCom(SET_WINDOW_EY);		
   TftSendDat(y1);
   
   return(TRUE);
}


/*******************************************************
* 名称: DelaymS
* 功能: 软件延时(1mS,与系统时钟有关)。
* 入口参数: no   延时控制(uint32),值越大延时越长
* 出口参数: 无
*******************************************************/
void  DelaymS(uint32 no)
{  uint32 i;

   for(; no>0; no--)
   {  for(i=0; i<500; i++);
   }
}


/****************************************************************************
* 名称:TFT_FillSCR()
* 功能:全屏填充。直接使用数据填充显示缓冲区。
* 入口参数:dat		填充的数据
* 出口参数:无
****************************************************************************/
void  TFT_FillSCR(uint16 dat)
{  uint16  i, j;

   TftSetWindow(0,0, 239, 319); 
   TftSetWrite(0, 0);
   for(i=0; i<GUI_LCM_YMAX; i++)		// 历遍所有行
   {  for(j=0; j<GUI_LCM_XMAX; j++)		// 历遍所有行
      {  TftSendDat(dat); 				// 填充数据
	  }
   }
}


/*******************************************************
* 名称: TftReset
* 功能: 控制TFT液晶模块复位。
* 入口参数: 无
* 出口参数: 无
*******************************************************/
void  TftReset(void)
{   PINSEL7 = PINSEL7 & (~(0x03<<16));
    FIO3DIR = FIO3DIR | S6D0139_RST;    

    FIO3CLR = S6D0139_RST;
    DelaymS(10);
    FIO3SET = S6D0139_RST;
    DelaymS(10);   
}


// 定义TFT4137初始化数据信息
STCOM_INI  TFT4137_INI[] = 
{   // 电源设置
    {0x0000, 0x0001, 10},	// Start Oscillation
    {0x0007, 0x0000,  0},	// Display control1 
    {0x0013, 0x0000,  0},	// Power control4 setting
    {0x0011, 0x2604,  0},	// Power control2 setting
    {0x0014, 0x0015,  0},	// Power control5 setting
    {0x0010, 0x3C00,  0},   // Power control1 setting
    {0x0013, 0x0040, 10},	// Power control4 setting
    {0x0013, 0x0060, 50},	// Power control4 setting
    {0x0013, 0x0070, 40},	// Power control4 setting
    
    {0x0001, 0x0127,  0},   // Driver output setting (240x320 mode, GS=0, SS=1)
    {0x0002, 0x0700,  0},   // LCD driving waveform setting
    {0x0003, 0x1030,  0},   // Entry mode setting (TRI=0, DFM=0, BGR=1, ID1:ID0 =11)
    {0x0007, 0x0000,  0},   // Display control1 
    {0x0008, 0x0404,  0},   // Display control2
    {0x000B, 0x0200,  0},	// Frame cycle setting
    {0x000C, 0x0000,  0},	// External display interface setting
    {0x00015,0x0000,  0},	
    
    //gamma setting
    {0x0030, 0x0000,  0},   // Gamma control1
    {0x0031, 0x0606,  0},   // Gamma control2
    {0x0032, 0x0006,  0},   // Gamma control3
    {0x0033, 0x0403,  0},   // Gamma control4
    {0x0034, 0x0107,  0},   // Gamma control5
    {0x0035, 0x0101,  0},   // Gamma control6
    {0x0036, 0x0707,  0},   // Gamma control7
    {0x0037, 0x0304,  0},   // Gamma control8
    {0x0038, 0x0A00,  0},   // Gamma control9
    {0x0039, 0x0706,  0},   // Gamma control10
    
    {0x0040, 0x0000,  0},   // Gate scan position (start G1 scan)
    {0x0041, 0x0000,  0},   // Vertical scroll setting
    {0x0042, 0x013F,  0},   // Screen end position (320-1)
    {0x0043, 0x0000,  0},   // Screen start position (0)
    {0x0044, 0x0000,  0},   // 2th Screen end position
    {0x0045, 0x0000,  0},   // 2th Screen start position
    {0x0046, 0xEF00,  0},   // window addr set for x0,x1 (0, 239)
    {0x0047, 0x013F,  0},   // window addr set for y0    (319)
    {0x0048, 0x0000,  0},   // window addr set for y1    (0)
    {0x0007, 0x0011, 40},   // Display control1
    {0x0007, 0x0017,  0},   // Display control1 
 
    {DATA_END,    0,  0}
};



/*******************************************************
* 名称: TftInit
* 功能: 初始化TFT液晶模块。
* 入口参数: 无
* 出口参数: 无
*******************************************************/
void  TftInit(void)  
{   STCOM_INI  init_dat;
    int  i;
   
    TftReset();
    for(i=0; i<100; i++)		// 设定最多100条初始化命令
    {   init_dat = TFT4137_INI[i];
        if(init_dat.com==DATA_END) break;
      
        TftSendCom(init_dat.com);
        TftSendDat(init_dat.dat);            
        DelaymS(init_dat.dly);      
    }
}



/****************************************************************************
* 名称:GUI_Initialize()
* 功能:初始化GUI,包括初始化显示缓冲区,初始化LCM并清屏。
* 入口参数:无
* 出口参数:无
* 说明:用户根据LCM的实际情况编写此函数。
****************************************************************************/
void  GUI_Initialize(void)
{   TftInit();
    TFT_FillSCR(GUI_CCOLOR);
}


/****************************************************************************
* 名称:GUI_FillSCR()
* 功能:全屏填充。直接使用数据填充显示缓冲区。
* 入口参数:dat		填充的数据
* 出口参数:无
* 说明:用户根据LCM的实际情况编写此函数。
****************************************************************************/
void  GUI_FillSCR(TCOLOR dat)
{   TFT_FillSCR(dat);
}


/****************************************************************************
* 名称:GUI_ClearSCR()
* 功能:清屏。
* 入口参数:无
* 出口参数:无
* 说明:用户根据LCM的实际情况编写此函数。
****************************************************************************/
void  GUI_ClearSCR(void)
{   TFT_FillSCR(GUI_CCOLOR);
}


/****************************************************************************
* 名称:GUI_Point()
* 功能:在指定位置上画点。
* 入口参数:x		指定点所在列的位置
*           y		指定点所在行的位置
*           color	显示颜色
* 出口参数:返回值为1时表示操作成功,为0时表示操作失败。
****************************************************************************/
uint8  GUI_Point(uint16 x, uint16 y, TCOLOR color)
{  /* 参数过滤 */
   if(x>=GUI_LCM_XMAX) return(0);
   if(y>=GUI_LCM_YMAX) return(0);
   
   /* 刷新显示 */
   TftSetWrite(x, y);
   TftSendDat(color);
   
   return(1);
}


/****************************************************************************
* 名称:GUI_ReadPoint()
* 功能:读取指定位置点的颜色数据。
* 入口参数:x		指定点所在列的位置
*           y		指定点所在行的位置
* 出口参数:返回值即是读出值(RRRRRGGGGGGBBBBB)。
****************************************************************************/
uint8  GUI_ReadPoint(uint16 x, uint16 y, TCOLOR *ret)
{  uint16  bak;

   /* 参数过滤 */
   if(x>=GUI_LCM_XMAX) return(0);
   if(y>=GUI_LCM_YMAX) return(0);
   
   /* 读取数据 */
   TftSetAddr(x, y);		// 设置地址
   TftSendCom(WR_RD_DATA);
   bak = TftRcvDat();
   bak = TftRcvDat();      
   *ret = bak;
   
   return(1);
}


/****************************************************************************
* 名称:GUI_HLine()
* 功能:画水平线。
* 入口参数:x0		水平线起点所在列的位置
*           y0		水平线起点所在行的位置
*           x1      水平线终点所在列的位置
*           color	显示颜色
* 出口参数:无
* 说明:操作失败原因是指定地址超出缓冲区范围。
****************************************************************************/
void  GUI_HLine(uint16 x0, uint16 y0, uint16 x1, TCOLOR color) 
{  uint16  bak;

   if(x0>x1) 						// 对x0、x1大小进行排列,以便画图
   {  bak = x1;
      x1 = x0;
      x0 = bak;
   }
      
   GUI_Point(x0, y0, color);		// 显示第一点
   x0++;
   while(x1>=x0)
   {  TftSendDat(color);			// 不断填充并显示
      x0++;
   }
}


/****************************************************************************
* 名称:GUI_RLine()
* 功能:画垂直线。
* 入口参数: x0		垂直线起点所在列的位置
*           y0		垂直线起点所在行的位置
*           y1      垂直线终点所在行的位置
*           color	显示颜色
* 出口参数:无
* 说明:操作失败原因是指定地址超出缓冲区范围。
****************************************************************************/
void  GUI_RLine(uint16 x0, uint16 y0, uint16 y1, TCOLOR color) 
{  uint16  bak;

   if(y0>y1) 						// 对y0、y1大小进行排列,以便画图
   {  bak = y1;
      y1 = y0;
      y0 = bak;
   }
   
   while(y1>=y0)
   {  GUI_Point(x0, y0, color);		// 逐点显示,描出垂直线
      y0++;
   }	
}














⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -