TFT_WriteRegister(0x04,0x0000); // Scalling Contral.
TFT_WriteRegister(0x08,0x0202); // Display Contral 2.(0x0207)
TFT_WriteRegister(0x09,0x0000); // Display Contral 3.(0x0000)
TFT_WriteRegister(0x0A,0x0000); // Frame Cycle Contal.(0x0000)
TFT_WriteRegister(0x0C,(1<<0)); // Extern Display Interface Contral 1.(0x0000)
TFT_WriteRegister(0x0D,0x0000); // Frame Maker Position.
TFT_WriteRegister(0x0F,0x0000); // Extern Display Interface Contral 2.
// TFT_Delay(100000);
Delay_ms(20);
TFT_WriteRegister(0x07,0x0101); // Display Contral.
// TFT_Delay(100000);
Delay_ms(20);
TFT_WriteRegister(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4)); // Power Control 1.(0x16b0)
TFT_WriteRegister(0x11,0x0007); // Power Control 2.(0x0001)
TFT_WriteRegister(0x12,(1<<8)|(1<<4)|(0<<0)); // Power Control 3.(0x0138)
TFT_WriteRegister(0x13,0x0B00); // Power Control 4.
TFT_WriteRegister(0x29,0x0000); // Power Control 7.
TFT_WriteRegister(0x2b,(1<<14)|(1<<4));
TFT_WriteRegister(0x50,0); // Set X Start.
TFT_WriteRegister(0x51,239); // Set X End.
TFT_WriteRegister(0x52,0); // Set Y Start.
TFT_WriteRegister(0x53,319); // Set Y End.
//extern void TFT_SetGPIO(void);
//extern void TFT_Delay(unsigned int nCount);
extern void Delay_us(unsigned char Times);
extern void Delay_ms(unsigned char Times);
extern void Delay_s(unsigned char Times);
extern unsigned short TFT_CheckContronller(void);
extern void TFT_BackLight(unsigned char status);
extern void TFT_Reset(void);
extern void TFT_WriteRegister(unsigned short index,unsigned short dat);
extern unsigned short TFT_ReadRegister(unsigned short index);
extern unsigned short TFT_ReadData(void);
extern void TFT_WriteData(unsigned short dat);
extern void TFT_Init(void);
extern void TFT_SetCursor(unsigned short x,unsigned short y);
extern void TFT_SetWindows(unsigned short startX,unsigned short startY,unsigned short endX,unsigned short endY);
extern void TFT_Clear(unsigned short dat);
extern unsigned short TFT_GetPoint(unsigned short x,unsigned short y);
extern void TFT_SetPoint(unsigned short x,unsigned short y,unsigned short point);
extern void TFT_DrawPicture(unsigned short startX,unsigned short startY,unsigned short endX,unsigned short endY,unsigned char const *pic);
extern void TFT_PutChar(unsigned short x,unsigned short y,unsigned char asciiCode,unsigned short charColor,unsigned short bkColor);
extern void TFT_Test(void);
extern unsigned short TFT_BGR2RGB(unsigned short c);
extern void TFT_WriteIndex(unsigned short idx);
extern void TFT_PutStr(unsigned short endX,unsigned short endY,unsigned char *ptr,unsigned short charColor,unsigned short bkColor);
#endif
/******************************************************
End Of File
******************************************************/
/******************************************************
* ³ÌÐòÃû³Æ: TFT²ÊÆÁÔ´´úÂë
* ³ÌÐò¹¦ÄÜ: TFT²ÊÆÁÏÔʾÇý¶¯
* Ä¿±êÓ²¼þ: C8051F020 22.1184
* ÎļþÃû³Æ£ºILI9320.c
* ´´½¨ÈÕÆÚ:
* Ô­´´×÷Õß:
******************************************************/
#include "mytype.h"
#include "ILI9320.h"
#include "ILI9320Font.h"
#include "intrins.h"
/************************************************************************************/
/***********************************************************************************
* º¯ÊýÃû³Æ£ºDelay_us;
*
* º¯Êý¹¦ÄÜÃèÊö£ºÑÓʱn΢Ãë×Óº¯Êý;
*
* ÊäÈë²ÎÊý£ºÑÓʱʱ¼ä£¨µ¥Î»Î¢Ã룩;
*
* ·µ»ØÊý¾Ý£ºnone£»
*
* ×¢Ò⣺ none;
************************************************************************************/
void Delay_us(unsigned char Times)
{
unsigned char i;
for (i=0; i<Times; i++)
{
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();
}
}
/***********************************************************************************
* º¯ÊýÃû³Æ£ºDelay_ms;
*
* º¯Êý¹¦ÄÜÃèÊö£ºÑÓʱnºÁÃë×Óº¯Êý;
*
* ÊäÈë²ÎÊý£ºÑÓʱʱ¼ä£¨µ¥Î»ºÁÃ룩;
*
* ·µ»ØÊý¾Ý£ºnone£»
*
* ×¢Ò⣺ none;
************************************************************************************/
void Delay_ms(unsigned char Times)
{
unsigned char i;
for (i=0; i<Times; i++)
{
Delay_us(250);
Delay_us(250);
Delay_us(250);
Delay_us(250);
}
}
/***********************************************************************************
* º¯ÊýÃû³Æ£ºDelay_s;
*
* º¯Êý¹¦ÄÜÃèÊö£ºÑÓʱnÃë×Óº¯Êý;
*
* ÊäÈë²ÎÊý£ºÑÓʱʱ¼ä£¨µ¥Î»Ã룩;
*
* ·µ»ØÊý¾Ý£ºnone£»
*
* ×¢Ò⣺ none;
************************************************************************************/
void Delay_s(unsigned char Times)
{
unsigned char i;
for (i=0; i<Times; i++)
{ Delay_ms(250);
Delay_ms(250);
Delay_ms(250);
Delay_ms(250);
}
}
/*****************************************************
º¯ Êý Ãû£ºTFT_Delay()
¹¦ ÄÜ£ºTFTÑÓʱ
˵ Ã÷£ºTFT²ÊÆÁÑÓʱ
Èë¿Ú²ÎÊý£ºnCount
·µ »Ø Öµ£ºÎÞ
*****************************************************/
//void TFT_Delay(uint32 nCount)
//{
//}
// ****************** дÊý¾Ý ************************
void WRITEDATA(unsigned short dat)
{
P5 = dat;
P0 = dat >> 8;
}
unsigned short READDATA()
{
unsigned short tmp;
tmp = P5;
tmp = ( tmp<<8 ) | P0;
return tmp;
}
/*****************************************************
º¯ Êý Ãû£ºTFT_SetGPIO()
¹¦ ÄÜ£ºTFT¶Ë¿Ú·½ÏòÉèÖÃ
˵ Ã÷£ºÎÞ
Èë¿Ú²ÎÊý£ºÎÞ
·µ »Ø Öµ£ºÎÞ
*****************************************************/
//void TFT_SetGPIO(void)
//{
// IO1DIR = (TFT_CS|TFT_RS|TFT_WR|TFT_RD|TFT_RST|TFT_BLK);
// IO0DIR = TFT_DAT;
//}
/*****************************************************
º¯ Êý Ãû£ºTFT_BackLight()
¹¦ ÄÜ£ºTFT±³¹â¿ª¹Ø
˵ Ã÷£º1 - ±³¹â¿ª£»0 - ±³¹â¹Ø
Èë¿Ú²ÎÊý£ºstatus
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_BackLight(uint8 status)
{
if (status >= 1)
{
ON_TFT_BLK(); // ±³¹â¿ª
}
else
{
OFF_TFT_BLK(); // ±³¹â¹Ø
}
}
/*****************************************************
º¯ Êý Ãû£ºTFT_Reset()
¹¦ ÄÜ£ºTFT¸´Î»
˵ Ã÷£º×¢Ò⸴λʱ¼ä
Èë¿Ú²ÎÊý£ºÎÞ
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_Reset(void)
{
/*=====================================================
== ==
== ------------\_____________________/----------- ==
== | <---- Tres ----> | ==
== ==
== Tres: Min.1ms ==
======================================================*/
SET_TFT_RST();
// TFT_Delay(5000);
Delay_ms(10);
CLR_TFT_RST();
// TFT_Delay(5000);
Delay_ms(10);
SET_TFT_RST();
// TFT_Delay(5000);
Delay_ms(10);
}
/*****************************************************
º¯ Êý Ãû£ºTFT_WriteRegister()
¹¦ ÄÜ£ºÐ´Ö¸¶¨µØÖ·¼Ä´æÆ÷µÄÖµ
˵ Ã÷£ºindex - ¼Ä´æÆ÷µØÖ·£»dat - ¼Ä´æÆ÷Öµ
Èë¿Ú²ÎÊý£ºindex£»dat
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_WriteRegister(uint16 index,uint16 dat)
{
/*====================================================
== ==
== nCS ----\______________________________/--- ==
== RS ------\____________/------------------- ==
== nRD --------------------------------------- ==
== nWR --------\_______/-----\_____/---------- ==
== DB[0:15] ---------[index]------[data]----------- ==
== ==
====================================================*/
CLR_TFT_CS();
SET_TFT_RD();
CLR_TFT_RS(); // дָÁî
TFT_WriteData(index);
//CLR_TFT_WR();
//SET_TFT_WR();
SET_TFT_RS();
TFT_WriteData(dat); // дÊý¾Ý
//CLR_TFT_WR();
//SET_TFT_WR();
SET_TFT_CS();
}
/*****************************************************
º¯ Êý Ãû£ºTFT_ReadRegister()
¹¦ ÄÜ£º¶ÁÈ¡Ö¸¶¨µØÖ·¼Ä´æÆ÷µÄÖµ
˵ Ã÷£ºindex - ¼Ä´æÆ÷µØÖ·
Èë¿Ú²ÎÊý£ºindex
·µ »Ø Öµ£ºtmp
*****************************************************/
uint16 TFT_ReadRegister(uint16 index)
{
uint16 tmp;
CLR_TFT_CS();
CLR_TFT_RS();
SET_TFT_RD();
TFT_WriteData(index);
//CLR_TFT_WR();
//SET_TFT_WR();
CLR_TFT_RD();
tmp = TFT_ReadData();
SET_TFT_RD();
SET_TFT_CS();
return tmp;
}
/*****************************************************
º¯ Êý Ãû£ºTFT_ReadData()
¹¦ ÄÜ£º¶ÁÈ¡¿ØÖƼĴæÆ÷Êý
˵ Ã÷£º
Èë¿Ú²ÎÊý£ºÎÞ
·µ »Ø Öµ£ºÎÞ
*****************************************************/
uint16 TFT_ReadData(void)
{
uint16 tmp;
tmp = READDATA();
return tmp;
}
/*****************************************************
º¯ Êý Ãû£ºTFT_WriteData()
¹¦ ÄÜ£ºÐ´TFT¼Ä´æÆ÷Êý¾Ý
˵ Ã÷£ºdat - ¼Ä´æÆ÷Êý¾Ý
Èë¿Ú²ÎÊý£ºdat
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_WriteData(uint16 dat)
{
WRITEDATA(dat); // д16λÊý¾Ý
CLR_TFT_WR();
SET_TFT_WR();
}
/*****************************************************
º¯ Êý Ãû£ºTFT_Init()
¹¦ ÄÜ£º³õʼ»¯TFT
˵ Ã÷£ºÎÞ
Èë¿Ú²ÎÊý£ºÎÞ
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_Init(void)
{
// TFT_SetGPIO(); // ³õʼ»¯¿ØÖƶ˿Ú
TFT_WriteData(0xFFFF);
SET_TFT_RST(); // ËùÓпØÖƶ˿ÚÀ­¸ß
SET_TFT_WR();
SET_TFT_CS();
SET_TFT_RS();
SET_TFT_RD();
SET_TFT_RST();
ON_TFT_BLK(); // ¿ª±³¹â
// ¸´Î»Òº¾§Ä£¿é
TFT_Reset();
// TFT_Delay(15000);
Delay_ms(10);
TFT_WriteRegister(0x00,0x0001); // start the oscillator Æô¶¯¾§Õñ
// TFT_Delay(15000);
Delay_ms(10);
TFT_WriteRegister(0x00,0x0000);
TFT_WriteRegister(0x01,0x0100); // Driver Output Contral.
TFT_WriteRegister(0x02,0x0700); // LCD Driver Waveform Contral.
TFT_WriteRegister(0x03,0x1030); // Entry Mode Set.
TFT_WriteRegister(0x04,0x0000); // Scalling Contral.
TFT_WriteRegister(0x08,0x0202); // Display Contral 2.(0x0207)
TFT_WriteRegister(0x09,0x0000); // Display Contral 3.(0x0000)
TFT_WriteRegister(0x0A,0x0000); // Frame Cycle Contal.(0x0000)
TFT_WriteRegister(0x0C,(1<<0)); // Extern Display Interface Contral 1.(0x0000)
TFT_WriteRegister(0x0D,0x0000); // Frame Maker Position.
TFT_WriteRegister(0x0F,0x0000); // Extern Display Interface Contral 2.
// TFT_Delay(100000);
Delay_ms(20);
TFT_WriteRegister(0x07,0x0101); // Display Contral.
// TFT_Delay(100000);
Delay_ms(20);
TFT_WriteRegister(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4)); // Power Control 1.(0x16b0)
TFT_WriteRegister(0x11,0x0007); // Power Control 2.(0x0001)
TFT_WriteRegister(0x12,(1<<8)|(1<<4)|(0<<0)); // Power Control 3.(0x0138)
TFT_WriteRegister(0x13,0x0B00); // Power Control 4.
TFT_WriteRegister(0x29,0x0000); // Power Control 7.
TFT_WriteRegister(0x2b,(1<<14)|(1<<4));
TFT_WriteRegister(0x50,0); // Set X Start.
TFT_WriteRegister(0x51,239); // Set X End.
TFT_WriteRegister(0x52,0); // Set Y Start.
TFT_WriteRegister(0x53,319); // Set Y End.
TFT_WriteRegister(0x60,0x2700); // Driver Output Control.
TFT_WriteRegister(0x61,0x0001); // Driver Output Control.
TFT_WriteRegister(0x6A,0x0000); // Vertical Srcoll Control.
TFT_WriteRegister(0x80,0x0000); // Display Position? Partial Display 1.
TFT_WriteRegister(0x81,0x0000); // RAM Address Start? Partial Display 1.
TFT_WriteRegister(0x82,0x0000); // RAM Address End-Partial Display 1.
TFT_WriteRegister(0x83,0x0000); // Displsy Position? Partial Display 2.
TFT_WriteRegister(0x84,0x0000); // RAM Address Start? Partial Display 2.
TFT_WriteRegister(0x85,0x0000); // RAM Address End? Partial Display 2.
TFT_WriteRegister(0x90,(0<<7)|(16<<0)); // Frame Cycle Contral.(0x0013)
TFT_WriteRegister(0x92,0x0000); // Panel Interface Contral 2.(0x0000)
TFT_WriteRegister(0x93,0x0001); // Panel Interface Contral 3.
TFT_WriteRegister(0x95,0x0110); // Frame Cycle Contral.(0x0110)
TFT_WriteRegister(0x97,(0<<8)); //
TFT_WriteRegister(0x98,0x0000); // Frame Cycle Contral.
TFT_WriteRegister(0x07,0x0173); // (0x0173)
// TFT_Delay(50000);
Delay_ms(20);
TFT_Clear(0xF800); // дÈëºìÉ«
}
/*****************************************************
º¯ Êý Ãû£ºTFT_SetCursor()
¹¦ ÄÜ£ºÉèÖÃÆÁÄ»×ø±ê
˵ Ã÷£ºx - ÐÐ×ø±ê£»y - ÁÐ×ø±ê
Èë¿Ú²ÎÊý£ºx£»y
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_SetCursor(uint16 x,uint16 y)
{
TFT_WriteRegister(0x0020,x); // ÐÐ
TFT_WriteRegister(0x0021,y); // ÁÐ
}
/*****************************************************
º¯ Êý Ãû£ºTFT_SetWindows()
¹¦ ÄÜ£ºÉèÖô°¿ÚÇøÓò
˵ Ã÷£º
Èë¿Ú²ÎÊý£ºstartX,startY,endX,endY
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_SetWindows(uint16 startX,uint16 startY,uint16 endX,uint16 endY)
{
TFT_SetCursor(startX,startY);
TFT_WriteRegister(0x0050,startX); // ˮƽ GRAMÆðʼλÖÃ
TFT_WriteRegister(0x0051,endX); // ˮƽGRAMÖÕֹλÖÃ
TFT_WriteRegister(0x0052,startY); // ´¹Ö±GRAMÆðʼλÖÃ
TFT_WriteRegister(0x0053,endY); // ´¹Ö±GRAMÖÕֹλÖÃ
}
/*****************************************************
º¯ Êý Ãû£ºTFT_BGR2RGB()
¹¦ ÄÜ£ºÑÕÉ«Êý¾Ý¸ñʽת»»
˵ Ã÷£ºRRRRRGGGGGBBBBB ¸Ä³É BBBBBGGGGGRRRRR
Èë¿Ú²ÎÊý£ºc - ÑÕÉ«
·µ »Ø Öµ£ºÎÞ
******************************************************/
uint16 TFT_BGR2RGB(uint16 c)
{
uint16 r,g,b;
b = (c>>0) & 0x1F;
g = (c>>5) & 0x3F;
r = (c>>11) & 0x1F;
return ((b<<11) | (g<<5) || (r<<0));
}
/*****************************************************
º¯ Êý Ãû£ºTFT_WriteIndex()
¹¦ ÄÜ£ºÐ´TFT¼Ä´æÆ÷µØÖ·
˵ Ã÷£ºµ÷ÓÃÇ°ÐèÏÈÑ¡ÖпØÖÆÆ÷
Èë¿Ú²ÎÊý£ºidx - ¼Ä´æÆ÷µØÖ·
·µ »Ø Öµ£ºÎÞ
******************************************************/
void TFT_WriteIndex(uint16 idx)
{
CLR_TFT_RS();
SET_TFT_RD();
TFT_WriteData(idx);
SET_TFT_RS();
}
/*****************************************************
º¯ Êý Ãû£ºTFT_Clear()
¹¦ ÄÜ£º½«ÆÁÄ»Ìî³ä³ÉÖ¸¶¨µÄÑÕÉ«£¬ÈçÇåÆÁ£¬ÔòÌî³ä 0xFFFF
˵ Ã÷£ºdat - Ìî³äÖµ
Èë¿Ú²ÎÊý£ºdat
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_Clear(uint16 dat)
{
uint32 i;
TFT_SetCursor(0x00,0x0000);
TFT_WriteRegister(0x0050,0x00); // ˮƽ GRAMÆðʼλÖÃ
TFT_WriteRegister(0x0052,0x00); // ´¹Ö±GRAMÆðʼλÖÃ
TFT_WriteRegister(0x0051,239); // ˮƽGRAMÖÕֹλÖÃ
TFT_WriteRegister(0x0053,319); // ´¹Ö±GRAMÖÕֹλÖÃ
CLR_TFT_CS();
TFT_WriteIndex(0x0022);
SET_TFT_RS();
for (i=0; i<76800; i++)
{
TFT_WriteData(dat);
}
SET_TFT_CS();
}
/*****************************************************
º¯ Êý Ãû£ºTFT_GetPoint()
¹¦ ÄÜ£º»ñÈ¡Ö¸¶¨×ù±êµÄÑÕÉ«Öµ
˵ Ã÷£ºx - ÐÐ×ø±ê£»y - ÁÐ×ø±ê
Èë¿Ú²ÎÊý£ºx,y
·µ »Ø Öµ£ºµ±Ç°×ø±êÑÕÉ«Öµ
*****************************************************/
uint16 TFT_GetPoint(uint16 x,uint16 y)
{
TFT_SetCursor(x,y);
return (TFT_BGR2RGB(TFT_ReadRegister(0x0022)));
}
/*****************************************************
º¯ Êý Ãû£ºTFT_SetPoint()
¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±ê»­µã
˵ Ã÷£ºx - ÐÐ×ø±ê£»y - ÁÐ×ø±ê£»point - µãµÄÑÕÉ«
Èë¿Ú²ÎÊý£ºx,y,point
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_SetPoint(uint16 x,uint16 y,uint16 point)
{
if ((x>240) || (y>320))
{
return;
}
TFT_SetCursor(x,y);
CLR_TFT_CS();
TFT_WriteIndex(0x0022);
SET_TFT_RS();
TFT_WriteData(point);
SET_TFT_CS();
}
/*****************************************************
º¯ Êý Ãû£ºTFT_DrawPicture()
¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±ê·¶Î§ÏÔʾһ¸±Í¼Æ¬
˵ Ã÷£º
Èë¿Ú²ÎÊý£ºstartX,startY,endX,endY,*pic
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_DrawPicture(uint16 startX,uint16 startY,uint16 endX,uint16 endY,uint8 const *pic)
{
uint32 i;
uint16 tmp;
TFT_SetWindows(startX,startY,endX,endY);
TFT_SetCursor(startX,startY);
CLR_TFT_CS();
TFT_WriteIndex(0x0022);
SET_TFT_RS();
for (i=0; i<(endX*endY); i++)
{
tmp = *pic++; // µÍ8λÊý¾ÝÔÝ´æ
tmp += (*pic++ << 8); // È¡¸ß8λÊý¾Ý£¬²¢ºÏ²¢³É16λÊý¾Ý
TFT_WriteData(tmp); // дÈë16λÊý¾Ý
}
SET_TFT_CS();
}
/*****************************************************
º¯ Êý Ãû£ºTFT_PutChar()
¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±êÏÔʾһ¸ö8x16µãÕóµÄascii×Ö·û
˵ Ã÷£ºx - ÐÐ×ø±ê£»y - ÁÐ×ø±ê£»charColor - ×Ö·ûµÄÑÕÉ«£»bkColor - ×Ö·û±³¾°ÑÕÉ«
Èë¿Ú²ÎÊý£ºx,y,asciCode,charColor,bkColor; asciiCode ÊäÈë·½·¨ÎªÖ±½ÓÊäÈëASCII»ò'A'ÐÎʽ
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_PutChar(uint16 x,uint16 y,uint8 asciiCode,uint16 charColor,uint16 bkColor)
{
uint16 i = 0;
uint16 j = 0;
uint8 tmpChar = 0;
for (i=0; i<16; i++)
{
tmpChar = ASCLL_8x16[((asciiCode-0x20)*16) + i];
for (j=0; j<8; j++)
{
if ((tmpChar >> 7-j) & 0x01 == 0x01)
{
TFT_SetPoint(x+j,y+i,charColor); // ×Ö·ûÑÕÉ«
}
else
{
if (bkColor != NOCOLOR)
{
TFT_SetPoint(x+j,y+i,bkColor); // ±³¾°ÑÕÉ«
}
}
}
}
}
/*****************************************************
º¯ Êý Ãû£ºTFT_PutChinese()
¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±êÏÔʾһ¸ö16x16µãÕóµÄÖÐÎĺº×Ö
˵ Ã÷£ºx - ÐÐ×ø±ê£»y - ÁÐ×ø±ê£»charColor - ×Ö·ûµÄÑÕÉ«£»bkColor - ×Ö·û±³¾°ÑÕÉ«
Èë¿Ú²ÎÊý£ºx,y,asciCode,arr,bkColor;
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_PutChinese(uint16 x,uint16 y,struct Gb16 const arr,uint16 charColor,uint16 bkColor)
{
uint8 i,j;
for (i=0; i<32; i++)
{
for (j=0; j<8; j++)
{
if ((arr.zimo >> 7-j) & 0x01 == 0x01)
{
TFT_SetPoint(x+j,y+i/2,charColor); // ×Ö·ûÑÕÉ«
}
else
{
if (bkColor != NOCOLOR)
{
TFT_SetPoint(x+j,y+i/2,bkColor); // ±³¾°ÑÕÉ«
}
}
}
if ((i != 0) && ((i % 2) != 0)) // ÆæÊý
{
x -= 8; // д×ó°ë
}
else
{
x += 8; // дÓÒ°ë
}
}
}
/*****************************************************
º¯ Êý Ãû£ºTFT_PutStr()
¹¦ ÄÜ£ºÊä³ö×Ö·û´®£¬¿ÉÒÔÊǺº×Ö£¬Ò²¿ÉÒÔÊÇÓ¢ÎÄ×Ö·û
˵ Ã÷£ºx - ÐÐ×ø±ê£»y - ÁÐ×ø±ê£»charColor - ×Ö·ûµÄÑÕÉ«£»bkColor - ×Ö·û±³¾°ÑÕÉ«
Èë¿Ú²ÎÊý£ºx,y,charColor,bkColor
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_PutStr(uint16 endX,uint16 endY,uint8 *ptr,uint16 charColor,uint16 bkColor)
{
uint8 c1,c2;
uint8 ulen = 0;
uint8 i = 0,j;
uint16 x = endX; // ºá×ø±ê
uint16 y = endY; // ×Ý×ø±ê
while (ptr[ulen] != 0)
{
ulen++; // ̽²â×Ö·û´®µÄ³¤¶È
}
while (i < ulen)
{
c1 = ptr; // È¡×Ö·ûµÄASCIIÂë
c2 = ptr[i+1]; //
// ASCII×Ö·ûÓ뺺×ÖÄÚÂëµÄÇø±ðÔÚÓÚ128
if (c1 <= 128) // ASCII < 128
{
TFT_PutChar(x,y,c1,charColor,bkColor); // ÏÔʾ×Ö·û
x += 8; // ºáÏòµØÖ·¼Ó1¸ö×Ö·ûλÖÃ
if (x > (WIDTH-8)) // ²»¹»Ð´ÈëÒ»¸ö×Ö·û
{
x = 0;
y += 16; // »»ÐÐÏÔʾ
}
i++; // È¡ÏÂÒ»×Ö·û
}
else // ºº×Ö > 128
{
for (j=0; j<sizeof(hz16[68])/sizeof(hz16[0]); j++)
{ // ²éÕÒ¶¨Î»µ±Ç°ºº×ֵĵãÕóÇø
if((c1 == hz16[j].index[0]) && (c2 == hz16[j].index[1]))
{
break;
}
}
TFT_PutChinese(x,y,hz16[j],charColor,bkColor); // ÏÔʾºº×Ö
x += 16; // ºáÏòµØÖ·¼Ó1¸ö×Ö·ûλÖÃ
if (x > (WIDTH-16)) // ²»¹»Ð´ÈëÒ»¸öºº×Ö
{
x = 0;
y += 16; // »»ÐÐÏÔʾ
}
i += 2; // È¡ÏÂÒ»ºº×Ö
}
}
}
/*****************************************************
º¯ Êý Ãû£ºTFT_Test()
¹¦ ÄÜ£º²âÊÔÒº¾§ÆÁ
˵ Ã÷£ºÏÔʾ²ÊÌõ£¬²âÊÔÒº¾§ÊÇ·ñÕý³£¹¤×÷
Èë¿Ú²ÎÊý£ºÎÞ
·µ »Ø Öµ£ºÎÞ
*****************************************************/
void TFT_Test(void)
{
uint8 R_Dat,G_Dat,B_Dat,i,j;
TFT_SetCursor(0x00,0x0000);
TFT_WriteRegister(0x0050,0x00);
TFT_WriteRegister(0x0051,239);
TFT_WriteRegister(0x0052,0x00);
TFT_WriteRegister(0x0053,319);
CLR_TFT_CS();
TFT_WriteIndex(0x0022);
SET_TFT_RS();
// ------------------ ºìÉ«½¥ÁÁÌõ --------------------
R_Dat = 0;
G_Dat = 0;
B_Dat = 0;
for (j=0; j<53; j++)
{
for (i=0; i<240; i++)
{
R_Dat = i/8;
TFT_WriteData((R_Dat<<11) | (G_Dat<<5) | B_Dat);
}
}
R_Dat = 0x1F;
G_Dat = 0x3F;
B_Dat = 0x1F;
for (j=0; j<54; j++)
{
for (i=0; i<240; i++)
{
G_Dat = 0x3F - (i/4);
B_Dat = 0x1F - (i/8);
TFT_WriteData((R_Dat<<11) | (G_Dat<<5) | B_Dat);
}
}
// ------------------ ÂÌÉ«½¥ÁÁÌõ --------------------
R_Dat = 0;
G_Dat = 0;
B_Dat = 0;
for (j=0; j<53; j++)
{
for (i=0; i<240; i++)
{
G_Dat = i/8;
TFT_WriteData((R_Dat<<11) | (G_Dat<<5) | B_Dat);
}
}
R_Dat = 0x1F;
G_Dat = 0x3F;
B_Dat = 0x1F;
for (j=0; j<54; j++)
{
for (i=0; i<240; i++)
{
R_Dat = 0x3F - (i/4);
B_Dat = 0x1F - (i/8);
TFT_WriteData((R_Dat<<11) | (G_Dat<<5) | B_Dat);
}
}
// ------------------ À¶É«½¥ÁÁÌõ --------------------
R_Dat = 0;
G_Dat = 0;
B_Dat = 0;
for (j=0; j<53; j++)
{
for (i=0; i<240; i++)
{
B_Dat = i/8;
TFT_WriteData((R_Dat<<11) | (G_Dat<<5) | B_Dat);
}
}
R_Dat = 0x1F;
G_Dat = 0x3F;
B_Dat = 0x1F;
for (j=0; j<53; j++) // ºìÉ«½¥ÁÁÌõ
{
for (i=0; i<240; i++)
{
G_Dat = 0x3F - (i/4);
R_Dat = 0x1F - (i/8);
TFT_WriteData((R_Dat<<11) | (G_Dat<<5) | B_Dat);
}
}
SET_TFT_CS();
}
/******************************************************
End Of File
******************************************************/
* ³ÌÐòÃû³Æ: TFT²ÊÆÁÍ·Îļþ
* ³ÌÐò¹¦ÄÜ: TFT²ÊÆÁ²ÎÊýÉèÖÃ
* Ä¿±êÓ²¼þ:
* ÎļþÃû³Æ£ºILI9320.h
* ´´½¨ÈÕÆÚ:
* Ô­´´×÷Õß:
******************************************************/
#ifndef __ILI9320_H
#define __ILI9320_H
#include "mytype.h"
#include "c8051f020.h"
/***************** ¹Ü½Å¶¨Òå ************************/
//#define TFT_CS 1 << 16 // P1.16 Ƭѡ
//#define TFT_RS 1 << 17 // P1.17 Ö¸Áî/Êý¾ÝÑ¡Ôñ 0 - Ö¸Á1 - Êý¾Ý
//#define TFT_WR 1 << 18 // P1.18
//#define TFT_RD 1 << 19 // P1.19
//#define TFT_RST 1 << 20 // P1.20 ¸´Î»
//#define TFT_BLK 1 << 21 // P1.21 ±³¹â¿ØÖÆ
//
//#define TFT_DAT 0xFFFF // P0.0~P0.15
sbit A0 = P2^1; //Êý¾Ý/ÃüÁîÇл»
sbit RES = P2^4; //¸´Î»
sbit WRB = P2^2; //д¿ØÖÆ
sbit RDB = P2^3; //¶Á¿ØÖÆ
sbit CS = P2^0; //Ƭѡ
sbit BLK = P2^5; //ÔÝʱûÓõ½
//****************** ºê¶¨Òå ***************************
#define SET_TFT_CS() (CS = 1)
#define CLR_TFT_CS() (CS = 0)
#define SET_TFT_RS() (A0 = 1)
#define CLR_TFT_RS() (A0 = 0)
#define SET_TFT_WR() (WRB = 1)
#define CLR_TFT_WR() (WRB = 0)
#define SET_TFT_RD() (RDB = 1)
#define CLR_TFT_RD() (RDB = 0)
#define SET_TFT_RST() (RES = 1)
#define CLR_TFT_RST() (RES = 0)
#define ON_TFT_BLK() (BLK = 1)
#define OFF_TFT_BLK() (BLK = 0)
// ****************** ¶ÁÊý¾Ý ************************
//#define READDATA() (P0)
//************** ÑÕÉ«¶¨Òå ***************************
#define RED 0xF800 // ºìÉ«
#define GREEN 0x03E0 // ÂÌÉ«
#define BLUE 0x001F // À¶É«
#define WRITE 0xFFFF // °×É«
#define BLACK 0x0000 // ºÚÉ«
#define ORANGE 0xF860 // ³ÈÉ«
#define YELLOW 0xFFE0 // »ÆÉ«
#define CYAN 0x07FF // ÇàÉ«
#define PROPLE 0xF81F // ×ÏÉ«
#define NOCOLOR 0x0001 // ÎÞÉ«
//************** ¶¨ÒåÆÁ¿í ***************************
#define WIDTH 240 // ÆÁ¿í
#define HEIGTH 320 // ÆÁ¸ß
/***************** º¯ÊýÉêÃ÷ ************************/
//extern void TFT_SetGPIO(void);
//extern void TFT_Delay(unsigned int nCount);
extern void Delay_us(unsigned char Times);
extern void Delay_ms(unsigned char Times);
extern void Delay_s(unsigned char Times);
extern unsigned short TFT_CheckContronller(void);
extern void TFT_BackLight(unsigned char status);
extern void TFT_Reset(void);
extern void TFT_WriteRegister(unsigned short index,unsigned short dat);
extern unsigned short TFT_ReadRegister(unsigned short index);
extern unsigned short TFT_ReadData(void);
extern void TFT_WriteData(unsigned short dat);
extern void TFT_Init(void);
extern void TFT_SetCursor(unsigned short x,unsigned short y);
extern void TFT_SetWindows(unsigned short startX,unsigned short startY,unsigned short endX,unsigned short endY);
extern void TFT_Clear(unsigned short dat);
extern unsigned short TFT_GetPoint(unsigned short x,unsigned short y);
extern void TFT_SetPoint(unsigned short x,unsigned short y,unsigned short point);
extern void TFT_DrawPicture(unsigned short startX,unsigned short startY,unsigned short endX,unsigned short endY,unsigned char const *pic);
extern void TFT_PutChar(unsigned short x,unsigned short y,unsigned char asciiCode,unsigned short charColor,unsigned short bkColor);
extern void TFT_Test(void);
extern unsigned short TFT_BGR2RGB(unsigned short c);
extern void TFT_WriteIndex(unsigned short idx);
extern void TFT_PutStr(unsigned short endX,unsigned short endY,unsigned char *ptr,unsigned short charColor,unsigned short bkColor);
#endif
/******************************************************
End Of File
******************************************************/
一周热门 更多>