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

📄 lcdconf_7529.c

📁 ST7529液晶驱动 The ST7529 is a driver & controller LSI for 32 gray scale graphic dot-matrix liquid cryst
💻 C
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------
File        : LCDConf_7529.c
Purpose     : configuration file
Author      : 陈伟文
Data        : 2007.2.8
----------------------------------------------------------------------
*/


/*
注意:
1  我是用16灰度的例子修改而成的,而在实际应用中只用到了5个灰度,故在用前景色画图时,
   我是把0~15的索引值转换为我要用到的5个灰度.
2  我是用一个16位数画3个点的模式的,如果用其他模式的需要修改部分代码.
3  在画位图的4个函数中,我只优化了画8位那个,1,2,4位的还未优化

*/
#include <string.h>                             /* for memset */
#include <stddef.h>                             /* needed for definition of NULL */
#include "LCD_Private.h"                        /* private modul definitions & config */
#include "GUI_Private.h"
#include "GUIDebug.h"
#include "config.h"
#include "LCDConf_7529.h"

#ifndef LCDCONF_H
#define LCDCONF_H
#endif
#define  UART_BPS	115200			            // 定义通讯波特率

#define TRUE  1
#define FALSE 0

#define WIN32                1
#define LCD_OPTIMIZE         0

#define  PixelIndex  uint8

#define LOG2PHYS(x,y) x,y
#define SETPIXEL(x, y, c)   _SetPixel(x, y, c)
#define GETPIXEL(x, y)      _GetPixel(x,y)
#define XORPIXEL(x, y)      XorPixel(x,y)
#define LCD_ON()            LCD_WRITE_A1(0xAF)
#define LCD_OFF()           LCD_WRITE_A1(0xAE)
  
  
uint16 ScanBuff[LCD_YSIZE][LCD_XSIZE/3+1];      //用作显示缓存,使得不用从液晶控制器读回数据
 
 
 void  UART0_Init(void)
{  
    uint16 Fdiv;

    U0LCR = 0x83;						       // DLAB = 1,可设置波特率
    Fdiv = (Fpclk / 16) / UART_BPS;		       // 设置波特率
    U0DLM = Fdiv / 256;							
    U0DLL = Fdiv % 256;						
    U0LCR = 0x03;
}

void  UART0_SendByte(uint8 data)
{  
    U0THR = data;				    	   // 发送数据
    
    while( (U0LSR&0x40)==0 );	    	   // 等待数据发送完毕
} 

void UART0_SendStr(INT8U const *str)
{    
    while(1)
    {    
        if( *str == '\0' ) break;   
        UART0_SendByte(*str++);	    	   // 发送数据
    }
}

void OutPutOneByte(INT8U i)
{
    if(i/16>9)UART0_SendByte(i/16+55);
	else UART0_SendByte(i/16+48);
	if(i%16>9)UART0_SendByte(i%16+55);
	else UART0_SendByte(i%16+48);
}


/*********************************************************************
*
*       Initialisation macro
*
**********************************************************************
*/

void LCD_WRITE_A0(uint16 dat)
{
   LCDDAT = dat;
}

void LCD_WRITE_A1(uint16 dat)
{
   LCDCOM = dat;
}

int LCD_READ_A0(void)
{
    uint16 dat;
    dat = LCDDAT;
    return dat;
}

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

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

/*******************************************************
* 名称: LcdSetAddr
* 功能: 设置数据地址指针(坐标值)。
* 入口参数: x1		起始横坐标的值 (0-158)
*           y1      起始纵坐标的值 (0-158)
*           x2		结束横坐标的值 (1-159)
*           y2      结束纵坐标的值 (1-159)
* 出口参数: 设置正确返回TRUE,参数超出范围返回FALSE
*******************************************************/
uint8  LcdSetAddr(uint16 x1, uint16 y1, uint16 x2, uint16 y2)
{  
   
   LCD_WRITE_A1(LASET);		                // 设置地址高8位
   LCD_WRITE_A0(y1);
   LCD_WRITE_A0(y2);
   
   LCD_WRITE_A1(CASET);		                // 设置地址低8位
   LCD_WRITE_A0(x1/3);
   LCD_WRITE_A0(x2/3);
   
   if((x2<160) && (y2<160)) return(TRUE);
     else  return(FALSE);
}


/*******************************************************
* 名称: LcdSetWrite
* 功能: 设置数据地址指针(坐标值),并发送写数据命令。
*       接着不断的写入数据即可,GRAM地址会自动增加。
* 入口参数: x		横坐标的值 (0-159)
*           y       纵坐标的值 (0-159)
* 出口参数: 设置正确返回TRUE,参数超出范围返回FALSE
*******************************************************/
uint8  LcdSetWrite(uint16 x1, uint16 y1, uint16 x2, uint16 y2)
{  
   uint8  ret;

   ret = LcdSetAddr(x1, y1, x2, y2);
   LCD_WRITE_A1(RAMWR);		                // 写数据
   return(ret);
}


/*******************************************************
* 名称: ReadEEPROM
* 功能: 读取EEPROM数据。
* 入口参数: 无
* 出口参数: 无
*******************************************************/
void ReadEEPROM(void)
{
     LCDCOM = ExtIn;
     LCDCOM = EPINT;
     LCDDAT = 0x0019;
     
     LCDCOM = ExtOut;
     LCDCOM = EPCTIN;
     LCDDAT = 0x0000;
     
     DelaymS(100);//100ms
     
     LCDCOM = EPMRD;
     DelaymS(100);//100ms
     
     LCDCOM = EPCOUT;
     LCDCOM = ExtIn;
} 

/*******************************************************
* 名称: LCD_INIT_CONTROLLER
* 功能: 初始化液晶模块。
* 入口参数: 无
* 出口参数: 无
*******************************************************/

void LCD_INIT_CONTROLLER()   
{   
    U8 i, j;
    
    UART0_Init();
    
                                                       
    LCDCOM = ExtIn;
    LCDCOM = SLPOUT;                          //SLEEP OUT
    LCDCOM = OSCON;                           //OSC ON
    LCDCOM = PWRCTRL;                         //POWER CONTROL SET
    LCDDAT = 0x0008;
    DelaymS(1);                               //1MS
    
    LCDCOM = PWRCTRL;
    LCDDAT = 0x000B;
    
    LCDCOM = VOLCTRL;                         //ELECTRONIC CONTROL
    LCDDAT = 0x0000;
    LCDDAT = 0x0005;
    
    LCDCOM = DISCTRL;                         //DISPALY CONTROL           
    LCDDAT = 0x0000;
    LCDDAT = 0x0027;
    LCDDAT = 0x0000;
    
    LCDCOM = DISNOR;                          //NORMAL DISPALY
    
    LCDCOM = COMSCN;                          //COM SCAN DIRECTION
    LCDDAT = 0x0001;
    
    LCDCOM = DATSDR;                          //DATA SCAN DIRECTION
    LCDDAT = 0x0001;
    LCDDAT = 0x0000;
    LCDDAT = 0x0001;
    
    LCDCOM = LASET;                           //LINE ADDRESS SET
    LCDDAT = 0x0000;
    LCDDAT = 0x009F;
    
    LCDCOM = CASET;                           //COLUMN ADDRESS SET
    LCDDAT = 0x0000;
    LCDDAT = 0x0036;
    
    LCDCOM = ExtOut;
    
    LCDCOM = ANASET;                          //ANALOG CIRCUIT SET
    LCDDAT = 0x0000;
    LCDDAT = 0x0002;
    LCDDAT = 0x0001;
    
    LCDCOM = SWINT;                           //SOFTWARE INITIAL
    
    ReadEEPROM();                             //READ EEPROM FLOW
    
    LCDCOM = ExtIn;
    
    LCDCOM = DISON;                           //DISPLAY ON
    
    for(i=0;i<LCD_YSIZE;i++)                  //初始化显示缓冲区,0xffff为全白色
       {
           for(j=0;j<LCD_XSIZE/3+1;j++)
               ScanBuff[i][j] = 0xffff;
       }  
    
}


/***************************************************************************************/
 void _SetPixel(int x, int y, LCD_PIXELINDEX c)          //画点函数 
{
    uint8 colour;
    uint16 temp = ScanBuff[y][x/3];                      //根据上层传过来的灰度索引参数C转换为液晶相应的灰度
    
    if(c == 0)colour = 0;                                //索引值转换
    else if((c > 0) && (c <= 5))colour = 0x08;
    else if((c > 5) && (c <= 10))colour = 0x10;
    else if((c > 10) && (c < 15))colour = 0x18;
    else colour = 0x1f;
    
    switch(x%3)
    {
        case 0:ScanBuff[y][x/3] = (temp & 0x07ff) | (uint16)(colour << 11);break;
        case 1:ScanBuff[y][x/3] = (temp & 0xf83f) | (uint16)(colour << 6);break;
        case 2:ScanBuff[y][x/3] = (temp & 0xffc0) | (colour);break;
        default:break;
    }
    LcdSetWrite( x, y, x+3, y+1);
    LCD_WRITE_A0(ScanBuff[y][x/3]);
}

/***************************************************************************************/
unsigned int _GetPixel(int x, int y)                      //取点函数
{
    int temp = ScanBuff[y][x/3];
    switch(x%3)
    {
        case 0:temp = ((temp & 0xf800) >> 11);break;
        case 1:temp = ((temp & 0x07c0) >> 6);break;
        case 2:temp = (temp & 0x001f);break;
        default:break;
    }
    return (uint8)temp;
}

/***************************************************************************************/
 void XorPixel(int x, int y)                              //异或函数
{
    uint16 temp1, temp = ScanBuff[y][x/3];
    switch(x%3)
    {
        case 0:temp1 = ((temp & 0xf800) >> 11);break;
        case 1:temp1 = ((temp & 0x07c0) >> 6);break;
        case 2:temp1 = (temp & 0x001f);break;
        default:break;
    }
    temp1 = 0x1f - temp1;
    switch(x%3)
    {
        case 0:temp = ((temp & 0x07ff) | (temp1 << 11));break;
        case 1:temp = ((temp & 0xf83f) | (temp1 << 6));break;
        case 2:temp = ((temp & 0xffe0) | temp1);break;
        default:break;
    }
    ScanBuff[y][x/3] = temp;
    LcdSetWrite( x, y, x+3, y+1);
    LCD_WRITE_A0(temp);
    
}

/***************************************************************************************/

void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex)   //上层调用的画点函数
{
     SETPIXEL(x, y, PixelIndex);
}


/***************************************************************************************/
unsigned int LCD_L0_GetPixelIndex(int x, int y)           //上层调用的取点函数
{
     unsigned int temp;
     temp = GETPIXEL(x, y);
     return (temp);
}


/***************************************************************************************/
void LCD_L0_XorPixel(int x, int y)                       //上层调用的异或函数
{
     XORPIXEL(x, y);
}


/***************************************************************************************/
uint16 Xor_Pixel(uint16 Pixel)                           //异或三个点(16位)的子函数
{
    uint8 P0,P1,P2;
    P0 = 0x1f - ((Pixel & 0xf800) >> 11);
    P1 = 0x1f - ((Pixel & 0x07c0) >> 6);
    P2 = 0x1f - (Pixel & 0x001f);
    return ((P0 << 11) | (P1 << 6) | P2);
}

/***************************************************************************************/

void LCD_L0_DrawHLine (int x0, int y,  int x1)           //上层调用的画横线函数
{
  uint8 remainder_x0 = x0%3;
  uint8 remainder_x1 = x1%3;
  
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)                          //反转模式
  {
      
      uint16 temp;
      uint8 i, P1, P2;
      if((remainder_x0 == 0) && (remainder_x1 == 2))                    //开始和结束的像素都是3的倍数
      {
           while (x0 <= x1) 
           {
               ScanBuff[y][x0/3] = Xor_Pixel(ScanBuff[y][x0/3]);
               x0+=3;
           }
           LCDCOM = ExtIn;
           LcdSetWrite( x0, y, x1, y+1);
           for(i = x0; i < x1; i+=3)
           LCD_WRITE_A0(ScanBuff[y][i/3]);
      }
      else if((remainder_x0 != 0) && (remainder_x1 == 2))               //开始的像素不是3的倍数
      {    
          temp = ScanBuff[y][x0/3];
          switch(remainder_x0)
          {
               case 1:P1 = 0x1f - ((temp & 0x07c0) >> 6);
                      P2 = 0x1f - (temp & 0x001f);
                      ScanBuff[y][x0/3] = (temp & 0xf800) | (P1 << 6) | P2;
                      break;
               case 2:P2 = 0x1f - (temp & 0x001f);
                      ScanBuff[y][x0/3] = (temp & 0xffc0) | P2;
                      break;
               default:break;
          }
          while ((x0 + 3) <= x1) 
          {
               ScanBuff[y][x0/3 + 1] = Xor_Pixel(ScanBuff[y][x0/3]);
               x0+=3;
          }
          LCDCOM = ExtIn;
          LcdSetWrite( x0, y, x1, y+1);
          for(i = x0; i < x1; i+=3)
          LCD_WRITE_A0(ScanBuff[y][i/3]);
     }
     else if((remainder_x0 == 0) && (remainder_x1 != 2))               //结束的像素不是3的倍数
     {    
          temp = ScanBuff[y][x1/3];
          switch(remainder_x1)
          {     
               case 0:P1 = 0x1f - ((temp & 0xf800) >> 11);
                      ScanBuff[y][x1/3] = (temp &0x07ff) | (P1 << 11);
                      break;
               case 1:P1 = 0x1f - ((temp & 0xf800) >> 11);
                      P2 = 0x1f - (temp & 0x07c0 >> 6);
                      ScanBuff[y][x1/3] = (temp & 0x001f) | (P1 << 11) | (P2 << 6);
                      break;
               default:break;
          }
          while (x0 <= (x1 - 3)) 
          {
               ScanBuff[y][x0/3] = Xor_Pixel(ScanBuff[y][x0/3 - 1]);
               x0+=3;
          }
          LCDCOM = ExtIn;
          LcdSetWrite( x0, y, x1, y+1);
          for(i = x0; i < x1; i+=3)
          LCD_WRITE_A0(ScanBuff[y][i/3]);
     }
     else                                             //开始和结束的像素不都是3的倍数
     {
          temp = ScanBuff[y][x0/3];     
          switch(remainder_x0)
          {
               case 1:P1 = 0x1f - ((temp & 0x07c0) >> 6);
                      P2 = 0x1f - (temp & 0x001f);
                      ScanBuff[y][x0/3] = (temp & 0xf800) | (P1 << 6) | P2;
                      break;
               case 2:P2 = 0x1f - (temp & 0x001f);
                      ScanBuff[y][x0/3] = (temp & 0xffc0) | P2;
                      break;
               default:break;
          }
          temp = ScanBuff[y][x1/3];
          switch(remainder_x1)
          {     
               case 0:P1 = 0x1f - ((temp & 0xf800) >> 11);
                      ScanBuff[y][x1/3] = (temp &0x07ff) | (P1 << 11);
                      break;
               case 1:P1 = 0x1f - ((temp & 0xf800) >> 11);
                      P2 = 0x1f - (temp & 0x07c0 >> 6);
                      ScanBuff[y][x1/3] = (temp & 0x001f) | (P1 << 11) | (P2 << 6);
                      break;
               default:break;
          } 
          while ((x0 + 3) <= (x1 - 3)) 
          {
               ScanBuff[y][x0/3 + 1] = Xor_Pixel(ScanBuff[y][x0/3 - 1]);
               x0+=3;

⌨️ 快捷键说明

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