在剛剛接觸到TFT選視屏?xí)r,確實(shí)對他產(chǎn)生過恐懼感,但是韓式堅(jiān)持學(xué)習(xí)下去;在最后用它打出點(diǎn)時(shí)一切問題都迎刃而解!!因?yàn)闀螯c(diǎn)了,也就會劃線了,會劃線了也就會畫出自己的坐標(biāo)系了?。?img onload="if(this.width>620)this.width=620;" onclick="window.open(this.src)" style="cursor:pointer" real_src="http://editerupload.eepw.com.cn/fetch/20161101/321643_1_1.jpg" src="http://editerupload.eepw.com.cn/fetch/20161101/321643_1_1.jpg" type="face" />還是之前的那句話,越是高級的外圍設(shè)備,它在出廠時(shí)都會有自己的一套驅(qū)動程序!只要掌握了就可以對他進(jìn)行操作了,而不需要你去寫程序!!所以從一定意義上來講,玩轉(zhuǎn)TFT的難度要比你玩轉(zhuǎn)四位數(shù)碼管的難度?。?!確實(shí)如此!其中的樂趣只有自己去做才能體會!
本文引用地址:http://www.ex-cimer.com/article/201611/321643.htm#include
#defineuint unsigned int
#define uchar unsigned char
#defineTYPE_LCD_DATA1
#defineTYPE_LCD_COMMAND0
#defineLCD_SIZE_X128
#defineLCD_SIZE_Y160
#defineDATAP0
sbit LCD_RST= P2^7;//RST 引腳定義
sbit LCD_RD= P3^2;//RD引腳定義
sbit LCD_WR= P3^3;//WR引腳定義
sbit LCD_RS= P2^5;//RS引腳定義
sbit LCD_CS= P2^6;//CS引腳定義
//想玩轉(zhuǎn)任何一種外圍設(shè)備都必須首先了解他的引腳的作用,才能隨心所欲的移植代碼,按自己的要求去操作??!
//以下函數(shù)大多部分都是TFT的驅(qū)動函數(shù),都有自己的功能注解,了解功能后就可使用?。?br />uint colors[]=
{
0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff
};
void delay_ms(uint ms)
{
unsigned char k;
while (ms--)
{
for (k = 0; k < 228; k++)
;
}
}
void LCD_Write(uchar type, uint value)
{
LCD_CS = 0;
LCD_RS = type;// 0: command1: data
LCD_WR= 0;
DATA = (uchar)value;;
LCD_WR = 1;
LCD_CS = 1;
}
void LCD_Wirte_Data16(uint value)// color data
{
LCD_CS = 0;
LCD_RS = 1;
LCD_WR= 0;
DATA = (uchar)value;
LCD_WR= 1;
LCD_WR= 0;
DATA = (uchar)(value>>8);
LCD_WR = 1;
LCD_CS = 1;
}
void Reg_Write(uint reg,uint value)
{
LCD_Write(TYPE_LCD_COMMAND,reg);
LCD_Write(TYPE_LCD_DATA,value);
}
void LCD_SetRamAddr(uint xStart, uint xEnd, uint yStart, uint yEnd)
{
Reg_Write(0x09, xStart);
Reg_Write(0x10, yStart);
Reg_Write(0x11, xEnd);
Reg_Write(0x12, yEnd);
Reg_Write(0x18, xStart);
Reg_Write(0x19, yStart);
LCD_Write(TYPE_LCD_COMMAND,0x22);// 0x22
}
void LCD_init(void)
{
uint num;
Reg_Write(0x0001,0x0002); //MODE_SEL1
Reg_Write(0x0002,0x0012);//MODE_SEL2
Reg_Write(0x0003,0x0000);//MODE_SEL3
Reg_Write(0x0004,0x0010);//MODE_SEL3
LCD_SetRamAddr(0,127, 0,159);
for(num=20480;num>0;num--)
LCD_Wirte_Data16(0xffff);
Reg_Write(0x0005,0x0008);//VCO_MODE
Reg_Write(0x0007,0x007f);//VCOMHT_CTRL
Reg_Write(0x0008,0x0017);//VCOMLT_CTRL
Reg_Write(0x0009,0x0000);//write SRAM window start X point
Reg_Write(0x0010,0x0000);//write SRAM window start y point
Reg_Write(0x0011,0x0083);//write SRAM window end x point
Reg_Write(0x0012,0x009f);//write SRAM window end y point
Reg_Write(0x0017,0x0000);//SRAM contrl
Reg_Write(0x0018,0x0000);//SRAM x position
Reg_Write(0x0019,0x0000);//SRAM y position
Reg_Write(0x0006,0x00c5);//DAC_OP_CTRL2
delay_ms(10); //延時(shí)
}
voidLCD_clear(uchar n)
{
uint num;
LCD_SetRamAddr(0,127, 0,159);
for(num=20480;num>0;num--)//160*128=20480
{
LCD_Wirte_Data16(colors[n]);
}
}
//===============================================================
//設(shè)定當(dāng)前顯示坐標(biāo)
//入口參數(shù): x,y為當(dāng)前顯示坐標(biāo)。
//出口參數(shù): 無
//說明:本函數(shù)實(shí)際上是LCD_setwindow函數(shù)的一個(gè)特例,顯示窗口為最小,僅是一個(gè)像素點(diǎn)。
void LCD_setxy(unsigned char x,unsigned int y)
{
LCD_SetRamAddr(x,y,x,y);
}
void GUI_Point(uchar x, uint y, uint n)
{
LCD_setxy(x,y);
LCD_Wirte_Data16(colors[n]);
}
void main()
{
uint num;
P2 = 0xff;
P0 = 0xff;
LCD_init();
while(1)
{
LCD_SetRamAddr(50,100, 50,50);
for(num=2500;num>0;num--)//160*128=20480
{
LCD_Wirte_Data16(colors[2]);//比如此函數(shù)只需知道是用來設(shè)置點(diǎn)的顏色即可,以及其參數(shù)是colors[]
}
}
}
評論