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

📄 lcd.c

📁 ucos_ii在mini2440上的移植KEIL编译环境
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "Lcd.h"

int job1_flag=0;
int job2_flag=0;

//LCD的显示缓冲区,每个颜色占16为
volatile unsigned short gsnLCD_BUFFER[SCR_YSIZE][SCR_XSIZE];
/********************************************************************** 

  *  函数名称: LCD_VideoON 
  
	*  功能描述: 
	*		打开LCD视频和控制信号输出
	*  参数说明
	*	  无
	*  返回值 
	*     无	  
******************************************************************/
void LCD_VideoON()
{
	SET_BIT(LCDCON1, 0);
}


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

  *  函数名称: LCD_VideoOFF 
  
	*  功能描述: 
	*		停止LCD视频和控制信号输出
	*  参数说明
	*	  无
	*  返回值 
	*     无	  
******************************************************************/
void LCD_VideoOFF()
{
	CLR_BIT(LCDCON1, 0);
}

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

  *  函数名称: LCD_PowerON 
  
	*  功能描述: 
	*		打开LCD电源
	*  参数说明
	*	  无
	*  返回值 
	*     无	  
******************************************************************/
void LCD_PowerON()
{
	SET_BIT(LCDCON5, 3);
}


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

  *  函数名称: LCD_PowerOFF 
  
	*  功能描述: 
	*		关闭LCD电源
	*  参数说明
	*	  无
	*  返回值 
	*     无	  
******************************************************************/
void LCD_PowerOFF()
{
	CLR_BIT(LCDCON5, 3);
}

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

  *  函数名称: LCD_Init 
  
	*  功能描述: 
	*		LCD初始化
	*  参数说明
	*	  无
	*  返回值 
	*     无	  
******************************************************************/
void LCD_Init()
{
	//TFT LCD数据和控制端口初始化
	//配置VCLK,VLINE,VFRAME,VM-GPC[4:1]和VD[7:0]-GPC[15:8]
	//禁止GPC[4:1]和GPC上拉,并将他们配置为多功能引脚
	GPCUP |= 0X0000FF1E;
	GPCCON &= 0XFFFF03FC;
	GPCCON |= 0XAAAAFEAB;

	//配置VD[23:8]-GPD[15:0]
	//禁止GPD[15:0]上拉,并将它们配置为多功能引脚
	GPDUP = 0X0000FFFF;
	GPDCON = 0XAAAAAAAA;
	
	//TFT LCD 功能模块初始化
	LCDCON1 = LCDCON1_VAL;
	LCDCON2 = LCDCON2_VAL;
	LCDCON3 = LCDCON3_VAL;
	LCDCON4 = LCDCON4_VAL;
	LCDCON5 = LCDCON5_VAL;
	 	
	//配置LCD显示缓冲区的地址
	LCDSADDR1 = LCD_LCDBANK | LCD_LCDBASEU;
	LCDSADDR2 = LCD_LCDBASEL;
	LCDSADDR3 = LCD_OFFSIZE | LCD_PAGEWIDTH;

 	//将GPG4设置为LCD电源的多功能引脚
	GPGUP = GPGUP | (1 << 4);	//禁止上拉	
	GPGCON = GPGCON | (3 << 8);//GPG4=LCD_PWREN
		
	//配置LCD的中断
	LCDINTMSK = LCD_FIWSEL | LCD_INT_FrSyn | LCD_INT_FiCnt;	
	
	LCD_PowerON();	//打开电源		
	LCD_VideoON();	//打开视频

	//清除LCD的屏幕为黑色
	LCD_ClearScreen(RGB(255,255,255));		
}
/********************************************************************** 

  *  函数名称: LCD_PutPixel 
  
	*  功能描述: 
	*		在LCD上输出一个像素
	*  参数说明
	*	  y、x像素的纵、横坐标 
	*     rgbColor 像素颜色  
	*  返回值 
	*     无	  
******************************************************************/
void LCD_PutPixel(unsigned int y, unsigned int x, RGB_COLOR rgbColor)
{
	if(x < SCR_XSIZE && y < SCR_YSIZE)
	{
		gsnLCD_BUFFER[y][x] = rgbColor;
	}
}

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

  *  函数名称: LCD_ClearScreen 
  
	*  功能描述: 
	*		将屏幕填充成一种颜色rgbColor
	*  参数说明: 
	*     rgbColor 填充颜色  
	*  返回值 
	*     无	  
******************************************************************/
void LCD_ClearScreen(RGB_COLOR rgbColor)
{
	int y, x;
	for(y = 0; y < SCR_YSIZE; y++)
	{
		for(x = 0; x < SCR_XSIZE; x++)
		{
			gsnLCD_BUFFER[y][x] = rgbColor;	
		}
	}

}

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

  *  函数名称: LCD_switch_Screen 
  
	*  功能描述: 
	*		指定屏幕位置填充成一种颜色rgbColor
	*  参数说明: 
	*     rgbColor 填充颜色  
	*  返回值 
	*     无	  
******************************************************************/
void LCD_switch_Screen(int ix,int iy,int ilong,int iwide,RGB_COLOR rgbColor)
{
	int y=0;
	int x=0;
	for(y=0; y < ilong; y++)
	{
		for(x=0; x < iwide; x++)
		{
			gsnLCD_BUFFER[y+iy][x+ix] = rgbColor;	
		}
	}

}

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

  *  函数名称: LCD_DrawLine 
  
	*  功能描述: 
	*		 两点之间画线
	*  参数说明: 
	*     y1、 x1第一点的纵、横坐标   
	*	  y2、 x2第一点的纵、横坐标
	*	  rgbColor 线条的颜色
	*  返回值 
	*     无	  
******************************************************************/
void LCD_DrawLine(
		unsigned int y1, unsigned int x1,
		unsigned int y2, unsigned int x2,
		RGB_COLOR rgbColor)
{
	int dx,dy,e;
	dx=x2-x1; 
	dy=y2-y1;
    
	if(dx>=0)
	{
		if(dy >= 0) // dy>=0
		{
			if(dx>=dy) // 1/8 octant
			{
				e=dy-dx/2;
				while(x1<=x2)
				{
					LCD_PutPixel(y1, x1, rgbColor);
					if(e>0){y1+=1;e-=dx;}	
					x1+=1;
					e+=dy;
				}
			}
			else		// 2/8 octant
			{
				e=dx-dy/2;
				while(y1<=y2)
				{
					LCD_PutPixel(y1, x1, rgbColor);
					if(e>0){x1+=1;e-=dy;}	
					y1+=1;
					e+=dx;
				}
			}
		}
		else		   // dy<0
		{
			dy=-dy;   // dy=abs(dy)

			if(dx>=dy) // 8/8 octant
			{
				e=dy-dx/2;
				while(x1<=x2)
				{
					LCD_PutPixel(y1, x1, rgbColor);
					if(e>0){y1-=1;e-=dx;}	
					x1+=1;
					e+=dy;
				}
			}
			else		// 7/8 octant
			{
				e=dx-dy/2;
				while(y1>=y2)
				{
					LCD_PutPixel(y1, x1, rgbColor);
					if(e>0){x1+=1;e-=dy;}	
					y1-=1;
					e+=dx;
				}
			}
		}	
	}
	else //dx<0
	{
		dx=-dx;		//dx=abs(dx)
		if(dy >= 0) // dy>=0
		{
			if(dx>=dy) // 4/8 octant
			{
				e=dy-dx/2;
				while(x1>=x2)
				{
					LCD_PutPixel(y1, x1, rgbColor);
					if(e>0){y1+=1;e-=dx;}	
					x1-=1;
					e+=dy;
				}
			}
			else		// 3/8 octant
			{
				e=dx-dy/2;
				while(y1<=y2)
				{
					LCD_PutPixel(y1, x1, rgbColor);
					if(e>0){x1-=1;e-=dy;}	
					y1+=1;
					e+=dx;
				}
			}
		}
		else		   // dy<0
		{
			dy=-dy;   // dy=abs(dy)

			if(dx>=dy) // 5/8 octant
			{
				e=dy-dx/2;
				while(x1>=x2)
				{
					LCD_PutPixel(y1, x1, rgbColor);
					if(e>0){y1-=1;e-=dx;}	
					x1-=1;
					e+=dy;
				}
			}
			else		// 6/8 octant
			{
				e=dx-dy/2;
				while(y1>=y2)
				{
					LCD_PutPixel(y1, x1, rgbColor);
					if(e>0){x1-=1;e-=dy;}	
					y1-=1;
					e+=dx;
				}
			}
		}	
	}
}


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

  *  函数名称: LCD_DispCN 
  
	*  功能描述: 
	*		  在LCD上显汉字
	*  参数说明: 
	*     nX 			汉字要在LCD上像素的起始横座标
	*	  nY 			汉字要在LCD上像素的起始纵座标
	*	  pcHZ 			显示汉字的起始地址
	*	  frontColor    前景色
	*	  backColor	    背景色
	*  返回值 
	*     无	  
******************************************************************/
void LCD_DispCN(char *pcHZ, int nY, int nX, RGB_COLOR backColor, RGB_COLOR frontColor)
{
	int nRow = nY;
	int nCol = nX;
	char cArea = pcHZ[0] - 0XA0;
	char cIndex = pcHZ[1] - 0xA0;
	char *pcCharPos = (char *)(HZK16_BASE + ((cArea - 1) * 94 + (cIndex - 1)) * 32);
	int nBit = 0;
	char cCh1;
	char cCh2;	

	while(nRow < nY + 16)
	{
		cCh1 = *pcCharPos;
		cCh2 = *(pcCharPos	+ 1);
		pcCharPos += 2;

  	 	while(nBit < 8)
		{
			if(cCh1 & (1 << (7 - nBit)))
			{
				if(nCol < SCR_XSIZE && nRow < SCR_YSIZE)
				{
					gsnLCD_BUFFER[nRow][nCol] = backColor;
				}
			}
			else
			{
				if(nCol < SCR_XSIZE && nRow < SCR_YSIZE)
				{
					gsnLCD_BUFFER[nRow][nCol] = frontColor;
				}
			}
			nCol++;
			nBit++;
		}
		nBit = 0;

		while(nBit < 8)
		{
			if(cCh2 & (1 << (7 - nBit)))
			{
				gsnLCD_BUFFER[nRow][nCol] = backColor;
			}
			else
			{
				gsnLCD_BUFFER[nRow][nCol] = frontColor;
			}
			nCol++;
			nBit++;			
		}
		nBit = 0;

		nRow++;
		nCol = nX;
	}
}


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

  *  函数名称: LCD_DispEN 
  
	*  功能描述: 
	*		  在LCD上显字符
	*  参数说明: 
	*     nX 			汉字要在LCD上像素的起始横座标
	*	  nY 			汉字要在LCD上像素的起始纵座标
	*	  cASC 			显示字符
	*	  frontColor    前景色
	*	  backColor	    背景色
	*  返回值 
	*     无	  
******************************************************************/
void LCD_DispEN(char cASC, int nY, int nX, RGB_COLOR backColor, RGB_COLOR frontColor)
{
	int nRow = nY;
	int nCol = nX;
	char *pcCharPos = (char *)(ASC16_BASE + (cASC  - 0x20) * 16);
	                                   

	while(nRow < nY + 16)
	{
		int nBit = 0;
		char cCh1 = *pcCharPos;
		pcCharPos++;
	
		while(nBit < 8)
		{
			if(cCh1 & (1 << (7 - nBit)))
			{  	
				if(nCol < SCR_XSIZE && nRow < SCR_YSIZE)
				{
					gsnLCD_BUFFER[nRow][nCol] = backColor;
				}	
			}
			else
			{
				if(nCol < SCR_XSIZE && nRow < SCR_YSIZE)
				{
					gsnLCD_BUFFER[nRow][nCol] = frontColor;
				}

⌨️ 快捷键说明

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