本程序采用了新唐NUC120RD2BN带了EBI总线的CPU,因为ILI9327只有一个地址线RS,也就是命令,数据寄存器地址,而且又支持16位总线,所以把此地址线接到多余的ALE上,把ALE配置成GPIO模式,把ALE地址锁存的时序忽略掉,直接用EBI总线驱动ILI9327的数据总线。
其余不多说,请查看源码文件:ili9327.c
文件内容如下:
* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <NUC1xx.H>
#include "Driver\DrvSYS.h"
#include "Driver\DrvGPIO.h"
#include "Driver\DrvEBI.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 by yuanxihua@21cn.com
//BYD LCM
//BM240400-8790FTGB
//262K TFT 240RGB×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.
_________________________________________________
| NUC120RD2BN ILI9327B |
| |
| PA9 TFT_RST ----> RESET |
| PA15 TFT_BL ----> BACKLIGHT |
| PB6 TFT_DC ----> RS |
| NCS TFT_CS ----> CS |
| NWR TFT_WR ----> WR |
| NRD TFT_RD ----> RD |
| AD0 TFT_D0 <---> DB0 |
| ... ... <---> ... |
| AD15 TFT_D15 <---> DB15 |
|_______________________________________________|
*/
uint16_t color_table[16]={0x0000,0xf800,0x07e0,0x001f,0xf81f,0xffe0,0x07ff,0xffff,};
void EBI_Init(void)
{
DRVEBI_CONFIG_T sEBIConfig;
DRVEBI_TIMING_T sEBITiming;
// 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("\n\r\n\r");
}
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<delay;i++)DrvSYS_Delay(1000);
}
void ILI9327_TEST(void)
{
uint16_t i,color;
printf("%s(%d): Running: %s()\n\r",__FILE__,__LINE__,__FUNCTION__);
while(1)
{
color = color_table[(i++)%8];
printf("COLOR = 0x%04x \n\r",color);
ILI9327_CLEAR(color);
Delay_1ms(2000); // 2s
}
}
void ILI9327_Init(void)
{
printf("*** ILI9327 Driver V1.00 Build by yuanxihua@21cn.com on ("__DATE__ " - " __TIME__ ")\n\r\n\r");
EBI_Init();
ILI9327_RESET();
ILI9327_READ_ID();
ILI9327_CMD(0xE9); //
ILI9327_DAT(0x20);
ILI9327_CMD(0x11); //exit_sleep_mode
DrvSYS_Delay(100000); //100 ms
ILI9327_CMD(0xD1); //VCOM Control
ILI9327_DAT(0x00);
ILI9327_DAT(0x6b);
ILI9327_DAT(0x18);
ILI9327_CMD(0xD0); //Power_Setting
ILI9327_DAT(0x07);
ILI9327_DAT(0x04);
ILI9327_DAT(0x88);
ILI9327_CMD(0x36); //set_address_mode
ILI9327_DAT(0x88);
ILI9327_CMD(0xC1); //Display_Timing_Setting for Normal/Partial Mode
ILI9327_DAT(0x10);
ILI9327_DAT(0x10);
ILI9327_DAT(0x02);
ILI9327_DAT(0x02);
ILI9327_CMD(0xC0); //Panel Driving Setting
ILI9327_DAT(0x00);
ILI9327_DAT(0x35);
ILI9327_DAT(0x00);
ILI9327_DAT(0x00);
ILI9327_DAT(0x01);
ILI9327_DAT(0x02);
ILI9327_CMD(0xC5); //Frame Rate Control
ILI9327_DAT(0x02);
ILI9327_CMD(0xD2); //Power_Setting for Normal Mode
ILI9327_DAT(0x01);
ILI9327_DAT(0x44);
ILI9327_CMD(0xC8); //Gamma Setting
ILI9327_DAT(0x00);
ILI9327_DAT(0x56);
ILI9327_DAT(0x45);
ILI9327_DAT(0x04);
ILI9327_DAT(0x03);
ILI9327_DAT(0x01);
ILI9327_DAT(0x23);
ILI9327_DAT(0x12);
ILI9327_DAT(0x77);
ILI9327_DAT(0x40);
ILI9327_DAT(0x09);
ILI9327_DAT(0x06);
ILI9327_DAT(0x88);
ILI9327_DAT(0x88);
ILI9327_DAT(0x88);
ILI9327_CMD(0x3A); //set_pixel_format
ILI9327_DAT(0x55);
ILI9327_CMD(0x2A); //set_column_address
ILI9327_DAT(0x00);
ILI9327_DAT(0x00);
ILI9327_DAT(0x00);
ILI9327_DAT(0xEF);
ILI9327_CMD(0x2B); //set_page_address
ILI9327_DAT(0x00);
ILI9327_DAT(0x20);
ILI9327_DAT(0x01);
ILI9327_DAT(0xAF);
ILI9327_CMD(0x29); //set_display_on
ILI9327_CMD(0x2C); //write_memory_start
DrvGPIO_SetBit(TFT_BL );
ILI9327_TEST();
}
void ILI9327_SLEEP(void)
{
ILI9327_CMD(0x10); //enter_sleep_mode
}
void ILI9327_WAKEUP(void)
{
ILI9327_CMD(0x11); //exit_sleep_mode
}
void EBI_test(void)
{
uint32_t i,j=0;
uint32_t data;
printf("%s(%d): Running: %s()\n\r",__FILE__,__LINE__,__FUNCTION__);
EBI_Init();
printf("MCLK of EBI colck is %d KHz.\n\r", (DrvSYS_GetHCLKFreq()/4)/1000);
//PA9 PB6 is defined as GPIO;
outpw(&SYS->GPAMFP, inpw(&SYS->GPAMFP) & ~(0x1<<9));
outpw(&SYS->GPBMFP, inpw(&SYS->GPBMFP) & ~(0x1<<6));
//TFT_RST TFT_DC TFT_BLis 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_Open(E_GPB, 1 , E_IO_OUTPUT); //LED test...
DrvGPIO_SetBit(TFT_DC );
DrvGPIO_SetBit(TFT_RST);
DrvGPIO_ClrBit(TFT_BL );
while(0)
{
//test for write
*(__IO uint16_t *)((uint32_t)0x60000000) = 0xffff;
*(__IO uint16_t *)((uint32_t)0x60000000) = 0x0000;
}
while(0)
{
//test for read
data = *(__IO uint16_t *)((uint32_t)0x60000000);
printf("Running %d Times : D15-D0:%1d%1d%1d%1d%1d%1d%1d%1d_%1d%1d%1d%1d%1d%1d%1d%1dB\n\r",j++,
(data>>15)&0x1,(data>>14)&0x1,(data>>13)&0x1,(data>>12)&0x1,
(data>>11)&0x1,(data>>10)&0x1,(data>> 9)&0x1,(data>> 8)&0x1,
(data>> 7)&0x1,(data>> 6)&0x1,(data>> 5)&0x1,(data>> 4)&0x1,
(data>> 3)&0x1,(data>> 2)&0x1,(data>> 1)&0x1,(data>> 0)&0x1);
for(i=0;i<0x200000;i++); //delay about 1 second
}
while(1)
{
printf("Running %d Times...\n\r",j++);
//test for IO
DrvGPIO_SetBit(TFT_RST);
DrvGPIO_SetBit(TFT_DC );
DrvGPIO_SetBit(TFT_BL );
GPIOB->DOUT |= (1 << 1);
for(i=0;i<0x200000;i++);
DrvGPIO_ClrBit(TFT_RST);
DrvGPIO_ClrBit(TFT_DC );
DrvGPIO_ClrBit(TFT_BL );
GPIOB->DOUT &= ~(1 << 1);
for(i=0;i<0x200000;i++);
}
}
文件结束。
最近编辑记录 缥缈九哥 (2020-05-09 20:01:56)
离线