运用彩屏显现汉字、字符和字符串,需求先完结彩屏的驱动程序,然后在驱动程序的基础上再编写应用程序。
彩屏的驱动程序假如写好的话,就能够一向运用了,精力首要会集在应用程序的编写就能够了,可是移植的话,要移植驱动程序。其实移植也仅仅改动那些很底层的接近处理器的那部分代码。
代码如下,注释比较具体,看懂了根本就能够了。
驱动程序的头文件LCD_driver.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//彩屏的分辨率为240*320
#defineLCD_SIZE_Y320
externuintcolors[];
voidLCD_Init(void);//LCD初始化函数
voidLCD_ShowString(uintx,uinty,uintFor_color,uintBk_color,char*p);//写字符串函数
voidLCD_ShowChar(uintx,uinty,uintFor_color,uintBk_color,charch);//写字符函数
voidChineseChar(uintx,uinty,intsize,uintFor_color,uintBk_color,charc);//写汉字函数
voiddelayms(intcount);
//voidLCD_Writ_Bus(charVH,charVL);//8位形式下的总线写函数
voidLCD_Writ_Bus(uintVH,uintVL);//16位形式下的总线写函数
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_driver.h”
#include”chinese.h”
#include”char.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//色彩数据是16位的
};
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
LCD_cs(1);//封闭片选使能
}
voiddelayms(intcount)//
{
inti,j;
for(i=0;i
for(j=0;j<100;j++);
}
#ifdefBus_16//条件编译-16位数据形式
//并行写入数据把数据分为高8位VH和低8位VL
voidLCD_Writ_Bus(uintVH,uintVL)//并行数据写入函数
{
//LCD_DataPortH=VH;//高位P1口
//屏蔽高8位将数据送到PA0-PA7
GPIOA->BSRR=VH&0x00ff;
GPIOA->BRR=(~VH)&0x00ff;
//GPIO_SetBits(GPIOA,VH&0x00ff);
//GPIO_ResetBits(GPIOA,(~VH&0x00ff));
//LCD_DataPortL=VL;//低位P0口
//屏蔽低8位将数据送到PB8-PB15
GPIOB->BSRR=(VL)<<8&0xff00;
GPIOB->BRR=((~VL)<<8)&0xff00;
LCD_wr(0);
LCD_wr(1);
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/dianzi/256267.html