利用彩屏显示图片需要先完成彩屏的驱动程序,然后在驱动程序的基础上再编写应用程序。
彩屏的驱动程序如果写好的话,就可以一直使用了,精力主要集中在应用程序的编写就可以了,但是移植的话,要移植驱动程序。其实移植也只是改变那些很底层的靠近处理器的那部分代码。
因为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