📄 tft_240_320.c
字号:
//====================================================================================
#include <string.h>
#include <at91sam7s256.h>
//#include "HzLib_65k.h"
#include "lpc213x_user.h"
//====================================================================================
void Delay(uint k)
{
uint i;
ulong j;
for(i = k;i > 0;i--)
for(j = 200000;j > 0;j--);
}
//====================================================================================
void DelayMs( int k)
{
uint i;
ulong j;
for(i = k;i > 0;i--)
for(j = 1000;j > 0;j--);
}
//====================================================================================
void WriData(uint ch)
{
LCD_DATA(ch);
LCD_RS_1;
LCD_WR_1;
LCD_CS_0;
LCD_WR_0;
LCD_CS_1;
}
//====================================================================================
void WriCom(uint ch)
{
LCD_DATA(ch);
LCD_RS_0;
LCD_WR_1;
LCD_CS_0;
LCD_WR_0;
LCD_CS_1;
}
//====================================================================================
void write_com(uint address,uint num)
{
WriCom(address);
WriData(num);
}
//====================================================================================
void TftInit(void)
{
LCD_RESET_0; //低电平复位
DelayMs(10);
LCD_RESET_1;
write_com(0x0000,0x0001); DelayMs(10); //打开晶振
write_com(0x0003,0xA8A4); DelayMs(10); //0xA8A4
write_com(0x000C,0x0000); DelayMs(10);
write_com(0x000D,0x080C); DelayMs(10);
write_com(0x000E,0x2B00); DelayMs(10);
write_com(0x001E,0x00B0); DelayMs(10);
write_com(0x0001,0x2B3F); DelayMs(10); //驱动输出控制320*240 0x6B3F(左上角点) 2B3F(右上角0点)
write_com(0x0002,0x0600); DelayMs(10);
write_com(0x0010,0x0000); DelayMs(10);
write_com(0x0011,0x6070); DelayMs(10); //0x4030 0x6070 //定义数据格式 16位色
write_com(0x0005,0x0000); DelayMs(10);
write_com(0x0006,0x0000); DelayMs(10);
write_com(0x0016,0xEF1C); DelayMs(10);
write_com(0x0017,0x0003); DelayMs(10);
write_com(0x0007,0x0233); DelayMs(10); //0x0233
write_com(0x000B,0x0000); DelayMs(10);
write_com(0x000F,0x0000); DelayMs(10); //扫描开始地址
write_com(0x0041,0x0000); DelayMs(10);
write_com(0x0042,0x0000); DelayMs(10);
write_com(0x0048,0x0000); DelayMs(10);
write_com(0x0049,0x013F); DelayMs(10);
write_com(0x004A,0x0000); DelayMs(10);
write_com(0x004B,0x0000); DelayMs(10);
write_com(0x0044,0xEF00); DelayMs(10);
write_com(0x0045,0x0000); DelayMs(10);
write_com(0x0046,0x013F); DelayMs(10);
write_com(0x0030,0x0707); DelayMs(10);
write_com(0x0031,0x0204); DelayMs(10);
write_com(0x0032,0x0204); DelayMs(10);
write_com(0x0033,0x0502); DelayMs(10);
write_com(0x0034,0x0507); DelayMs(10);
write_com(0x0035,0x0204); DelayMs(10);
write_com(0x0036,0x0204); DelayMs(10);
write_com(0x0037,0x0502); DelayMs(10);
write_com(0x003A,0x0302); DelayMs(10);
write_com(0x003B,0x0302); DelayMs(10);
write_com(0x0023,0x0000); DelayMs(10);
write_com(0x0024,0x0000); DelayMs(10);
write_com(0x0025,0x8000); DelayMs(10);
write_com(0x004f,0); //行首址0
write_com(0x004e,0); //列首址0
}
//====================================================================================
void DispOneColor(int Color)
{
int i,j;
write_com(0x004f,0); //行首址0
write_com(0x004e,0); //列首址0
WriCom(0x22);
for(j=0;j<320;j++)
for(i=0;i<240;i++)
WriData(Color);
}
//====================================================================================
void DispClear(void)
{
DispOneColor(BLACK);
}
//==============================================
void Set_ramaddr(uint x,uint y)
{
write_com(0x004f,y); //行首址
write_com(0x004e,x); //列首址
}
//====================================================================================
void DrawPixel(uint x, uint y, int Color)
{
Set_ramaddr(x,y);
WriCom(0x22);
WriData(Color);
}
//====================================================================================
void DispPic240_320(const unsigned char *str)
{
int i;
Set_ramaddr(0,0);
WriCom(0x22);
for (i = 0; i < 240 * 320; i++)
{
WriData(*(unsigned short *)(&str[ 2 * i]));
}
}
//====================================================================================
void DispSmallPic(uint x, uint y, uint w, uint h, const uchar *str)
{
uint i,j,temp;
for(j=0;j<h;j++)
{
Set_ramaddr(x,y+j);
WriCom(0x22);
for(i=0;i<w;i++)
{ //send_data(*(unsigned short *)(&str[(j*w+i)*2])); //高位在前
temp=str[(j*w+i)*2+1]<<8; //低位在前
temp|=str[(j*w+i)*2];
WriData(temp);
}
}
}
//====================================================================================
/*
void DrawSingleHz(uint x, uint y, uchar *pHz, uint LineColor,uint FillColor, uchar Mod)
{
uchar Ch1,Ch2;
uchar i, k;
uint str;
uint OffSet;
Ch1 = *pHz;
Ch2 = *(pHz + 1);
OffSet = ((Ch1 - 0xb0)*94 + (Ch2 - 0xa1))*32;
for (i=0;i<16;i++)
{
Set_ramaddr(x,y+i);
WriCom(0x22);
str = *(HzLib + OffSet + i*2)<<8|*(HzLib + OffSet + i*2+1);
for (k=0;k<16;k++)
{
if ( str & (0x8000>>k) ) //0x8000>>k
{
WriData((uint)(LineColor&0xffff));
}
else
{
if (NORMAL == Mod)
WriData((uint)(FillColor&0xffff));
else
{
Set_ramaddr(x+k+1,y+i);
WriCom(0x22);
}
}
}
}
}
//====================================================================================
void DrawSingleAscii(uint x, uint y, uchar *pAscii, uint LineColor,uint FillColor, uchar Mod)
{
uchar i, j;
uchar str;
uint OffSet;
OffSet = (*pAscii - 32)*16;
for (i=0;i<16;i++)
{
Set_ramaddr(x,y+i);
WriCom(0x22);
str = *(AsciiLib + OffSet + i);
for (j=0;j<8;j++)
{
if ( str & (0x80>>j) ) //0x80>>j
{
WriData((uint)(LineColor&0xffff));
}
else
{
if (NORMAL == Mod)
WriData((uint)(FillColor&0xffff));
else
{
Set_ramaddr(x+j+1,y+i);
WriCom(0x22);
}
}
}
}
}
//====================================================================================
void DrawString(uint x, uint y, uchar *pStr, uint LineColor,uint FillColor, uchar Mod)
{
while(1)
{
if (*pStr == 0) {return;}
if (*pStr > 0x80) //汉字
{
DrawSingleHz(x, y, pStr, LineColor, FillColor, Mod);
x += 16;
pStr += 2;
}
else //英文字符
{
DrawSingleAscii(x, y, pStr, LineColor, FillColor, Mod);
x += 8;
pStr += 1;
}
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -