基于新唐NUC120RD2BN的EBI接口的ILI9327的驅(qū)動程序
本程序采用了新唐NUC120RD2BN帶了EBI總線的CPU,因為ILI9327只有一個地址線RS,也就是命令,數(shù)據(jù)寄存器地址,而且又支持16位總線,所以把此地址線接到多余的ALE上,把ALE配置成GPIO模式,把ALE地址鎖存的時序忽略掉,直接用EBI總線驅(qū)動ILI9327的數(shù)據(jù)總線。
本文引用地址:http://m.butianyuan.cn/article/201611/323196.htm其余不多說,請查看源碼文件:ili9327.c
文件內(nèi)容如下:
* Includes ------------------------------------------------------------------*/
#include
#include
#include "DriverDrvSYS.h"
#include "DriverDrvGPIO.h"
#include "DriverDrvEBI.h"
#define TFT_BL E_GPA, 15 /* PA.15 = TFT_BL */
#define TFT_RST E_GPA, 9 /* PA.9 = TFT_RST */
#define TFT_DC E_GPB, 6 /* PB.6 = TFT_DC */
#define ILI9327_READ()(*(__IO uint16_t *)(0x60000000))
#define ILI9327_DAT(DAT) *(__IO uint16_t *)(0x60000000) = DAT
#define ILI9327_CMD(CMD){GPIOB->DOUT &= 0xffbf;*(__IO uint16_t *)(0x60000000) = CMD;GPIOB->DOUT |= 0x0040;}
/*
//make byyuanxihua@21cn.com
//BYD LCM
//BM240400-8790FTGB
//262K TFT240RGB×400dots
//
//ILI9327 is a 262,144-color single-chip SoC driver for a-TFT liquid crystal display
//with resolution of 240RGBx432 dots, comprising a 720-channel source driver, a 432-channel
//gate driver, 233,280 bytes GRAM for graphic data of 240RGBx432 dots, and power supply circuit.
_________________________________________________
|NUC120RD2BNILI9327B|
||
|PA9TFT_RST---->RESET|
|PA15TFT_BL---->BACKLIGHT|
|PB6TFT_DC---->RS|
|NCSTFT_CS---->CS|
|NWRTFT_WR---->WR|
|NRDTFT_RD---->RD|
|AD0TFT_D0<--->DB0|
|......<--->...|
|AD15TFT_D15<--->DB15|
|_______________________________________________|
*/
uint16_t color_table[16]={0x0000,0xf800,0x07e0,0x001f,0xf81f,0xffe0,0x07ff,0xffff,};
void EBI_Init(void)
{
DRVEBI_CONFIG_TsEBIConfig;
DRVEBI_TIMING_TsEBITiming;
// Open EBI function
sEBIConfig.eDataWidth= E_DRVEBI_DATA_16BIT;
sEBIConfig.eAddrWidth= E_DRVEBI_ADDR_16BIT;
sEBIConfig.u32BaseAddress = DRVEBI_BASE_ADDR;
sEBIConfig.u32Size = DRVEBI_MAX_SIZE;
DrvEBI_Open(sEBIConfig);
// Disable nWRH & nWRL for EBI support
outpw(&SYS->GPBMFP, inpw(&SYS->GPBMFP) & ~(0x3<<2));
outpw(&SYS->ALTMFP, inpw(&SYS->ALTMFP) & ~(0x3<<13));
// Configure EBI timing
//sEBITiming.eMCLKDIV = E_DRVEBI_MCLKDIV_1;// 1656.0 KHZ //Display And Read ID ERROR!!!
//sEBITiming.eMCLKDIV = E_DRVEBI_MCLKDIV_2;// 1147.0 KHZ //Display OK, But Read ID ERROR!!!
sEBITiming.eMCLKDIV = E_DRVEBI_MCLKDIV_4;// 666.7 KHZ //Display OK, And Read ID OK!!!
//sEBITiming.eMCLKDIV = E_DRVEBI_MCLKDIV_8;// 400.0 KHZ
//sEBITiming.eMCLKDIV = E_DRVEBI_MCLKDIV_16;// 211.9 KHZ
//sEBITiming.eMCLKDIV = E_DRVEBI_MCLKDIV_32;// 106.4 KHZ
sEBITiming.u8ExttALE = 0;
sEBITiming.u8ExtIR2R = 0;
sEBITiming.u8ExtIW2X = 0;
sEBITiming.u8ExttAHD = 0;
sEBITiming.u8ExttACC = 0;
DrvEBI_SetBusTiming(sEBITiming);
}
void ILI9327_READ_ID(void)
{
uint16_t i;
ILI9327_CMD(0xEF);//Device Code Read
printf("ILI9327 ID DATA: ");
for(i=1;i<=6;i++){printf("%04x ",(uint16_t)ILI9327_READ());}
printf("");
}
void ILI9327_RESET(void)
{
//PA9 PA15 PB6 is defined as GPIO;
outpw(&SYS->GPAMFP, inpw(&SYS->GPAMFP) & ~(0x1<< 9));
outpw(&SYS->GPAMFP, inpw(&SYS->GPAMFP) & ~(0x1<<15));
outpw(&SYS->GPBMFP, inpw(&SYS->GPBMFP) & ~(0x1<< 6));
//TFT_RST TFT_DC TFT_BL is defined as Output;
DrvGPIO_Open(TFT_RST, E_IO_OUTPUT);
DrvGPIO_Open(TFT_DC , E_IO_OUTPUT);
DrvGPIO_Open(TFT_BL , E_IO_OUTPUT);
DrvGPIO_SetBit(TFT_DC );
DrvGPIO_ClrBit(TFT_BL );
DrvGPIO_SetBit(TFT_RST);
DrvSYS_Delay(1000);
DrvGPIO_ClrBit(TFT_RST); // RESET LOW >= 1 ms
DrvSYS_Delay(2000);
DrvGPIO_SetBit(TFT_RST); // RESET HIGH >= 120 ms
DrvSYS_Delay(200000);
}
void ILI9327_CLEAR(uint16_t color)
{
uint16_t i,j;
for(i=0;i<240;i++)
{
for (j=0;j<400;j++){ILI9327_DAT(color);}
}
}
void Delay_1ms(int delay)
{
uint32_t i;
for(i=0;i
void ILI9327_TEST(void)
{
uint16_t i,color;
printf("%s(%d): Running: %s()",__FILE__,__LINE__,__FUNCTION__);
while(1)
{
color = color_table[(i++)%8];
printf("COLOR = 0x%04x ",color);
ILI9327_CLEAR(color);
Delay_1ms(2000); // 2s
}
}
評論