#include "SmartM_M0.h"
STATIC UINT32 g_unFontPos =LCD_FONT_IN_SD ;
STATIC UINT32 g_unLcdDirection=LCD_DIRECTION_180;
/****************************************
*函数名称:LcdWriteBus
*输 入:VH -高8位数据
VL -低8位数据
*输 出:无
*功 能:Lcd并行数据传输
******************************************/
VOID LcdWriteBus(UINT8 VH,UINT8 VL) //并行数据写入函数
{
LCD_DATAPORT_L=VL;
LCD_DATAPORT_H=VH;
LCD_WR(0);
NOP();NOP();NOP();NOP();
LCD_WR(1);
}
/****************************************
*函数名称:LcdWriteCmd
*输 入:VH -高8位数据
VL -低8位数据
*输 出:无
*功 能:Lcd写命令
******************************************/
VOID LcdWriteCmd(UINT8 VH,UINT8 VL) //发送命令-8位参数
{
LCD_RS(0);
NOP();NOP();NOP();NOP();
LcdWriteBus(VH,VL);
}
/****************************************
*函数名称:LcdWriteCmd
*输 入:VH -高8位数据
VL -低8位数据
*输 出:无
*功 能:Lcd写数据
******************************************/
VOID LcdWriteData(UINT8 VH,UINT8 VL) //发送数据-8位参数
{
LCD_RS(1);
NOP();NOP();NOP();NOP();
LcdWriteBus(VH,VL);
}
/****************************************
*函数名称:LcdWriteCmdData
*输 入:VH -高8位数据
VL -低8位数据
*输 出:无
*功 能:Lcd写数据
******************************************/
VOID LcdWriteCmdData(UINT32 cmd,UINT32 val) //发送数据命令
{
LcdWriteCmd(cmd>>8,cmd);
LcdWriteData(val>>8,val);
}
/****************************************
*函数名称:LcdAddressSet
*输 入:x1 -横坐标1
y1 -纵坐标1
x2 -横坐标2
y2 -纵坐标2
*输 出:无
*功 能:Lcd显示地址
******************************************/
VOID LcdAddressSet(UINT32 x1,UINT32 y1,UINT32 x2,UINT32 y2)
{
UINT16 Lcd_x1=x1,Lcd_y1=y1,Lcd_x2=x2,Lcd_y2=y2;
/* 检测屏幕是否翻转180度 */
if(g_unLcdDirection == LCD_DIRECTION_180)
{
Lcd_x1=LCD_WIDTH-x2;
Lcd_x2=LCD_WIDTH-x1;
Lcd_y1=LCD_HEIGHT-y2;
Lcd_y2=LCD_HEIGHT-y1;
}
LcdWriteCmd(0x00,0x20);LcdWriteData(Lcd_x1>>8,Lcd_x1);//设置X坐标位置
LcdWriteCmd(0x00,0x21);LcdWriteData(Lcd_y1>>8,Lcd_y1);//设置Y坐标位置
LcdWriteCmd(0x00,0x50);LcdWriteData(Lcd_x1>>8,Lcd_x1);//开始X
LcdWriteCmd(0x00,0x52);LcdWriteData(Lcd_y1>>8,Lcd_y1);//开始Y
LcdWriteCmd(0x00,0x51);LcdWriteData(Lcd_x2>>8,Lcd_x2);//结束X
LcdWriteCmd(0x00,0x53);LcdWriteData(Lcd_y2>>8,Lcd_y2);//结束Y
LcdWriteCmd(0x00,0x22);
}
/****************************************
*函数名称:LcdCleanScreen
*输 入:usColor -颜色
*输 出:无
*功 能:Lcd清屏
******************************************/
VOID LcdCleanScreen(UINT16 usColor)
{
UINT32 i,j;
LcdAddressSet(0,0,239,319);
for(i=0;i<320;i++)
{
for (j=0;j<240;j++)
{
LcdWriteData(usColor>>8,usColor);
}
}
}
/****************************************
*函数名称:LcdInit
*输 入:unFontPos -字符存储位置
unLcdDirection -显示方向
*输 出:无
*功 能:Lcd初始化
******************************************/
VOID LcdInit(UINT32 unFontPos,UINT32 unLcdDirection)
{
g_unLcdDirection = unLcdDirection;
g_unFontPos = unFontPos;
P0_PMD = 0x5555;
P2_PMD = 0x5555;
/*
P4.4-Lcd cs pin
P4.5-Lcd rs pin
*/
P4_PMD &=~((3<<8)|(3<<10));
P4_PMD |= (1<<8)|(1<<10);
LCD_RS(1);
LCD_CS(0);
/* P3.6-Lcd wr
P3.7-Lcd rd
*/
P3_PMD &=~((3<<12)|(3<<14));
P3_PMD |= (1<<12)|(1<<14);
LCD_WR(1);
LCD_RD(1);
/* P4.3-Lcd led pin */
P4_PMD &=~(3<<6);
P4_PMD |= (1<<6);
LCD_BL(0);
Delayms(100);
LcdWriteCmdData(0x0001,0x0100); Delayms(1);
LcdWriteCmdData(0x0002,0x0700); Delayms(1);
LcdWriteCmdData(0x0003,0x1030); Delayms(1);
LcdWriteCmdData(0x0004,0x0000); Delayms(1);
LcdWriteCmdData(0x0008,0x0207); Delayms(1);
LcdWriteCmdData(0x0009,0x0000); Delayms(1);
LcdWriteCmdData(0x000A,0x0000); Delayms(1);
LcdWriteCmdData(0x000C,0x0000); Delayms(1);
LcdWriteCmdData(0x000D,0x0000); Delayms(1);
LcdWriteCmdData(0x000F,0x0000); Delayms(1);
LcdWriteCmdData(0x0010,0x0000); Delayms(1);
LcdWriteCmdData(0x0011,0x0007); Delayms(1);
LcdWriteCmdData(0x0012,0x0000); Delayms(1);
LcdWriteCmdData(0x0013,0x0000); Delayms(1);
LcdWriteCmdData(0x0010,0x1290); Delayms(1);
LcdWriteCmdData(0x0011,0x0227); Delayms(1);
LcdWriteCmdData(0x0012,0x001d); Delayms(1);
LcdWriteCmdData(0x0013,0x1500); Delayms(1);
LcdWriteCmdData(0x0029,0x0018); Delayms(1);
LcdWriteCmdData(0x002B,0x000D); Delayms(1);
LcdWriteCmdData(0x0030,0x0004); Delayms(1);
LcdWriteCmdData(0x0031,0x0307); Delayms(1);
LcdWriteCmdData(0x0032,0x0002); Delayms(1);
LcdWriteCmdData(0x0035,0x0206); Delayms(1);
LcdWriteCmdData(0x0036,0x0408); Delayms(1);
LcdWriteCmdData(0x0037,0x0507); Delayms(1);
LcdWriteCmdData(0x0038,0x0204); Delayms(1);
LcdWriteCmdData(0x0039,0x0707); Delayms(1);
LcdWriteCmdData(0x003C,0x0405); Delayms(1);
LcdWriteCmdData(0x003D,0x0F02); Delayms(1);
LcdWriteCmdData(0x0050,0x0000); Delayms(1);
LcdWriteCmdData(0x0051,0x00EF); Delayms(1);
LcdWriteCmdData(0x0052,0x0000); Delayms(1);
LcdWriteCmdData(0x0053,0x013F); Delayms(1);
LcdWriteCmdData(0x0060,0xA700); Delayms(1);
LcdWriteCmdData(0x0061,0x0001); Delayms(1);
LcdWriteCmdData(0x006A,0x0000); Delayms(1);
LcdWriteCmdData(0x0080,0x0000); Delayms(1);
LcdWriteCmdData(0x0081,0x0000); Delayms(1);
LcdWriteCmdData(0x0082,0x0000); Delayms(1);
LcdWriteCmdData(0x0083,0x0000); Delayms(1);
LcdWriteCmdData(0x0084,0x0000); Delayms(1);
LcdWriteCmdData(0x0085,0x0000); Delayms(1);
LcdWriteCmdData(0x0090,0x0010); Delayms(1);
LcdWriteCmdData(0x0092,0x0600); Delayms(1);
LcdWriteCmdData(0x0093,0x0003); Delayms(1);
LcdWriteCmdData(0x0095,0x0110); Delayms(1);
LcdWriteCmdData(0x0097,0x0000); Delayms(1);
LcdWriteCmdData(0x0098,0x0000); Delayms(1);
LcdWriteCmdData(0x0007,0x0133); Delayms(1);
}
/****************************************
*函数名称:LcdDrawPoint
*输 入:unFontPos -字符存储位置
unLcdDirection -显示方向
*输 出:无
*功 能:Lcd初始化
******************************************/
VOID LcdDrawPoint(UINT32 x,UINT32 y,UINT32 color)
{
LcdAddressSet(x,y,x,y);//设置光标位置
LcdWriteData(color>>8,color);
}
/****************************************
*函数名称:LcdFill
*输 入:x_s -横坐标起始地址
y_s -纵坐标起始地址
x_e -横坐标结束地址
y_e -纵坐标结束地址
color -颜色
*输 出:无
*功 能:Lcd颜色填充
******************************************/
VOID LcdFill(UINT32 x_s,UINT32 y_s,UINT32 x_e,UINT32 y_e,UINT32 color)
{
UINT32 i,j;
LcdAddressSet(x_s,y_s,x_e,y_e); //设置光标位置
for(i=y_s;i<=y_e;i++)
{
for(j=x_s;j<=x_e;j++)LcdWriteData(color>>8,color);//设置光标位置
}
}
/****************************************
*函数名称:LcdSetDirection
*输 入:unDirection 显示方向
*输 出:无
*功 能:Lcd显示方向设置
******************************************/
VOID LcdSetDirection(UINT32 unDirection)
{
g_unLcdDirection = unDirection;
}
/****************************************
*函数名称:LcdGetDirection
*输 入:无
*输 出:无
*功 能:Lcd显示方向获取
******************************************/
UINT32 LcdGetDirection(VOID)
{
return g_unLcdDirection;
}
/****************************************
*函数名称:LcdRemakeFont
*输 入:pucCode -字符缓冲区
unDirection -字体方向
unFontType -字体
*输 出:无
*功 能:重置字体
******************************************/
STATIC VOID LcdRemakeFont(UINT8 *pucCode,UINT32 unDirection,UINT32 unFontType)
{
UINT8 i=0,j=0,m=0,n=0,size=0;
UINT8 TempBuf[32]={0};
if(unFontType ==FONT_IS_ASC16)
{
size=16;
}
if(unFontType ==FONT_IS_GBK16)
{
size=32;
}
for(i=0;i<size;i++)
{
TempBuf[size-1-i]=pucCode[i];
TempBuf[i]=pucCode[size-1-i];
}
for(i=0;i<size;i+=2)
{
m=0;n=0;
for(j=0; j<8; j++)
{
if(TempBuf[i] &1<<j)m|=1<<(7-j);
if(TempBuf[i+1]&1<<j)n|=1<<(7-j);
}
pucCode[i] =m;
pucCode[i+1]=n;
}
}
/****************************************
*函数名称:LcdDrawBigPoint
*输 入:x -横坐标
y -纵坐标
color -描点颜色
*输 出:无
*功 能:Lcd描粗点
******************************************/
VOID LcdDrawBigPoint(UINT32 x,UINT32 y,UINT32 color)
{
LcdFill(x,y,x+10,y+10,color);
}
/****************************************
*函数名称:LcdShowFlashFont
*输 入:x -横坐标
y -纵坐标
pucCode -字符缓冲区
color -字体颜色
bgcolor -字体背景色
*输 出:无
*功 能:Lcd显示时采用存储在Flash中的字体
******************************************/
STATIC VOID LcdShowFlashFont(UINT32 x,UINT32 y,UINT8 *pucCode,UINT32 color,UINT32 bgcolor)
{
UINT32 FontOffset;
UINT8 i=0,j=0;
UINT8 buf[32]={0};
if(pucCode[0]&0x80) //汉字
{
FontOffset =FLASH_HZK16_ADDRESS;
FontOffset+=(94 *((UINT8) pucCode[0] - 0xA1 ) + ( (UINT8)pucCode[1] - 0xA1 ) ) << 5;
SpiFlashRead(buf,FontOffset,32);
if(LcdGetDirection()!=LCD_DIRECTION_0)
{
LcdRemakeFont(buf,LcdGetDirection(),FONT_IS_GBK16);
}
LcdAddressSet(x,y,x+15,y+15); //设置区域
for(j=0;j<32;j++)
{
for(i=0;i<8;i++)
{
if((buf[j]&(1<<(7-i)))!=0)
{
LcdWriteData(color>>8,color);
}
else
{
LcdWriteData(bgcolor>>8,bgcolor);
}
}
}
}//ASC
else
{
FontOffset =FLASH_ASC16_ADDRESS;
FontOffset += pucCode[0] << 4;
SpiFlashRead(buf,FontOffset,16);
if(LcdGetDirection()!=LCD_DIRECTION_0)
{
LcdRemakeFont(buf,LcdGetDirection(),FONT_IS_ASC16);
}
LcdAddressSet(x,y,x+7,y+15); //设置区域
for(j=0;j<16;j++)
{
for(i=0;i<8;i++)
{
if((buf[j]&(1<<(7-i)))!=0)
{
LcdWriteData(color>>8,color);
}
else
{
LcdWriteData(bgcolor>>8,bgcolor);
}
}
}
}
}
/****************************************
*函数名称:LcdShowFont
*输 入:x -横坐标
y -纵坐标
pucCode -字符缓冲区
color -字体颜色
bgcolor -字体背景色
*输 出:无
*功 能:Lcd显示单个文字
******************************************/
VOID LcdShowFont(UINT32 x,UINT32 y,UINT8 *pucCode,UINT32 color,UINT32 bgcolor)
{
switch(g_unFontPos)
{
case LCD_FONT_IN_SD:
{
}break;
case LCD_FONT_IN_FLASH:
{
LcdShowFlashFont(x,y,pucCode,color,bgcolor);
}break;
default:break;
}
}
/****************************************
*函数名称:LcdShowString
*输 入:x -横坐标
y -纵坐标
pucCode -字符缓冲区
color -字体颜色
bgcolor -字体背景色
*输 出:无
*功 能:Lcd显示字符串
******************************************/
VOID LcdShowString(UINT32 x,UINT32 y,UINT8 *pucCode,UINT32 color,UINT32 bgcolor)
{
UINT32 x_bak=x;
while(pucCode && *pucCode)
{
LcdShowFont(x,y,pucCode,color,bgcolor);
if(*pucCode & 0x80)
{
pucCode+=2;
x+=16;
}
else
{
pucCode++;
x+=16;
}
if(x>=240) //换行
{
x = x_bak;
y+=20;
}
}
}
|