运用彩屏显现图片需求先完结彩屏的驱动程序,然后在驱动程序的基础上再编写应用程序。
彩屏的驱动程序假如写好的话,就能够一向运用了,精力首要会集在应用程序的编写就能够了,可是移植的话,要移植驱动程序。其实移植也仅仅改动那些很底层的接近处理器的那部分代码。
由于STM32F103C8的片上只要64K的FLASH,所以不能存储太多的图片数据,也就不能显现太大的图片。
一下的程序注释的比较具体,看懂了基本上就能够用了。
彩屏驱动程序的头文件lcd.h如下:
#defineucharunsignedchar
#defineuintunsignedint
#defineBus_16//16位数据形式,假如运用8位形式,请注释此句子,假如运用16位形式,请翻开此句
#defineLCD_DataPortHP1//高8位数据口,8位形式下只运用高8位
#defineLCD_DataPortLP0//低8位数据口,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);//显现图片函数
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);
驱动程序lcd.c文件如下:
#include“stm32f10x_lib.h”
#include“Lcd.h”
//存储图片数据的头文件
//#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)//自己界说位操作函数
#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//色彩数据
};
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
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/changshang/256265.html