缥缈九哥
本程序采用了新唐NUC120RD2BN带了EBI总线的CPU,因为ILI9327只有一个地址线RS,也就是命令,数据寄存器地址,而且又支持16位总线,所以把此地址线接到多余的ALE上,把ALE配置成GPIO模式,把ALE地址锁存的时序忽略掉,直接用EBI总线驱动ILI9327的数据总线。 其余不多说,请查看源码
9G-NUC120_gls-1028.rar
(270.54 KB, 下载次数: 1881)
文件内容如下:
* 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
}
文件结束。
|
|
|