Ну вот к примеру, я нашёл такой вот код для ili9341 и STM32F103VCT
CODE
/*
* gs_ili9341.c
*
* Created on: 23 Jun 2016
* Author: Glenn
*/
#include <stdint.h>
#include<assert.h>
#include "stm32f10x.h"
#include "gui.h"
#include "gsili9341.h"
#include "gslcd.h"
/****************************************************************************
*! \brief
*gsili9341
*My ili9341 code.
*See GUIDRV_Template.c for my code that add the required
*and some optional EMWIN driver code
***************************************************************************/
void gsDelay(uint32_t mS);
extern volatile uint32_t glbMilliSecTick;
#if 0
You have to first calculate your base address. For example base address of Bank1 of NOR/SRAM Bank1~4 is 0x60000000.
This address (0x60000000) is your command address.
Then according to your Address line pin you have to calculate data address.For A16 you can callculate like this;
RAM base address = 0X60020000 = 0X60000000 +2 ^ 16 * 2 = 0X60000000 + 0X20000 = 0X60020000
This address is your data address.
Example code:
#define Bank1_LCD_D ((uint32_t) 0x60020000) // Disp Data ADDR for A16
#define Bank1_LCD_C ((uint32_t) 0x60000000) // Disp Reg ADDR
#define LCD_REG (*((volatile unsigned short *) 0x60000000))
#define LCD_RAM (*((volatile unsigned short *) 0x60020000))
#endif
#define LCD_REG (*((volatile unsigned short *) 0x60000000))
#define LCD_RAM (*((volatile unsigned short *) 0x60020000))
#define Bank1_LCD_D ((uint32_t) 0x60020000) // Disp Data ADDR for A16
#define Bank1_LCD_C ((uint32_t) 0x60000000) // Disp Reg ADDR
int LCD_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
volatile uint16_t deviceCode=0xffff;
lcdId_t id;
uint16_t temp,temp1;
#if 0
GPIO_WriteBit(LCD_RESET_GPIO,LCD_RESET_PIN,Bit_RESET); //RESET lcd
gsDelay(10);
GPIO_WriteBit(LCD_RESET_GPIO,LCD_RESET_PIN,Bit_SET);
#endif
//************* Reset LCD Driver ****************//
#if 0
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //reset
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_RESET); //RESET lcd
gsDelay(10);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_SET);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_SET); //RESET lcd
gsDelay(1);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_RESET); //RESET lcd
// Delay 1ms
gsDelay(10);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_SET);
#endif
gsDelay(120);
//************* Start Initialisation **********//
gsLCD_Backlight(100);
LCD_WR_REG(0x01); //software reset
gsDelay(5);
LCD_WR_REG(0x28); // display off
//------------power control------------------------------
LCD_WR_REG(0xc0); //power control
LCD_WR_Data(0x26);
LCD_WR_REG(0xc1); //power control
LCD_WR_Data(0x11);
LCD_WR_REG(0xc5); //vcom control
LCD_WR_Data(0x5c);//35
LCD_WR_Data(0x4c);//3E
LCD_WR_REG(0xc7); //vcom control
LCD_WR_Data(0x94);
//------------memory access control------------------------
LCD_WR_REG(0x36); // memory access control
LCD_WR_Data(0x48); //0048 my,mx,mv,ml,BGR,mh,0.0
//LCD_WR_Data(0x68); //XXXGS x,y reversed
LCD_WR_REG(0x3a); // pixel format set
LCD_WR_Data(0x55);//16bit /pixel
//----------------- frame rate------------------------------
LCD_WR_REG(0xb1); // frame rate
LCD_WR_Data(0x00);
LCD_WR_Data(0x1B); //70
#if 0
//----------------Gamma---------------------------------
LCD_WR_REG(0xf2); // 3Gamma Function Disable
LCD_WR_Data(0x08)
;
LCD_WR_REG(0x26);
LCD_WR_Data(0x01); // gamma set 4 gamma curve 01/02/04/08
//-----------------------
LCD_WR_REG(0xE0); //positive gamma correction
LCD_WR_Data(0x1f);
LCD_WR_Data(0x1a);
LCD_WR_Data(0x18);
LCD_WR_Data(0x0a);
LCD_WR_Data(0x0f);
LCD_WR_Data(0x06);
LCD_WR_Data(0x45);
LCD_WR_Data(0x87);
LCD_WR_Data(0x32);
LCD_WR_Data(0x0a);
LCD_WR_Data(0x07);
LCD_WR_Data(0x02);
LCD_WR_Data(0x07);
LCD_WR_Data(0x05);
LCD_WR_Data(0x00);
//--------------------
LCD_WR_REG(0xE1); //negamma correction
LCD_WR_Data(0x00);
LCD_WR_Data(0x25);
LCD_WR_Data(0x27);
LCD_WR_Data(0x05);
LCD_WR_Data(0x10);
LCD_WR_Data(0x09);
LCD_WR_Data(0x3a);
LCD_WR_Data(0x78);
LCD_WR_Data(0x4d);
LCD_WR_Data(0x05);
LCD_WR_Data(0x18);
LCD_WR_Data(0x0d);
LCD_WR_Data(0x38);
LCD_WR_Data(0x3a);
LCD_WR_Data(0x1f);
#endif
//--------------ddram ---------------------
LCD_WR_REG(0x2a); // column set
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0xEF); //239
LCD_WR_REG(0x2b); // page address set
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x01);
LCD_WR_Data(0x3F); //319
// LCD_WR_REG(0x34); // tearing effect off
//LCD_WR_REG(0x35); // tearing effect on
//LCD_WR_REG(0xb4); // display inversion
//LCD_WR_Data(0x00,0x00);
LCD_WR_REG(0xb7); //entry mode set. lcd voltages
LCD_WR_Data(0x07);
//-----------------display---------------------
LCD_WR_REG(0xb6); // display function control
LCD_WR_Data(0x0a);
LCD_WR_Data(0x82);
LCD_WR_Data(0x27);
LCD_WR_Data(0x00);
LCD_WR_REG(0x11); //sleep out
gsDelay(100);
LCD_WR_REG(0x29); // display on
gsDelay(100);
//LCD_WR_REG(0x2c); //memory write
gsDelay(200);
LCD_RD_Id(&id);
temp1=0;
LCD_WR_REG(0x0f); //self diagnostic test
temp= LCD_RD_REG(); //should return 0
temp1= LCD_RD_REG(); //should return 0xc and does
if(temp != 0 || temp1 !=0xc0)
{
return -1;
}
return 0;
}
//#define R34 0x22
//#define LCD_REG (*((volatile unsigned short *) 0x60000000)) /* RS = 0 */
//#define LCD_RAM (*((volatile unsigned short *) 0x60020000)) /* RS = 1 */
uint16_t LCD_ReadReg(uint8_t LCD_Reg)
{
/* Write 16-bit Index (then Read Reg) */
LCD_REG = LCD_Reg; //writes LCD_Reg to address 0x60000000
/* Read 16-bit Reg */
return (LCD_RAM); //returns the value of a read of 0x60020000
}
void LCD_DisplayOn(void)
{
LCD_WriteReg(LCD_REG_7, 0x0173);
}
void LCD_DisplayOff(void)
{
LCD_WriteReg(LCD_REG_7, 0x0000);
}
Привёл его к виду
CODE
/*
* gs_ili9341.c
*
* Created on: 23 Jun 2016
* Author: Glenn
*/
#include <stdint.h>
#include <assert.h>
#include "stm32f10x.h"
#include "gui.h"
#include "gsili9341.h"
#include "gslcd.h"
/****************************************************************************
*! \brief
*gsili9341
*My ili9341 code.
*See GUIDRV_Template.c for my code that add the required
*and some optional EMWIN driver code
***************************************************************************/
void gsDelay(uint32_t mS);
extern volatile uint32_t glbMilliSecTick;
#if 0
You have to first calculate your base address. For example base address of Bank1 of NOR/SRAM Bank1~4 is 0x60000000.
This address (0x60000000) is your command address.
Then according to your Address line pin you have to calculate data address.For A16 you can callculate like this;
RAM base address = 0X60020000 = 0X60000000 +2 ^ 16 * 2 = 0X60000000 + 0X20000 = 0X60020000
This address is your data address.
Example code:
#define Bank1_LCD_D ((uint32_t) 0x60020000) // Disp Data ADDR for A16
#define Bank1_LCD_C ((uint32_t) 0x60000000) // Disp Reg ADDR
#define LCD_REG (*((volatile unsigned short *) 0x60000000))
#define LCD_RAM (*((volatile unsigned short *) 0x60020000))
#endif
#define LCD_REG (*((volatile unsigned short *) 0x60000000))
#define LCD_RAM (*((volatile unsigned short *) 0x60020000))
#define Bank1_LCD_D ((uint32_t) 0x60020000) // Disp Data ADDR for A16
#define Bank1_LCD_C ((uint32_t) 0x60000000) // Disp Reg ADDR
int LCD_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
volatile uint16_t deviceCode=0xffff;
lcdId_t id;
uint16_t temp,temp1;
#if 0
GPIO_WriteBit(LCD_RESET_GPIO,LCD_RESET_PIN,Bit_RESET); //RESET lcd
gsDelay(10);
GPIO_WriteBit(LCD_RESET_GPIO,LCD_RESET_PIN,Bit_SET);
#endif
//************* Reset LCD Driver ****************//
#if 0
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //reset
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_RESET); //RESET lcd
gsDelay(10);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_SET);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_SET); //RESET lcd
gsDelay(1);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_RESET); //RESET lcd
// Delay 1ms
gsDelay(10);
GPIO_WriteBit(GPIOA,GPIO_Pin_3,Bit_SET);
#endif
gsDelay(120);
//************* Start Initialisation **********//
gsLCD_Backlight(100);
LCD_WR_REG(0x01); //software reset
gsDelay(5);
LCD_WR_REG(0x28); // display off
//------------power control------------------------------
LCD_WR_REG(0x00c0,0x0026); //power control
LCD_WR_REG(0x00c1,0x0011); //power control
LCD_WR_REG(0x00c5,0x005c); //vcom control 35
LCD_WR_REG(0x00c5,0x004c); //vcom control 3E
LCD_WR_REG(0x00c7,0x0094); //vcom control
//------------memory access control------------------------
LCD_WR_REG(0x0036,0x0048); // memory access control
//LCD_WR_Data(0x68); //XXXGS x,y reversed
LCD_WR_REG(0x003a,0x0055); // pixel format set 16bit /pixel
//----------------- frame rate------------------------------
LCD_WR_REG(0x00b1,0x0000); // frame rate
LCD_WR_REG(0x00b2,0x001B); //70
#if 0
//----------------Gamma---------------------------------
LCD_WR_REG(0x00f2,0x0008); // 3Gamma Function Disable
LCD_WR_REG(0x0026,0x0001); // gamma set 4 gamma curve 01/02/04/08
//-----------------------
LCD_WR_REG(0x00E0,0x001f); //positive gamma correction
LCD_WR_REG(0x00E1,0x001a);
LCD_WR_REG(0x00E2,0x0018);
LCD_WR_REG(0x00E3,0x000a);
LCD_WR_REG(0x00E4,0x000f);
LCD_WR_REG(0x00E5,0x0006);
LCD_WR_REG(0x00E6,0x0045);
LCD_WR_REG(0x00E7,0x0087);
LCD_WR_REG(0x00E8,0x0032);
LCD_WR_REG(0x00E9,0x000a);
LCD_WR_REG(0x00EA,0x0007);
LCD_WR_REG(0x00EB,0x0002);
LCD_WR_REG(0x00EC,0x0007);
LCD_WR_REG(0x00ED,0x0005);
LCD_WR_REG(0x00EE,0x0000);
//--------------------
LCD_WR_REG(0x00E1,0x0000); //negamma correction
LCD_WR_REG(0x00E2,0x0000);
LCD_WR_REG(0x00E3,0x0025);
LCD_WR_REG(0x00E4,0x0027);
LCD_WR_REG(0x00E5,0x0005);
LCD_WR_REG(0x00E6,0x0010);
LCD_WR_REG(0x00E7,0x0009);
LCD_WR_REG(0x00E8,0x003a);
LCD_WR_REG(0x00E9,0x0078);
LCD_WR_REG(0x00EA,0x004d);
LCD_WR_REG(0x00EB,0x0005);
LCD_WR_REG(0x00EC,0x0018);
LCD_WR_REG(0x00ED,0x000d);
LCD_WR_REG(0x00EE,0x0038);
LCD_WR_REG(0x00EF,0x003a);
LCD_WR_REG(0x00F0,0x001f);
#endif
//--------------ddram ---------------------
LCD_WR_REG(0x002a,0x0000); // column set
LCD_WR_REG(0x002b,0x0000);
LCD_WR_REG(0x002c,0x0000);
LCD_WR_REG(0x002d,0x00EF); //239
LCD_WR_REG(0x002b,0x0000); // page address set
LCD_WR_Data(0x002c,0x0000);
LCD_WR_Data(0x002d,0x0001);
LCD_WR_Data(0x002e,0x003F); //319
// LCD_WR_REG(0x34); // tearing effect off
//LCD_WR_REG(0x35); // tearing effect on
//LCD_WR_REG(0xb4); // display inversion
//LCD_WR_Data(0x00,0x00);
LCD_WR_REG(0x00b7,0x0007); //entry mode set. lcd voltages
//-----------------display---------------------
LCD_WR_REG(0x00b6,0x000a); // display function control
LCD_WR_REG(0x00b7,0x0082);
LCD_WR_REG(0x00b8,0x0027);
LCD_WR_REG(0x00b9,0x0000);
LCD_WR_REG(0x11); //sleep out
gsDelay(100);
LCD_WR_REG(0x29); // display on
gsDelay(100);
//LCD_WR_REG(0x2c); //memory write
gsDelay(200);
LCD_RD_Id(&id);
temp1=0;
LCD_WR_REG(0x0f); //self diagnostic test
temp= LCD_RD_REG(); //should return 0
temp1= LCD_RD_REG(); //should return 0xc and does
if(temp != 0 || temp1 !=0xc0)
{
return -1;
}
return 0;
}
//#define R34 0x22
//#define LCD_REG (*((volatile unsigned short *) 0x60000000)) /* RS = 0 */
//#define LCD_RAM (*((volatile unsigned short *) 0x60020000)) /* RS = 1 */
uint16_t LCD_ReadReg(uint8_t LCD_Reg)
{
/* Write 16-bit Index (then Read Reg) */
LCD_REG = LCD_Reg; //writes LCD_Reg to address 0x60000000
/* Read 16-bit Reg */
return (LCD_RAM); //returns the value of a read of 0x60020000
}
void LCD_DisplayOn(void)
{
LCD_WriteReg(LCD_REG_7, 0x0173);
}
void LCD_DisplayOff(void)
{
LCD_WriteReg(LCD_REG_7, 0x0000);
}
Правильно я Вас понял?