#include <hw_types.h>
#include <hw_memmap.h>
#include <sysctl.h>
#include <gpio.h>
#include "TFT240_320.H"
#include "GB8_16.H"
#include "GB16_16.H"
#include "GB32_32.H"
#include "Picture.h"
/**************************************************************************************************
**
** 延时函数
**
****************************************************************************************************/
void delayTFT(int n)
{
while(n--);
}
/**************************************************************************************************
**
** 写入命令
**
****************************************************************************************************/
void Write_Cmd(unsigned char DH,unsigned char DL)
{
GPIOPinWrite(TFT_COM_PORT,TFT_CS,0x00);
GPIOPinWrite(TFT_COM_PORT,TFT_RS,0x00);
GPIOPinWrite(TFT_COM_PORT1,TFT_RD,0x00);
GPIOPinWrite(TFT_DATA_PORT,0xff,DH);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0x00);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0xff);
GPIOPinWrite(TFT_DATA_PORT,0xff,DL);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0x00);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0xff);
GPIOPinWrite(TFT_COM_PORT,TFT_CS,0xff);
}
/**************************************************************************************************
**
** 写入数据
**
****************************************************************************************************/
void Write_Data(unsigned char DH,unsigned char DL)
{
GPIOPinWrite(TFT_COM_PORT,TFT_CS,0x00);
GPIOPinWrite(TFT_COM_PORT,TFT_RS,0xff);
GPIOPinWrite(TFT_COM_PORT1,TFT_RD,0x00);
GPIOPinWrite(TFT_DATA_PORT,0xff,DH);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0x00);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0xff);
GPIOPinWrite(TFT_DATA_PORT,0xff,DL);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0x00);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0xff);
GPIOPinWrite(TFT_COM_PORT,TFT_CS,0xff);
}
/**************************************************************************************************
**
** 读出数据
**
****************************************************************************************************/
unsigned int Read_Data(void)
{
unsigned int data=0;
GPIOPinTypeGPIOInput(TFT_DATA_PORT,0xff);
GPIOPinWrite(TFT_COM_PORT,TFT_CS,0x00);
GPIOPinWrite(TFT_COM_PORT,TFT_RS,0xff);
GPIOPinWrite(TFT_COM_PORT,TFT_RW,0xff);
GPIOPinWrite(TFT_COM_PORT1,TFT_RD,0x00);
delayTFT(500);
data=GPIOPinRead(TFT_DATA_PORT,0xff);
GPIOPinWrite(TFT_COM_PORT1,TFT_RD,0xff);
data=data<<8;
GPIOPinWrite(TFT_COM_PORT1,TFT_RD,0x00);
delayTFT(500);
data |= GPIOPinRead(TFT_DATA_PORT,0xff);
GPIOPinWrite(TFT_COM_PORT1,TFT_RD,0xff);
GPIOPinWrite(TFT_COM_PORT,TFT_CS,0xff);
GPIOPinTypeGPIOOutput(TFT_DATA_PORT,0xff);
return data;
}
/**************************************************************************************************
**
**
**
****************************************************************************************************/
void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor)
{
unsigned int i,j;
LCD_SetPos(x,x+8-1,y,y+16-1);
for(i=0; i<16;i++)
{
unsigned char m=Font8x16[c*16+i];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80)
{
Write_Data_U16(fColor);
}
else
{
Write_Data_U16(bColor);
}
m<<=1;
}
}
}
/**************************************************************************************************
**
**
**
****************************************************************************************************/
void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor)
{
LCD_PutChar8x16( x, y, c, fColor, bColor );
}
/**************************************************************************************************
**
**
**
****************************************************************************************************/
void PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor)
{
unsigned int i,j,k;
LCD_SetPos(x, x+16-1,y, y+16-1);
for (k=0;k<64;k++)
{ //64标示自建汉字库中的个数,循环查询内码
if ((codeGB_16[k].Index[0]==c[0])&&(codeGB_16[k].Index[1]==c[1]))
{
for(i=0;i<32;i++)
{
unsigned short m=codeGB_16[k].Msk[i];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80) Write_Data_U16(fColor);
else Write_Data_U16(bColor);
m<<=1;
}
}
}
}
}
/**************************************************************************************************
**
**
**
****************************************************************************************************/
void PutGB3232(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor)
{
unsigned int i,j,k;
LCD_SetPos(x, x+32-1,y, y+32-1);
for (k=0;k<15;k++)
{ //15标示自建汉字库中的个数,循环查询内码
if ((codeGB_32[k].Index[0]==c[0])&&(codeGB_32[k].Index[1]==c[1]))
{
for(i=0;i<128;i++)
{
unsigned short m=codeGB_32[k].Msk[i];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80) Write_Data_U16(fColor);
else Write_Data_U16(bColor);
m<<=1;
}
}
}
}
}
/**************************************************************************************************
**
**
**
****************************************************************************************************/
void LCD_PutString(unsigned short x, unsigned short y, unsigned char *s, unsigned int fColor, unsigned int bColor)
{
unsigned char l=0;
while(*s)
{
if( *s < 0x80)
{
LCD_PutChar(x+l*8,y,*s,fColor,bColor);
s++;l++;
}
else
{
PutGB1616(x+l*8,y,(unsigned char*)s,fColor,bColor);
s+=2;l+=2;
}
}
}
/**************************************************************************************************
**
** 显示R G B 顔色
**
****************************************************************************************************/
void Show_RGB (unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1,unsigned int Color)
{
unsigned int i,j;
LCD_SetPos(x0,x1,y0,y1);
for (i=y0;i<=y1;i++)
{
for (j=x0;j<=x1;j++)
Write_Data_U16(Color);
}
}
/**************************************************************************************************
**
** 显示彩条
**
****************************************************************************************************/
void show_colour_bar (void)
{
int V,H;
LCD_SetPos(0,240,0,320);//320x240
for(H=0;H<240;H++)
{
for(V=0;V<40;V++)
Write_Data(0xf8,0x00);
}
for(H=0;H<240;H++)
{
for(V=40;V<80;V++)
Write_Data(0x07,0xe0);
}
for(H=0;H<240;H++)
{
for(V=80;V<120;V++)
Write_Data(0x00,0x1f);
}
for(H=0;H<240;H++)
{
for(V=120;V<160;V++)
Write_Data(0xff,0xe0);
}
for(H=0;H<240;H++)
{
for(V=160;V<200;V++)
Write_Data(0xf8,0x1f);
}
for(H=0;H<240;H++)
{
for(V=200;V<240;V++)
Write_Data(0x07,0xff);
}
for(H=0;H<240;H++)
{
for(V=240;V<280;V++)
Write_Data(0xff,0xff);
}
for(H=0;H<240;H++)
{
for(V=280;V<320;V++)
Write_Data(0x00,0x00);
}
}
/**************************************************************************************************
**
**
**
****************************************************************************************************/
void show_photo(void)
{
unsigned char j;
unsigned int i;
unsigned long s=0;
LCD_SetPos(0,240,0,320);//320x240
for (i=0;i<75;i++)
{
for (j=0;j<240;j++)
Write_Data(0xff,0xff);
}
for (i=0;i<170;i++)
{
for (j=0;j<55;j++)
Write_Data(0xff,0xff);
for (j=0;j<130;j++)
Write_Data(pic[s++],pic[s++]);