新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32學(xué)習(xí)筆記——TFT2.4彩屏顯示圖片

STM32學(xué)習(xí)筆記——TFT2.4彩屏顯示圖片

作者: 時間:2016-11-28 來源:網(wǎng)絡(luò) 收藏
利用彩屏顯示圖片需要先完成彩屏的驅(qū)動程序,然后在驅(qū)動程序的基礎(chǔ)上再編寫應(yīng)用程序。

彩屏的驅(qū)動程序如果寫好的話,就可以一直使用了,精力主要集中在應(yīng)用程序的編寫就可以了,但是移植的話,要移植驅(qū)動程序。其實移植也只是改變那些很底層的靠近處理器的那部分代碼。

本文引用地址:http://m.butianyuan.cn/article/201611/322857.htm

因為STM32F103C8的片上只有64K的FLASH,所以不能存儲太多的圖片數(shù)據(jù),也就不能顯示太大的圖片。

一下的程序注釋的比較詳細,看懂了基本上就可以用了。

彩屏驅(qū)動程序的頭文件lcd.h如下:

#defineucharunsignedchar

#defineuintunsignedint

#defineBus_16//16位數(shù)據(jù)模式,如果使用8位模式,請注釋此語句,如果使用16位模式,請打開此句

#defineLCD_DataPortHP1//高8位數(shù)據(jù)口,8位模式下只使用高8位

#defineLCD_DataPortLP0//低8位數(shù)據(jù)口,8位模式下低8位可以不接線

#defineLCD_WRGPIO_Pin_2//WR引腳定義P2^5

#defineLCD_RSGPIO_Pin_1//RS引腳定義P2^6

#defineLCD_CSGPIO_Pin_0//CS引腳定義P2^7

#defineLCD_RSTGPIO_Pin_11//RST引腳定義P3^3

#defineLCD_RDGPIO_Pin_8//RD引腳定義P3^2

#defineLCD_SIZE_X240

#defineLCD_SIZE_Y320

externuintcolors[];

externvoidpic_play(uintxStart,uintxEnd,uintyStart,uintyEnd);//顯示圖片函數(shù)

voiddelayms(intcount);

//voidLCD_Writ_Bus(charVH,charVL);

voidLCD_Init(void);

voidLCD_Writ_Bus(uintVH,uintVL);

voidLCD_Write_COM(charVH,charVL);

voidLCD_Write_DATA(charVH,charVL);

voidPant(charVH,charVL);

voidAddress_set(unsignedintx1,unsignedinty1,unsignedintx2,unsignedinty2);

驅(qū)動程序lcd.c文件如下:

#include"stm32f10x_lib.h"

#include"Lcd.h"

//存儲圖片數(shù)據(jù)的頭文件

//#include"picture.h"

#include"picture_sara.h"

#include"xiaoqian.h"

#include"yang.h"

#defineLCD_rest(x)x?GPIO_SetBits(GPIOA,LCD_RST):GPIO_ResetBits(GPIOA,LCD_RST)//自己定義位操作函數(shù)

#defineLCD_rd(x)x?GPIO_SetBits(GPIOA,LCD_RD):GPIO_ResetBits(GPIOA,LCD_RD)

#defineLCD_rs(x)x?GPIO_SetBits(GPIOB,LCD_RS):GPIO_ResetBits(GPIOB,LCD_RS)

#defineLCD_wr(x)x?GPIO_SetBits(GPIOB,LCD_WR):GPIO_ResetBits(GPIOB,LCD_WR)

#defineLCD_cs(x)x?GPIO_SetBits(GPIOB,LCD_CS):GPIO_ResetBits(GPIOB,LCD_CS)

uintcolors[]=

{

0xf800,0x07e0,0x001f,0xffe0,0x0000,0x07ff,0xf81f,0xffff//顏色數(shù)據(jù)

};

voidLCD_Init(void)//初始化LCD

{

LCD_rest(1);

delayms(5);

LCD_rest(0);

delayms(5);

LCD_rest(1);

delayms(5);

LCD_cs(0);//打開片選使能

//

LCD_Write_COM(0x00,0xE5);LCD_Write_DATA(0x78,0xF0);//setSRAMinternaltiming

LCD_Write_COM(0x00,0x01);LCD_Write_DATA(0x01,0x00);//setSSandSMbit

LCD_Write_COM(0x00,0x02);LCD_Write_DATA(0x07,0x00);//set1lineinversion

LCD_Write_COM(0x00,0x03);LCD_Write_DATA(0x10,0x30);//setGRAMwritedirectionandBGR=1.

LCD_Write_COM(0x00,0x04);LCD_Write_DATA(0x00,0x00);//Resizeregister

LCD_Write_COM(0x00,0x08);LCD_Write_DATA(0x02,0x07);//setthebackporchandfrontporch

LCD_Write_COM(0x00,0x09);LCD_Write_DATA(0x00,0x00);//setnon-displayarearefreshcycleISC[3:0]

LCD_Write_COM(0x00,0x0A);LCD_Write_DATA(0x00,0x00);//FMARKfunction

LCD_Write_COM(0x00,0x0C);LCD_Write_DATA(0x00,0x00);//RGBinterfacesetting

LCD_Write_COM(0x00,0x0D);LCD_Write_DATA(0x00,0x00);//FramemarkerPosition

LCD_Write_COM(0x00,0x0F);LCD_Write_DATA(0x00,0x00);//RGBinterfacepolarity

//

LCD_Write_COM(0x00,0x10);LCD_Write_DATA(0x00,0x00);//SAP,BT[3:0],AP,DSTB,SLP,STB

LCD_Write_COM(0x00,0x11);LCD_Write_DATA(0x00,0x07);//DC1[2:0],DC0[2:0],VC[2:0]

LCD_Write_COM(0x00,0x12);LCD_Write_DATA(0x00,0x00);//VREG1OUTvoltage

LCD_Write_COM(0x00,0x13);LCD_Write_DATA(0x00,0x00);//VDV[4:0]forVCOMamplitude

LCD_Write_COM(0x00,0x07);LCD_Write_DATA(0x00,0x01);

delayms(50);//Dis-chargecapacitorpowervoltage

LCD_Write_COM(0x00,0x10);LCD_Write_DATA(0x10,0x90);//1490//SAP,BT[3:0],AP,DSTB,SLP,STB

LCD_Write_COM(0x00,0x11);LCD_Write_DATA(0x02,0x27);//DC1[2:0],DC0[2:0],VC[2:0]

delayms(50);//Delay50ms

LCD_Write_COM(0x00,0x12);LCD_Write_DATA(0x00,0x1F);//001C//Internalreferencevoltage=Vci;

delayms(50);//Delay50ms

LCD_Write_COM(0x00,0x13);LCD_Write_DATA(0x15,0x00);//0x1000//1400SetVDV[4:0]forVCOMamplitude1A00

LCD_Write_COM(0x00,0x29);LCD_Write_DATA(0x00,0x27);//0x0012//001aSetVCM[5:0]forVCOMH//0x00250034

LCD_Write_COM(0x00,0x2B);LCD_Write_DATA(0x00,0x0D);//SetFrameRate000C

delayms(50);//Delay50ms

LCD_Write_COM(0x00,0x20);LCD_Write_DATA(0x00,0x00);//GRAMhorizontalAddress

LCD_Write_COM(0x00,0x21);LCD_Write_DATA(0x00,0x00);//GRAMVerticalAddress

//-----------AdjusttheGammaCurve----------//

LCD_Write_COM(0x00,0x30);LCD_Write_DATA(0x00,0x00);

LCD_Write_COM(0x00,0x31);LCD_Write_DATA(0x07,0x07);

LCD_Write_COM(0x00,0x32);LCD_Write_DATA(0x03,0x07);

LCD_Write_COM(0x00,0x35);LCD_Write_DATA(0x02,0x00);

LCD_Write_COM(0x00,0x36);LCD_Write_DATA(0x00,0x08);//0207

LCD_Write_COM(0x00,0x37);LCD_Write_DATA(0x00,0x04);//0306

LCD_Write_COM(0x00,0x38);LCD_Write_DATA(0x00,0x00);//0102

LCD_Write_COM(0x00,0x39);LCD_Write_DATA(0x07,0x07);//0707

LCD_Write_COM(0x00,0x3C);LCD_Write_DATA(0x00,0x02);//0702

LCD_Write_COM(0x00,0x3D);LCD_Write_DATA(0x1D,0x04);//1604

//------------------SetGRAMarea---------------//

LCD_Write_COM(0x00,0x50);LCD_Write_DATA(0x00,0x00);//HorizontalGRAMStartAddress

LCD_Write_COM(0x00,0x51);LCD_Write_DATA(0x00,0xEF);//HorizontalGRAMEndAddress

LCD_Write_COM(0x00,0x52);LCD_Write_DATA(0x00,0x00);//VerticalGRAMStartAddress

LCD_Write_COM(0x00,0x53);LCD_Write_DATA(0x01,0x3F);//VerticalGRAMStartAddress

LCD_Write_COM(0x00,0x60);LCD_Write_DATA(0xA7,0x00);//GateScanLine

LCD_Write_COM(0x00,0x61);LCD_Write_DATA(0x00,0x01);//NDL,VLE,REV

LCD_Write_COM(0x00,0x6A);LCD_Write_DATA(0x00,0x00);//setscrollingline

//--------------PartialDisplayControl---------//

LCD_Write_COM(0x00,0x80);LCD_Write_DATA(0x00,0x00);

LCD_Write_COM(0x00,0x81);LCD_Write_DATA(0x00,0x00);

LCD_Write_COM(0x00,0x82);LCD_Write_DATA(0x00,0x00);

LCD_Write_COM(0x00,0x83);LCD_Write_DATA(0x00,0x00);

LCD_Write_COM(0x00,0x84);LCD_Write_DATA(0x00,0x00);

LCD_Write_COM(0x00,0x85);LCD_Write_DATA(0x00,0x00);

//--------------PanelControl-------------------//

LCD_Write_COM(0x00,0x90);LCD_Write_DATA(0x00,0x10);

LCD_Write_COM(0x00,0x92);LCD_Write_DATA(0x06,0x00);

LCD_Write_COM(0x00,0x07);LCD_Write_DATA(0x01,0x33);//262KcoloranddisplayON


上一頁 1 2 3 下一頁

評論


技術(shù)專區(qū)

關(guān)閉