在线时间0 小时
UID156111
ST金币0
蝴蝶豆0
注册时间2008-5-30
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
我用51都可以的,但stm32就不行,我的目的很简单,就让TFT显示出颜色就行,这是我的程序,让大家看看哪里不对:
#include "stm32f10x_lib.h"
#define GPIOA_LCD_CS GPIO_Pin_1
#define GPIOA_LCD_RS GPIO_Pin_2
#define GPIOA_LCD_WR GPIO_Pin_3
#define GPIOA_LCD_RD GPIO_Pin_8
#define GPIOA_LCD_RESET GPIO_Pin_11
#define ILI9325_CS_LOW() GPIO_ResetBits(GPIOA,GPIOA_LCD_CS)
#define ILI9325_CS_HIGH() GPIO_SetBits(GPIOA,GPIOA_LCD_CS)
#define ILI9325_RS_LOW() GPIO_ResetBits(GPIOA,GPIOA_LCD_RS)
#define ILI9325_RS_HIGH() GPIO_SetBits(GPIOA,GPIOA_LCD_RS)
#define ILI9325_WR_LOW() GPIO_ResetBits(GPIOA,GPIOA_LCD_WR)
#define ILI9325_WR_HIGH() GPIO_SetBits(GPIOA,GPIOA_LCD_WR)
#define ILI9325_RD_LOW() GPIO_ResetBits(GPIOA,GPIOA_LCD_RD)
#define ILI9325_RD_HIGH() GPIO_SetBits(GPIOA,GPIOA_LCD_RD)
#define ILI9325_RESET_LOW() GPIO_ResetBits(GPIOA,GPIOA_LCD_RESET)
#define ILI9325_RESET_HIGH() GPIO_SetBits(GPIOA,GPIOA_LCD_RESET)
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
}
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
void GPIO_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
/* Configure PD.7--PD.11 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIOA_LCD_CS | GPIOA_LCD_RS | GPIOA_LCD_WR | GPIOA_LCD_RD |
GPIOA_LCD_RESET ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure PE.00 -- PE.15 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
//延时功能函数
void ILI9325_Delay (int nCount)
{
int i;
for (i = 0; i < nCount * 250; i++)
{ }
}
void ILI9325_WriteData(unsigned int Data)
{
ILI9325_RS_HIGH();
ILI9325_RD_HIGH();
GPIO_Write(GPIOB,Data);
ILI9325_WR_LOW();
ILI9325_WR_HIGH();
}
void ILI9325_WriteCom(unsigned int Data)
{
ILI9325_RS_LOW();
ILI9325_RD_HIGH();
GPIO_Write(GPIOB,Data);
ILI9325_WR_LOW();
ILI9325_WR_HIGH();
}
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
ILI9325_WriteCom(0x0020);ILI9325_WriteData(x1);
ILI9325_WriteCom(0x0021);ILI9325_WriteData(y1);
ILI9325_WriteCom(0x0050);ILI9325_WriteData(x1);
ILI9325_WriteCom(0x0052);ILI9325_WriteData(y1);
ILI9325_WriteCom(0x0051);ILI9325_WriteData(x2);
ILI9325_WriteCom(0x0053);ILI9325_WriteData(y2);
ILI9325_WriteCom(0x0022);
}
void ILI9325_Init(void)
{
ILI9325_RESET_HIGH();
ILI9325_Delay(5);
ILI9325_RESET_LOW();
ILI9325_Delay(5);
ILI9325_RESET_HIGH();
ILI9325_Delay(5);
ILI9325_CS_LOW();
ILI9325_WriteCom(0x00E5); ILI9325_WriteData(0x78F0); // set SRAM internal timing
ILI9325_WriteCom(0x0001); ILI9325_WriteData(0x0100); // set SS and SM bit
ILI9325_WriteCom(0x0002); ILI9325_WriteData(0x0700); // set 1 line inversion
ILI9325_WriteCom(0x0003); ILI9325_WriteData(0x1030); // set GRAM write direction and BGR=1.
ILI9325_WriteCom(0x0004); ILI9325_WriteData(0x0000); // Resize register
ILI9325_WriteCom(0x0008); ILI9325_WriteData(0x0207); // set the back porch and front porch
ILI9325_WriteCom(0x0009); ILI9325_WriteData(0x0000); // set non-display area refresh cycle ISC[3:0]
ILI9325_WriteCom(0x000A); ILI9325_WriteData(0x0000); // FMARK function
ILI9325_WriteCom(0x000C); ILI9325_WriteData(0x0000); // RGB interface setting
ILI9325_WriteCom(0x000D); ILI9325_WriteData(0x0000); // Frame marker Position
ILI9325_WriteCom(0x000F); ILI9325_WriteData(0x0000); // RGB interface polarity
//*************Power On sequence ****************//
ILI9325_WriteCom(0x0010); ILI9325_WriteData(0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
ILI9325_WriteCom(0x0011); ILI9325_WriteData(0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
ILI9325_WriteCom(0x0012); ILI9325_WriteData(0x0000); // VREG1OUT voltage
ILI9325_WriteCom(0x0013); ILI9325_WriteData(0x0000); // VDV[4:0] for VCOM amplitude
ILI9325_WriteCom(0x0007); ILI9325_WriteData(0x0001);
ILI9325_Delay(50); // Dis-charge capacitor power voltage
ILI9325_WriteCom(0x0010); ILI9325_WriteData(0x1090); // 1490//SAP, BT[3:0], AP, DSTB, SLP, STB
ILI9325_WriteCom(0x0011); ILI9325_WriteData(0x0227); // DC1[2:0], DC0[2:0], VC[2:0]
ILI9325_Delay(50); // Delay 50ms
ILI9325_WriteCom(0x0012); ILI9325_WriteData(0x001F); //001C// Internal reference voltage= Vci;
ILI9325_Delay(50); // Delay 50ms
ILI9325_WriteCom(0x0013); ILI9325_WriteData(0x1500); //0x1000//1400 Set VDV[4:0] for VCOM amplitude 1A00
ILI9325_WriteCom(0x0029); ILI9325_WriteData(0x0027); //0x0012 //001a Set VCM[5:0] for VCOMH //0x0025 0034
ILI9325_WriteCom(0x002B); ILI9325_WriteData(0x000D); // Set Frame Rate 000C
ILI9325_Delay(50); // Delay 50ms
ILI9325_WriteCom(0x0020); ILI9325_WriteData(0x0000); // GRAM horizontal Address
ILI9325_WriteCom(0x0021); ILI9325_WriteData(0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
ILI9325_WriteCom(0x0030); ILI9325_WriteData(0x0000);
ILI9325_WriteCom(0x0031); ILI9325_WriteData(0x0707);
ILI9325_WriteCom(0x0032); ILI9325_WriteData(0x0307);
ILI9325_WriteCom(0x0035); ILI9325_WriteData(0x0200);
ILI9325_WriteCom(0x0036); ILI9325_WriteData(0x0008);//0207
ILI9325_WriteCom(0x0037); ILI9325_WriteData(0x0004);//0306
ILI9325_WriteCom(0x0038); ILI9325_WriteData(0x0000);//0102
ILI9325_WriteCom(0x0039); ILI9325_WriteData(0x0707);//0707
ILI9325_WriteCom(0x003C); ILI9325_WriteData(0x0002);//0702
ILI9325_WriteCom(0x003D); ILI9325_WriteData(0x1D04);//1604
//------------------ Set GRAM area ---------------//
ILI9325_WriteCom(0x0050); ILI9325_WriteData(0x0000); // Horizontal GRAM Start Address
ILI9325_WriteCom(0x0051); ILI9325_WriteData(0x00EF); // Horizontal GRAM End Address
ILI9325_WriteCom(0x0052); ILI9325_WriteData(0x0000); // Vertical GRAM Start Address
ILI9325_WriteCom(0x0053); ILI9325_WriteData(0x013F); // Vertical GRAM Start Address
ILI9325_WriteCom(0x0060); ILI9325_WriteData(0xA700); // Gate Scan Line
ILI9325_WriteCom(0x0061); ILI9325_WriteData(0x0001); // NDL,VLE, REV
ILI9325_WriteCom(0x006A); ILI9325_WriteData(0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
ILI9325_WriteCom(0x0080); ILI9325_WriteData(0x0000);
ILI9325_WriteCom(0x0081); ILI9325_WriteData(0x0000);
ILI9325_WriteCom(0x0082); ILI9325_WriteData(0x0000);
ILI9325_WriteCom(0x0083); ILI9325_WriteData(0x0000);
ILI9325_WriteCom(0x0084); ILI9325_WriteData(0x0000);
ILI9325_WriteCom(0x0085); ILI9325_WriteData(0x0000);
//-------------- Panel Control -------------------//
ILI9325_WriteCom(0x0090); ILI9325_WriteData(0x0010);
ILI9325_WriteCom(0x0092); ILI9325_WriteData(0x0600);
ILI9325_WriteCom(0x0007); ILI9325_WriteData(0x0133); // 262K color and display ON
ILI9325_CS_HIGH();
}
void Pant(unsigned int Data)
{
int i,j;
ILI9325_CS_LOW();
Address_set(0,0,240,320);
for(i=0;i |
|