im trying to interface a Arm Cortex m3 with a ili9325 lcd controller with little success.
When i turn on the circuit the screen just flickers. i have debugged my code and it seems to be working on the uC side. At a glance, can someone tell me why all im getting is flickering?
ALSO, the pins at low state have voltage of .235 volts which is causing the backlight to illuminate! is this normal?!
#include “stm32f10x_lib.h”
#include “ili9320.h”
#include “CN16.h”
#include “HzLib_65k.h”
u16 DeviceCode;
#define White 0xFFFF
#define Black 0x0000
#define Blue 0x001F
#define Blue2 0x051F
#define Red 0xF800
#define Magenta 0xF81F
#define Green 0x07E0
#define Cyan 0x7FFF
#define Yellow 0xFFE0
//Ó²¼þÏà¹ØµÄ×Óº¯Êý
#define Set_Cs GPIO_SetBits(GPIOE,GPIO_Pin_0);
#define Clr_Cs GPIO_ResetBits(GPIOE,GPIO_Pin_0);
#define Set_Rs GPIO_SetBits(GPIOE,GPIO_Pin_1);
#define Clr_Rs GPIO_ResetBits(GPIOE,GPIO_Pin_1);
#define Set_nWr GPIO_SetBits(GPIOE,GPIO_Pin_2);
#define Clr_nWr GPIO_ResetBits(GPIOE,GPIO_Pin_2);
#define Set_nRd GPIO_SetBits(GPIOE,GPIO_Pin_3);
#define Clr_nRd GPIO_ResetBits(GPIOE,GPIO_Pin_3);
#define Set_Rst GPIO_SetBits(GPIOE,GPIO_Pin_4);
#define Clr_Rst GPIO_ResetBits(GPIOE,GPIO_Pin_4);
#define Lcd_Light_ON GPIO_SetBits(GPIOE,GPIO_Pin_5);
#define Lcd_Light_OFF GPIO_ResetBits(GPIOE,GPIO_Pin_5);
void Clk_Init (void)
{
// 1. Clocking the controller from internal HSI RC (8 MHz)
RCC_HSICmd(ENABLE);
// wait until the HSI is ready
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
// 2. Enable ext. high frequency OSC
RCC_HSEConfig(RCC_HSE_ON);
// wait until the HSE is ready
while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
// 3. Init PLL
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); // 72MHz
RCC_PLLCmd(ENABLE);
// wait until the PLL is ready
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
// 4. Set system clock dividers
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
#ifdef EMB_FLASH
// 5. Init Embedded Flash
// Zero wait state, if 0 < HCLK 24 MHz
// One wait state, if 24 MHz < HCLK 56 MHz
// Two wait states, if 56 MHz < HCLK 72 MHz
// Flash wait state
FLASH_SetLatency(FLASH_Latency_2);
// Half cycle access
FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);
// Prefetch buffer
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
#endif // EMB_FLASH
// 5. Clock system from PLL
// RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
}
/****************************************************************************
-
Ãû ³Æ£ºvoid ili9320_Initializtion()
-
¹¦ ÄÜ£º³õʼ»¯ ILI9320 ¿ØÖÆÆ÷
-
Èë¿Ú²ÎÊý£ºÎÞ
-
³ö¿Ú²ÎÊý£ºÎÞ
-
˵ Ã÷£º
-
µ÷Ó÷½·¨£ºili9320_Initializtion();
****************************************************************************/
void ili9320_Initializtion()
{
/*****************************
** Ó²¼þÁ¬½Ó˵Ã÷ **
** STM32 ili9320 **
** PE0~15 <----> DB0~15 **
** PE3 <----> nRD **
** PE1 <----> RS **
** PE2 <----> nWR **
** PE0 <----> nCS **
** PE4 <----> nReset **
** PE5 <----> BK_LED **
******************************/
u16 i;
ili9320_WriteData(0xffff);
Set_nWr;
Set_Cs;
Set_Rs;
Set_nRd;
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
ili9320_WriteRegister(0x0000,0x0001);ili9320_Delay(10000);
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
DeviceCode = ili9320_ReadRegister(0x0000);
// DeviceCode = 0x9320;
ili9320_WriteRegister(0x00e7,0x0010);
ili9320_WriteRegister(0x0000,0x0001); //start internal osc
ili9320_WriteRegister(0x0001,0x0100);
ili9320_WriteRegister(0x0002,0x0700); //power on sequence
ili9320_WriteRegister(0x0003,(1<<12)|(1<<5)|(1<<4) ); //65K
ili9320_WriteRegister(0x0004,0x0000);
ili9320_WriteRegister(0x0008,0x0207);
ili9320_WriteRegister(0x0009,0x0000);
ili9320_WriteRegister(0x000a,0x0000); //display setting
ili9320_WriteRegister(0x000c,0x0001); //display setting
ili9320_WriteRegister(0x000d,0x0000); //0f3c
ili9320_WriteRegister(0x000f,0x0000);
//Power On sequence //
ili9320_WriteRegister(0x0010,0x0000);
ili9320_WriteRegister(0x0011,0x0007);
ili9320_WriteRegister(0x0012,0x0000);
ili9320_WriteRegister(0x0013,0x0000);
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
ili9320_WriteRegister(0x0010,0x1590);
ili9320_WriteRegister(0x0011,0x0227);
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
ili9320_WriteRegister(0x0012,0x009c);
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
ili9320_WriteRegister(0x0013,0x1900);
ili9320_WriteRegister(0x0029,0x0023);
ili9320_WriteRegister(0x002b,0x000e);
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
ili9320_WriteRegister(0x0020,0x0000);
ili9320_WriteRegister(0x0021,0x0000);
///////////////////////////////////////////////////////
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
ili9320_WriteRegister(0x0030,0x0007);
ili9320_WriteRegister(0x0031,0x0707);
ili9320_WriteRegister(0x0032,0x0006);
ili9320_WriteRegister(0x0035,0x0704);
ili9320_WriteRegister(0x0036,0x1f04);
ili9320_WriteRegister(0x0037,0x0004);
ili9320_WriteRegister(0x0038,0x0000);
ili9320_WriteRegister(0x0039,0x0706);
ili9320_WriteRegister(0x003c,0x0701);
ili9320_WriteRegister(0x003d,0x000f);
for(i=50000;i>0;i–);
for(i=50000;i>0;i–);
ili9320_WriteRegister(0x0050,0x0000);
ili9320_WriteRegister(0x0051,0x00ef);
ili9320_WriteRegister(0x0052,0x0000);
ili9320_WriteRegister(0x0053,0x013f);
ili9320_WriteRegister(0x0060,0xa700);
ili9320_WriteRegister(0x0061,0x0001);
ili9320_WriteRegister(0x006a,0x0000);
ili9320_WriteRegister(0x0080,0x0000);
ili9320_WriteRegister(0x0081,0x0000);
ili9320_WriteRegister(0x0082,0x0000);
ili9320_WriteRegister(0x0083,0x0000);
ili9320_WriteRegister(0x0084,0x0000);
ili9320_WriteRegister(0x0085,0x0000);
ili9320_WriteRegister(0x0090,0x0010);
ili9320_WriteRegister(0x0092,0x0000);
ili9320_WriteRegister(0x0093,0x0003);
ili9320_WriteRegister(0x0095,0x0110);
ili9320_WriteRegister(0x0097,0x0000);
ili9320_WriteRegister(0x0098,0x0000);
//display on sequence
ili9320_WriteRegister(0x0007,0x0133);
ili9320_WriteRegister(0x0020,0x0000);
ili9320_WriteRegister(0x0021,0x0000);
for(i=50000;i>0;i–);
ili9320_Clear(0x00f8);
ili9320_Clear(0xf800);
}
/****************************************************************************
-
Ãû ³Æ£ºvoid ili9320_SetCursor(u16 x,u16 y)
-
¹¦ ÄÜ£ºÉèÖÃÆÁÄ»×ù±ê
-
Èë¿Ú²ÎÊý£ºx ÐÐ×ù±ê
-
y ÁÐ×ù±ê
-
³ö¿Ú²ÎÊý£ºÎÞ
-
˵ Ã÷£º
-
µ÷Ó÷½·¨£ºili9320_SetCursor(10,10);
****************************************************************************/
void ili9320_SetCursor(u16 x,u16 y)
{
if(DeviceCode==0x8989)
{
ili9320_WriteRegister(0x004e,y); //ÐÐ
ili9320_WriteRegister(0x004f,0x13f-x); //ÁÐ
}
else if(DeviceCode==0x9919)
{
ili9320_WriteRegister(0x004e,x); // ÐÐ
ili9320_WriteRegister(0x004f,y); // ÁÐ
}
else
{
ili9320_WriteRegister(0x0020,y); // ÐÐ
ili9320_WriteRegister(0x0021,0x13f-x); // ÁÐ
}
}
/****************************************************************************
-
Ãû ³Æ£ºvoid ili9320_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY)
-
¹¦ ÄÜ£ºÉèÖô°¿ÚÇøÓò
-
Èë¿Ú²ÎÊý£ºStartX ÐÐÆðʼ×ù±ê
-
StartY ÁÐÆðʼ×ù±ê
-
EndX ÐнáÊø×ù±ê
-
EndY ÁнáÊø×ù±ê
-
³ö¿Ú²ÎÊý£ºÎÞ
-
˵ Ã÷£º
-
µ÷Ó÷½·¨£ºili9320_SetWindows(0,0,100,100)£»
****************************************************************************/
void ili9320_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY)
{
ili9320_SetCursor(StartX,StartY);
ili9320_WriteRegister(0x0050, StartX);
ili9320_WriteRegister(0x0052, StartY);
ili9320_WriteRegister(0x0051, EndX);
ili9320_WriteRegister(0x0053, EndY);
}
/****************************************************************************
-
Ãû ³Æ£ºvoid ili9320_Clear(u16 dat)
-
¹¦ ÄÜ£º½«ÆÁÄ»Ìî³ä³ÉÖ¸¶¨µÄÑÕÉ«£¬ÈçÇåÆÁ£¬ÔòÌî³ä 0xffff
-
Èë¿Ú²ÎÊý£ºdat Ìî³äÖµ
-
³ö¿Ú²ÎÊý£ºÎÞ
-
˵ Ã÷£º
-
µ÷Ó÷½·¨£ºili9320_Clear(0xffff);
****************************************************************************/
void ili9320_Clear(u16 dat)
{
u32 i;
ili9320_SetCursor(0x0000, 0x0000);
Clr_Cs;
ili9320_WriteIndex(0x0022);
for(i=0;i<76800;i++)
{
ili9320_WriteData(dat);
}
Set_Cs;
}
/****************************************************************************
-
Ãû ³Æ£ºu16 ili9320_GetPoint(u16 x,u16 y)
-
¹¦ ÄÜ£º»ñÈ¡Ö¸¶¨×ù±êµÄÑÕÉ«Öµ
-
Èë¿Ú²ÎÊý£ºx ÐÐ×ù±ê
-
y ÁÐ×ù±ê
-
³ö¿Ú²ÎÊý£ºµ±Ç°×ù±êÑÕÉ«Öµ
-
˵ Ã÷£º
-
µ÷Ó÷½·¨£ºi=ili9320_GetPoint(10,10);
****************************************************************************/
//u16 ili9320_GetPoint(u16 x,u16 y)
//{
// ili9320_SetCursor(x,y);
// return (ili9320_BGR2RGB(ili9320_ReadRegister(0x0022)));
//}
u16 ili9320_GetPoint(u16 x,u16 y)
{
u16 temp;
ili9320_SetCursor(x,y);
Clr_Cs;
ili9320_WriteIndex(0x0022);
temp = ili9320_ReadData(); //dummy
temp = ili9320_ReadData();
Set_Cs;
if(DeviceCode!=0x7783)
temp=ili9320_BGR2RGB(temp);
return (temp);
}
/****************************************************************************
-
Ãû ³Æ£ºvoid ili9320_SetPoint(u16 x,u16 y,u16 point)
-
¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±ê»µã
-
Èë¿Ú²ÎÊý£ºx ÐÐ×ù±ê
-
y ÁÐ×ù±ê
-
point µãµÄÑÕÉ«
-
³ö¿Ú²ÎÊý£ºÎÞ
-
˵ Ã÷£º
-
µ÷Ó÷½·¨£ºili9320_SetPoint(10,10,0x0fe0);
****************************************************************************/
void ili9320_SetPoint(u16 x,u16 y,u16 point)
{
if ( (x>320)||(y>240) ) return;
ili9320_SetCursor(x,y);
Clr_Cs;
ili9320_WriteIndex(0x0022);
ili9320_WriteData(point);
Set_Cs;
}
/****************************************************************************
-
Ãû ³Æ£ºvoid ili9320_DrawPicture(u16 StartX,u16 StartY,u16 EndX,u16 EndY,u16 *pic)
-
¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±ê·¶Î§ÏÔʾһ¸±Í¼Æ¬
-
Èë¿Ú²ÎÊý£ºStartX ÐÐÆðʼ×ù±ê
-
StartY ÁÐÆðʼ×ù±ê
-
EndX ÐнáÊø×ù±ê
-
EndY ÁнáÊø×ù±ê
pic ͼƬͷָÕë
-
³ö¿Ú²ÎÊý£ºÎÞ
-
˵ Ã÷£ºÍ¼Æ¬È¡Ä£¸ñʽΪˮƽɨÃ裬16λÑÕɫģʽ
-
µ÷Ó÷½·¨£ºili9320_DrawPicture(0,0,100,100,(u16*)demo);
****************************************************************************/
void ili9320_DrawPicture(u16 StartX,u16 StartY,u16 EndX,u16 EndY,u16 *pic)
{
u16 i;
ili9320_SetWindows(StartX,StartY,EndX,EndY);
ili9320_SetCursor(StartX,StartY);
Clr_Cs;
ili9320_WriteIndex(0x0022);
for (i=0;i<(EndX*EndY);i++)
{
ili9320_WriteData(*pic++);
}
Set_Cs;
}
/****************************************************************************
-
Ãû ³Æ£ºvoid ili9320_PutChar(u16 x,u16 y,u8 c,u16 charColor,u16 bkColor)
-
¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±êÏÔʾһ¸ö8x16µãÕóµÄascii×Ö·û
-
Èë¿Ú²ÎÊý£ºx ÐÐ×ù±ê
-
y ÁÐ×ù±ê
-
charColor ×Ö·ûµÄÑÕÉ«
-
bkColor ×Ö·û±³¾°ÑÕÉ«
-
³ö¿Ú²ÎÊý£ºÎÞ
-
˵ Ã÷£ºÏÔʾ·¶Î§ÏÞ¶¨Îª¿ÉÏÔʾµÄasciiÂë
-
µ÷Ó÷½·¨£ºili9320_PutChar(10,10,‘a’,0x0000,0xffff);
****************************************************************************/
void ili9320_PutChar(u16 x,u16 y,u8 c,u16 charColor,u16 bkColor)
{
u16 i=0;
u16 j=0;
u8 tmp_char=0;
for (i=0;i<16;i++)
{
tmp_char=AsciiLib[((c-0x20)*16)+i];
for (j=0;j<8;j++)
{
if ( (tmp_char >> 7-j) & 0x01 == 0x01)
{
ili9320_SetPoint(x+j,y+i,charColor); // ×Ö·ûÑÕÉ«
}
else
{
ili9320_SetPoint(x+j,y+i,bkColor); // ±³¾°ÑÕÉ«
}
}
}
}
/****************************************************************************
-
Ãû ³Æ£ºili9320_PutCN(u16 x,u16 y,u8 *p,u16 charColor,u16 bkColor)
-
¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±êÏÔʾһ¸ö16x16µãÕóµÄËÎÌ庺×Ö
-
Èë¿Ú²ÎÊý£ºx ÐÐ×ù±ê
-
y ÁÐ×ù±ê
-
charColor ×Ö·ûµÄÑÕÉ«
-
bkColor ×Ö·û±³¾°ÑÕÉ«
-
³ö¿Ú²ÎÊý£ºÎÞ
-
˵ Ã÷£ºÏÔʾ·¶Î§ÏÞ¶¨Îª¿ÉÏÔʾµÄasciiÂë
-
µ÷Ó÷½·¨£ºili9320_PutCN(100,100,“Äã”,Red,Blue);
****************************************************************************/
void ili9320_PutCN(u16 x,u16 y,uc8 *p,u16 charColor,u16 bkColor)
{
u8 i,j;
u16 k,font_byte;
u8 *buf;
while(*p!=‘\0’)
{
for(k=0;k<3;k++)//k<×Ö¿âÊýÄ¿
{
if((p== CN16Lib[k].Font_Index[0])&&((p+1) == CN16Lib[k].Font_Index[1]))
{
buf=(u8*)(&(CN16Lib[k].Font_Code[0]));
for (i=0;i<16;i++)//16ÐÐ
{
font_byte=((u16*)buf);
for (j=0;j<16;j++)//ÿÐÐ16¸öµã
{
if (font_byte&0x01)
{
ili9320_SetPoint(x,y,charColor);//дÓÐЧµã
}
else
{
ili9320_SetPoint(x,y,bkColor);//дµ×É«
}
font_byte>>=1;
x++;
}
x-=16;
y++;
}
}
}
p+=2;
x+=16;
y-=16;
}
}
/****************************************************************************
* Ãû ³Æ£ºvoid ili9320_Test()
* ¹¦ ÄÜ£º²âÊÔÒº¾§ÆÁ
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£ºÏÔʾ²ÊÌõ£¬²âÊÔÒº¾§ÆÁÊÇ·ñÕý³£¹¤×÷
* µ÷Ó÷½·¨£ºili9320_Test();
****************************************************************************/
void ili9320_Test()
{
u8 R_data,G_data,B_data,i,j;
ili9320_SetCursor(0x00, 0x0000);
ili9320_WriteRegister(0x0050,0x00);//ˮƽ GRAMÆðʼλÖÃ
ili9320_WriteRegister(0x0051,239);//ˮƽGRAMÖÕֹλÖÃ
ili9320_WriteRegister(0x0052,0);//´¹Ö±GRAMÆðʼλÖÃ
ili9320_WriteRegister(0x0053,319);//´¹Ö±GRAMÖÕֹλÖÃ
Clr_Cs;
ili9320_WriteIndex(0x0022);
R_data=0;G_data=0;B_data=0;
for(j=0;j<50;j++)//ºìÉ«½¥Ç¿Ìõ
{
for(i=0;i<240;i++)
{R_data=i/8;ili9320_WriteData(R_data<<11|G_data<<5|B_data);
}
}
R_data=0x1f;G_data=0x3f;B_data=0x1f;
for(j=0;j<50;j++)
{
for(i=0;i<240;i++)
{
G_data=0x3f-(i/4);
B_data=0x1f-(i/8);
ili9320_WriteData(R_data<<11|G_data<<5|B_data);
}
}
//----------------------------------
R_data=0;G_data=0;B_data=0;
for(j=0;j<50;j++)//ÂÌÉ«½¥Ç¿Ìõ
{
for(i=0;i<240;i++)
{G_data=i/4;
ili9320_WriteData(R_data<<11|G_data<<5|B_data);
}
}
R_data=0x1f;G_data=0x3f;B_data=0x1f;
for(j=0;j<50;j++)
{
for(i=0;i<240;i++)
{
R_data=0x1f-(i/8);
B_data=0x1f-(i/8);
ili9320_WriteData(R_data<<11|G_data<<5|B_data);
}
}
//----------------------------------
R_data=0;G_data=0;B_data=0;
for(j=0;j<60;j++)//À¶É«½¥Ç¿Ìõ
{
for(i=0;i<240;i++)
{B_data=i/8;ili9320_WriteData(R_data<<11|G_data<<5|B_data);
}
}
B_data=0;
R_data=0x1f;G_data=0x3f;B_data=0x1f;
for(j=0;j<60;j++)
{
for(i=0;i<240;i++)
{
G_data=0x3f-(i/4);
R_data=0x1f-(i/8);
ili9320_WriteData(R_data<<11|G_data<<5|B_data);
}
}
Set_Cs;
}
/****************************************************************************
* Ãû ³Æ£ºu16 ili9320_BGR2RGB(u16 c)
* ¹¦ ÄÜ£ºRRRRRGGGGGGBBBBB ¸ÄΪ BBBBBGGGGGGRRRRR ¸ñʽ
* Èë¿Ú²ÎÊý£ºc BRG ÑÕÉ«Öµ
* ³ö¿Ú²ÎÊý£ºRGB ÑÕÉ«Öµ
* ˵ Ã÷£ºÄÚ²¿º¯Êýµ÷ÓÃ
* µ÷Ó÷½·¨£º
****************************************************************************/
u16 ili9320_BGR2RGB(u16 c)
{
u16 r, g, b, rgb;
b = (c>>0) & 0x1f;
g = (c>>5) & 0x3f;
r = (c>>11) & 0x1f;
rgb = (b<<11) + (g<<5) + (r<<0);
return( rgb );
}
/****************************************************************************
* Ãû ³Æ£ºvoid ili9320_WriteIndex(u16 idx)
* ¹¦ ÄÜ£ºÐ´ ili9320 ¿ØÖÆÆ÷¼Ä´æÆ÷µØÖ·
* Èë¿Ú²ÎÊý£ºidx ¼Ä´æÆ÷µØÖ·
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£ºµ÷ÓÃÇ°ÐèÏÈÑ¡ÖпØÖÆÆ÷£¬ÄÚ²¿º¯Êý
* µ÷Ó÷½·¨£ºili9320_WriteIndex(0x0000);
****************************************************************************/
void ili9320_WriteIndex(u16 idx)
{
Clr_Rs;
Set_nRd;
GPIOC->ODR = idx;
Clr_nWr;
Set_nWr;
}
/****************************************************************************
* Ãû ³Æ£ºvoid ili9320_WriteData(u16 dat)
* ¹¦ ÄÜ£ºÐ´ ili9320 ¼Ä´æÆ÷Êý¾Ý
* Èë¿Ú²ÎÊý£ºdat ¼Ä´æÆ÷Êý¾Ý
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£ºÏò¿ØÖÆÆ÷Ö¸¶¨µØַдÈëÊý¾Ý£¬µ÷ÓÃÇ°ÐèÏÈд¼Ä´æÆ÷µØÖ·£¬ÄÚ²¿º¯Êý
* µ÷Ó÷½·¨£ºili9320_WriteData(0x1030)
****************************************************************************/
void ili9320_WriteData(u16 data)
{
Set_Rs;
Set_nRd;
GPIOC->ODR = data;
Clr_nWr;
Set_nWr;
}
/****************************************************************************
* Ãû ³Æ£ºu16 ili9320_ReadData(void)
* ¹¦ ÄÜ£º¶ÁÈ¡¿ØÖÆÆ÷Êý¾Ý
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£º·µ»Ø¶ÁÈ¡µ½µÄÊý¾Ý
* ˵ Ã÷£ºÄÚ²¿º¯Êý
* µ÷Ó÷½·¨£ºi=ili9320_ReadData();
****************************************************************************/
u16 ili9320_ReadData(void)
{
//========================================================================
// ** **
// ** nCS ----_/------- **
// ** RS ------_/----------------------------------- **
// ** nRD -------------------------_/--------------------- **
// ** nWR --------_/--------------------------------------
// ** DB[0:15] ---------[index]----------[data]----------------------- **
// ** **
//========================================================================
unsigned short val = 0;
Set_Rs;
Set_nWr;
Clr_nRd;
GPIOC->CRH = 0x44444444;
GPIOC->CRL = 0x44444444;
val = GPIOC->IDR;
val = GPIOC->IDR;
GPIOC->CRH = 0x33333333;
GPIOC->CRL = 0x33333333;
Set_nRd;
return val;
}
/****************************************************************************
Ãû ³Æ£ºu16 ili9320_ReadRegister(u16 index)
_ ¹¦ ÄÜ£º¶ÁÈ¡Ö¸¶¨µØÖ·¼Ä´æÆ÷µÄÖµ_
* Èë¿Ú²ÎÊý£ºindex ¼Ä´æÆ÷µØÖ·
* ³ö¿Ú²ÎÊý£º¼Ä´æÆ÷Öµ
* ˵ Ã÷£ºÄÚ²¿º¯Êý
* µ÷Ó÷½·¨£ºi=ili9320_ReadRegister(0x0022);
****************************************************************************/
u16 ili9320_ReadRegister(u16 index)
{
Clr_Cs;
ili9320_WriteIndex(index);
index = ili9320_ReadData();
Set_Cs;
return index;
}
/****************************************************************************
* Ãû ³Æ£ºvoid ili9320_WriteRegister(u16 index,u16 dat)
* ¹¦ ÄÜ£ºÐ´Ö¸¶¨µØÖ·¼Ä´æÆ÷µÄÖµ
* Èë¿Ú²ÎÊý£ºindex ¼Ä´æÆ÷µØÖ·
* £ºdat ¼Ä´æÆ÷Öµ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£ºÄÚ²¿º¯Êý
* µ÷Ó÷½·¨£ºili9320_WriteRegister(0x0000,0x0001);
****************************************************************************/
void ili9320_WriteRegister(u16 index,u16 dat)
{
/************************************************************************
** **
** nCS ----_/-------
RS ------_/-----------------------------------
_ nRD ------------------------------------------------------- _
nWR --------_/--------_/-----------------------
_ DB[0:15] ---------[index]----------[data]----------------------- _
_ _
_/_
Clr_Cs;
ili9320_WriteIndex(index);
ili9320_WriteData(dat);
Set_Cs;
}
_/_
Ãû ³Æ£ºvoid ili9320_Delay(vu32 nCount)
_ ¹¦ ÄÜ£ºÑÓʱ_
_ Èë¿Ú²ÎÊý£ºnCount ÑÓʱֵ_
_ ³ö¿Ú²ÎÊý£ºÎÞ_
_ ˵ Ã÷£º_
µ÷Ó÷½·¨£ºili9320_Delay(10000);
****************************************************************************/
void ili9320_Delay(vu32 nCount)
{
for(; nCount != 0; nCount–);
}
/****************************************************************************
* Ãû ³Æ£ºvoid GUI_Text(u16 x, u16 y, u8 str,u16 Color, u16 bkColor)
_ ¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±êÏÔʾ×Ö·û´®_
* Èë¿Ú²ÎÊý£ºx ÐÐ×ù±ê
* y ÁÐ×ù±ê
* *str ×Ö·û´®
* Color ×Ö·ûÑÕÉ«
* bkColor×Ö·û±³¾°ÑÕÉ«
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£º
* µ÷Ó÷½·¨£ºGUI_Text(0,0,“0123456789”,0x0000,0xffff);
****************************************************************************/
void ili9320_writestr(u16 x, u16 y, u8 *str,u16 Color, u16 bkColor)
{
while((*str != ‘\0’))
{
ili9320_PutChar(x,y,*str++,Color,bkColor);
if(x<=311)
{
x+=8;
}
else
{
x=0;
y+=8;
}
}
}
////////////////////////////////
//
//
//
//Start MAIN function
//
//
//
//////////////////////////////
void main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
#ifdef DEBUG
debug();
#endif
// Init clock system
Clk_Init();
// GPIO Init
// Enable GPIO clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
// Assign PC to DATA(DB0:DB15)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// Assign PE to CONTROL(RS, WR, RD, CS, LED-A)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3
| GPIO_Pin_4 | GPIO_Pin_5;
GPIO_Init(GPIOE, &GPIO_InitStructure);
ili9320_Initializtion();
ili9320_Clear(0xffff);
ili9320_writestr(32, 50, “HELLO,WORLD!”,Red,Blue);
ili9320_PutCN(0,0,“HIYA”,Red,Blue);
//LOOP FOREVER
while(1)
{
}
}
#ifdef DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(“Wrong parameters value: file %s on line %d\r\n”, file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif