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

📄 lcdconf_7529.c

📁 控制器为ST7529的液晶模块针对ucGUI的驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************Copyright(c)**********************************
**********************************千能电力**************************************
**--------------文件信息---------------------------------------------------
**文   件   名: LCDConf_7529.c
**创   建   人: 杨林军
**创 建 日  期: 2008-4-1
**最 新 版  本: $Id: LCDConf_7529.c,v 1.1.1.5 2008/05/23 06:15:28 yanglinjun Exp $
**描        述: 
**--------------历史版本信息-----------------------------------------------
** 修改人:  杨林军
** 日 期:  
** 版  本: 
** 描 述:  
**-------------------------------------------------------------------------
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#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 "LCDConf_7529.h"
#include "71x_type.h"
#include "bsp_globe.h"
/* Private typedef -----------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
#define SETPIXEL(x, y, c)   _SetPixel(x, y, c)
#define CLRPIXEL(x,y)       _SetPixel(x, y, 0)
#define XORPIXEL(x, y)      //XorPixel(x,y)
#define  COLOR  LCD_COLORINDEX  //LCD_COLORINDEX defined in LCD_Private.h
/* Private variables ---------------------------------------------------------*/
char xbyte[LCDY][LCDX/8];
/* Private functions ---------------------------------------------------------*/
/* Interface functions -------------------------------------------------------*/



/////////////////////LCD初始化//////////////////////////
void LCD_INIT_CONTROLLER(void)
{
    LCD_X_Init();

	LCD_WRITE_A0(ExtModeOff);	// EXT=0

	LCD_WRITE_A0(SleepOut);	// SLEEP OUT
	LCD_WRITE_A0(InternalOscOn);// INTERNAL OSCILLATION ON

	LCD_WRITE_A0(PowerCtrlSet);// POWER CONTROL SET
	LCD_WRITE_A1(0x08);		// TURN ON BOOSTER first;
	DelayMs(10);
	LCD_WRITE_A0(PowerCtrlSet);// POWER CONTROL SET
	LCD_WRITE_A1(0x0b);		// TURN ON BOOSTER AND REFERENCE VOLTAGE GENERATION CIRCUIT ;0bh

	LCD_WRITE_A0(VolumnCtrl);// THREE COMMANDSET REFERENCE VOLTAGE SELECT MODE 
//	LCD_WRITE_A1(0x0a);// REFERENCE VOLTAGE PARAMETER ;16
	LCD_WRITE_A1(0x0a);// REFERENCE VOLTAGE PARAMETER ;16
	LCD_WRITE_A1(0x05);// SET REFERENCE VOLTAGE PARAMETER ;04

	LCD_WRITE_A0(DispCtrl); // DISPLAY CONTROL 
	LCD_WRITE_A1(0x00);// CL DIVIDING RATIO ,F1 AND F2 DRIVE PATTERN
	LCD_WRITE_A1(0x27);// DRIVER DUTY 1/160
	LCD_WRITE_A1(0x1c);// FR INVERSE-SET VALUE 16

	LCD_WRITE_A0(DispInv);// DISPLAY NORMAL

	LCD_WRITE_A0(ComScan); // C0M0-->COM79,C0M159-->COM81
	LCD_WRITE_A1(0x02); 

	LCD_WRITE_A0(DataScanDir); // data scan direction
//	LCD_WRITE_A1(0x00);     //normal mode
//	LCD_WRITE_A1(0x00);     //p1p2p3p1p2p3...
	LCD_WRITE_A1(0x02);     //inverse mode
	LCD_WRITE_A1(0x01);     //p3p2p1...
	LCD_WRITE_A1(0x02);     //3B3P

	LCD_WRITE_A0(LineAddSet); // line address set
	LCD_WRITE_A1(0x00); 
	LCD_WRITE_A1(0x9f); 

	LCD_WRITE_A0(ColumnAddSet);// THIRDCOMMAND SET COLUMN ADDRESS 
//	LCD_WRITE_A1(0x00);// START COLUMN
//	LCD_WRITE_A1(0x35);// ENDCOLUMN
	LCD_WRITE_A1(0x1f);// START COLUMN 31
	LCD_WRITE_A1(0x54);// ENDCOLUMN 84

	LCD_WRITE_A0(ExtModeOn); // EXT=1

	//==================================================== 
	LCD_WRITE_A0(SetGray1);// SET GRAY VALUE

	LCD_WRITE_A1(0X00);// START PARA00
	LCD_WRITE_A1(0X03);// START PARA03 
	LCD_WRITE_A1(0X06);// START PARA06
	LCD_WRITE_A1(0X09);// START PARA09

	LCD_WRITE_A1(0X0B);// START PARA
	LCD_WRITE_A1(0X0D);// START PARA
	LCD_WRITE_A1(0X0E);// START PARA 
	LCD_WRITE_A1(0X0F);// START PARA
	 
	LCD_WRITE_A1(0X10);// START PARA
	LCD_WRITE_A1(0X11);// START PARA
	LCD_WRITE_A1(0X12);// START PARA 
	LCD_WRITE_A1(0X14);// START PARA

	LCD_WRITE_A1(0X16);// START PARA
	LCD_WRITE_A1(0X18);// START PARA
	LCD_WRITE_A1(0X1B);// START PARA 
	LCD_WRITE_A1(0X1F);// START PARA

	LCD_WRITE_A0(SetGray2);// SET GRAY VALUE

	LCD_WRITE_A1(0X00);// START PARA00
	LCD_WRITE_A1(0X03);// START PARA03 
	LCD_WRITE_A1(0X06);// START PARA06
	LCD_WRITE_A1(0X09);// START PARA09

	LCD_WRITE_A1(0X0B);// START PARA
	LCD_WRITE_A1(0X0D);// START PARA
	LCD_WRITE_A1(0X0E);// START PARA 
	LCD_WRITE_A1(0X0F);// START PARA
	 
	LCD_WRITE_A1(0X10);// START PARA
	LCD_WRITE_A1(0X11);// START PARA
	LCD_WRITE_A1(0X12);// START PARA 
	LCD_WRITE_A1(0X14);// START PARA

	LCD_WRITE_A1(0X16);// START PARA
	LCD_WRITE_A1(0X18);// START PARA
	LCD_WRITE_A1(0X1B);// START PARA 
	LCD_WRITE_A1(0X1F);// START PARA

	LCD_WRITE_A0(AnalogCircuitSet);// ANALOG CIRCUIT SET 
	LCD_WRITE_A1(0x00);// OSC FREQUENCEY ADJUSTMENT 0~3 -> 12.7Khz ~ 25Khz
	LCD_WRITE_A1(0x03);// BOOSTER EFFICIENCY SET	0~3 -> 3,6,12,24Khz
	LCD_WRITE_A1(0x01);// BIAS SETTING 0~7 -> 1/14,1/13,1/12,1/11,1/10,1/9,1/7,1/5

	LCD_WRITE_A0(SoftInit);// DITHERER OFF

	LCD_WRITE_A0(ExtModeOff); // EXT=0
	LCD_WRITE_A0(DispOn); // display on;

	//=====================================================  
}

/*******************************************************************************
* Function Name  : _SetPixel
* Description    : 画点函数
* Input          : 
* Return         : None
* note : 该函数扇入很高很高,要非常重视优化,最好用汇编重写
*******************************************************************************/
void _SetPixel(int x, int y, LCD_PIXELINDEX c)          //画点函数 
{
    unsigned char bx,i;
    unsigned char temp[3];
	bx = (x+95)%3;	
	SetWindow(x,y,159,159);
	LCD_WRITE_A0(ReadModifyWriteOn);//DATA WRITE 
		LCD_READ_A1;		//dummy read
	for(i=0;i<3;++i)
		temp[i]=LCD_READ_A1;
	for(i=0;i<3;++i)
	{
		if(i==bx)
			LCD_WRITE_A1(c);
		else
			LCD_WRITE_A1(temp[i]);
	}

	LCD_WRITE_A0(ReadModifyWriteOff);//DATA WRITE 
}

void SetWindow(short x, short y, short x1, short y1)
{
    short z;
	if(y > y1)
	{
		z = y;
		y = y1;
		y1 = z;
	}
	if(x > x1)
	{
		z = x;
		x = x1;
		x1 = z;
	}
	LCD_WRITE_A0(LineAddSet); // line address set
	LCD_WRITE_A1(y); 
	LCD_WRITE_A1(y1);

	LCD_WRITE_A0(ColumnAddSet);// THIRDCOMMAND SET COLUMN ADDRESS 

	LCD_WRITE_A1((95+x)/3);// 起始列,从第95个SEG开始
	LCD_WRITE_A1((95+x1)/3);// 终止列,从第95个SEG开始
	return;
}

void LCD_ClearScreen(void)
{
    short i,j;

	SetWindow(0,10,159,159);
	LCD_WRITE_A0(MemWrite);//DATA WRITE 
	//LCD_WRITE_A0(MemRead);
    for(j=0;j<160;++j)
	{
		LCD_WRITE_A1(0x00); //写每行前两个seg
		LCD_WRITE_A1(0x00);
        //LCD_READ_A1;
        //LCD_READ_A1;
		for(i=0;i<40;++i)
		{
			LCD_WRITE_A1(0x00);
            LCD_WRITE_A1(0x00);
            LCD_WRITE_A1(0x00);
            LCD_WRITE_A1(0x00);
		}
	}
    
}



//*************************************************************
//              ****以下是根据内存内容区域刷新函数****
//*************************************************************
void SetPix(short x, short y)
{	
	if((x > (LCDX - 1)) || (y > (LCDY - 1)))
		return;
	xbyte[y][x/8] |= 0x80 >> (x%8);   //写数组
}
void ClrPix(short x, short y)
{
	if((x > (LCDX - 1)) || (y > (LCDY - 1)))
		return;
		xbyte[y][x/8] &= (~(0x80 >> (x%8)));//写数组
}
void Up_Pix(const short x,const short y)
{
char byte_t;
	byte_t=x%8;
	if((xbyte[y][x/8]>>(7-byte_t)) & 0x01)//根据数组内容刷新固定坐标点
	{
		LCD_WRITE_A1(0xff);
	}
	else
	    LCD_WRITE_A1(0x00);
}

void Up_HLine(const char x1,const char y1,const char w)
{
char bx,ax,n,x_t;
char temp[3];
char i,j;
	x_t=x1;
	bx = (95+x1)%3;	
	ax = (95+x1+w)%3;	
	if(bx)
		n = (w - ax - (3 - bx))/3;
	else
		n = (w - ax)/3;
	
	SetWindow(x1,y1,x1+w-1,159);
	
	LCD_WRITE_A0(ReadModifyWriteOn);//DATA WRITE 
	if(bx)
	{
		LCD_READ_A1;		//dummy read
		for(i=0;i<3;++i)
			temp[i]=LCD_READ_A1;
		for(i=0;i<bx;++i)
			LCD_WRITE_A1(temp[i]);
		for(i=0;i<3-bx;++i)
		{
			Up_Pix(x_t,y1);
			x_t++;
		}
	}
	for(i=0;i<n;++i)
	{
		LCD_READ_A1;
		LCD_READ_A1;
		LCD_READ_A1;
		LCD_READ_A1;
		for(j=0;j<3;++j)
		{
			Up_Pix(x_t,y1);
			x_t++;
		}
	}
	if(ax)
	{
		LCD_READ_A1;		//dummy read
		for(i=0;i<3;++i)
			temp[i]=LCD_READ_A1;
		for(i=0;i<ax;++i)
		{
			Up_Pix(x_t,y1);
			x_t++;
		}
		for(i=0;i<3-ax;++i)
			LCD_WRITE_A1(temp[ax+i]);
	}
	LCD_WRITE_A0(ReadModifyWriteOff);//DATA WRITE 
}

void UpAreaLcd(const short x, const short y, const short x1, const short y1)
{	
short n;
	for(n=y;n<y1;++n)
	{
		Up_HLine(x,n,x1-x+1);
	}
}
void Up_Lcd()
{
	short i,j;
	short n;
	SetWindow(0,0,LCDX-1,LCDY-1);
	LCD_WRITE_A0(MemWrite);//DATA WRITE

	for(j=0;j<LCDY;++j)
	{
		LCD_WRITE_A1(0x00);
		LCD_WRITE_A1(0x00);
		for(i=0;i<LCDX/8;++i) 
		{	
			for(n=0;n<8;++n)
			{
				if(xbyte[j][i] & (0x80>>n))
				{
					LCD_WRITE_A1(0xff);					
				}					
				else
				{				
					LCD_WRITE_A1(0x00);
				}				
			}
		}
	}
}





//*************************************************************
//              ****以下是液晶物理操作函数****
//*************************************************************
void LCD_SetPix(int x,int y)
{

}

void LCD_ClrPix(int x,int y)
{
unsigned char bx,i;
unsigned char temp[3];
	bx = (x+95)%3;	
	SetWindow(x,y,159,159);
	LCD_WRITE_A0(ReadModifyWriteOn);//DATA WRITE 
		LCD_READ_A1;		//dummy read
	for(i=0;i<3;++i)
		temp[i]=LCD_READ_A1;
	for(i=0;i<3;++i)
	{
		if(i==bx)
			LCD_WRITE_A1(0x00);
		else
			LCD_WRITE_A1(temp[i]);
	}		
	LCD_WRITE_A0(ReadModifyWriteOff);//DATA WRITE
}

void LCD_HLine(char x1,char y1,char w)
{
    char bx,ax,n;
    char temp[3];
    char i;
   char pixelIndex;
   
    if (GUI_Context.DrawMode == GUI_DRAWMODE_NORMAL)     //正常模式
    {
        pixelIndex = 0xFF;
    }
    else if(GUI_Context.DrawMode & GUI_DRAWMODE_REV)    //翻转模式
    {
        pixelIndex = 0x00;
    }

	bx = (95+x1)%3;
	ax = (95+x1+w)%3;	
	if(bx)
		n = (w - ax - (3 - bx))/3;
	else
		n = (w - ax)/3;
	
	SetWindow(x1,y1,x1+w-1,159);
	
	LCD_WRITE_A0(ReadModifyWriteOn);//DATA WRITE 
	if(bx)	
	{
		LCD_READ_A1;		//dummy read
		for(i=0;i<3;++i)
			temp[i]=LCD_READ_A1;
		for(i=0;i<bx;++i)
			LCD_WRITE_A1(temp[i]);
		for(i=0;i<3-bx;++i)
			LCD_WRITE_A1(pixelIndex);
	}
	for(i=0;i<n;++i)
	{
		LCD_READ_A1;
		LCD_READ_A1;
		LCD_READ_A1;
		LCD_READ_A1;
		LCD_WRITE_A1(pixelIndex);
		LCD_WRITE_A1(pixelIndex);
		LCD_WRITE_A1(pixelIndex);
	}
	if(ax)
	{
		LCD_READ_A1;		//dummy read
		for(i=0;i<3;++i)
			temp[i]=LCD_READ_A1;
		for(i=0;i<ax;++i)
			LCD_WRITE_A1(pixelIndex);
		for(i=0;i<3-ax;++i)
			LCD_WRITE_A1(temp[ax+i]);
	}
	LCD_WRITE_A0(ReadModifyWriteOff);//DATA WRITE 
}

void LCD_VLine(int x1,int y1,int y2)
{
    int i;
    int z;
	if(y1 > y2)
	{
		z = y2;
		y2 = y1;
		y1 = z;
	}
	for(i=y1;i<y2+1;++i)
		LCD_SetPix(x1,i);
}


#if 0
//*************************************************************
//              ****以下是内存绘图函数****
//*************************************************************
void DrawHPixLine(short x1,short y,short x2)
{
    short i;
    short z;

	if(x1 > x2)
	{
		z = x2;
		x2 = x1;
		x1 = z;
	}
	for(i=x1;i<x2+1;++i)
		SetPix(i,y);
}

void DrawVPixLine(short x,short y1,short y2)
{
    short i;
    short z;

	if(y1 > y2)
	{
		z = y2;
		y2 = y1;
		y1 = z;
	}

	for(i=y1;i<y2+1;++i)
		SetPix(x,i);	
}

void  DrawRect(short x0, short y0, short x1, short y1)
{
   DrawHPixLine(x0, y0, x1);  
   DrawHPixLine(x0, y1, x1);
   DrawVPixLine(x0, y0, y1);
   DrawVPixLine(x1, y0, y1);
   Up_Lcd();   
}

void  DrawRectFill(short x0, short y0, short x1, short y1)
{
	short  z;

   if(x0>x1) 						// 若x0>x1,则x0与x1交换
   {  z = x0;
      x0 = x1;
      x1 = z;
   }
   if(y0>y1)						// 若y0>y1,则y0与y1交换
   {  z = y0;
      y0 = y1;
      y1 = z;
   }
   

   if(y0==y1) 
   {
      DrawHPixLine(x0, y0, x1);
      return;
   }

⌨️ 快捷键说明

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