/*--------------------------------------------------------------------------- 功能: lcd 初始化 ---------------------------------------------------------------------------*/ void __lcd_ili9325_init(void) { GPIO_PowerOn(CN_GPIO_F); GPIO_PowerOn(CN_GPIO_G); GPIO_CfgPinFunc(CN_GPIO_F,10,CN_GPIO_MODE_GPIO_OUT_OD_2Mhz); GPIO_CfgPinFunc(CN_GPIO_G,8,CN_GPIO_MODE_GPIO_OUT_PP_2Mhz); lcd_backlight_off(); lcd_reset(); Djy_DelayUs(100000); if( __ili9325_read_reg() != 0x9325) { return; } __ili9325_write_reg(0x0000, 0x0001); //Start internal OSC __ili9325_write_reg(0x0001, 0x0000); // set SS=0 and SM=0 S1---S720 __ili9325_write_reg(0x0002, 0x0700); // set 1 line inversion __ili9325_write_reg(0x0003, 0x1030); // set GRAM write direction and BGR=1. __ili9325_write_reg(0x0004, 0x0000); // Resize register __ili9325_write_reg(0x0008, 0x0207); // set the back porch and front porch __ili9325_write_reg(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0] __ili9325_write_reg(0x000a, 0x0000); // FMARK function __ili9325_write_reg(0x000c, 0x0000); // RGB interface setting __ili9325_write_reg(0x000d, 0x0000); // Frame marker Position __ili9325_write_reg(0x000f, 0x0000); // RGB interface polarity //-------------power on sequence------------ __ili9325_write_reg(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB __ili9325_write_reg(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0] __ili9325_write_reg(0x0012, 0x0000); // VREG1OUT voltage __ili9325_write_reg(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude Djy_DelayUs(5000); __ili9325_write_reg(0x0010, 0x1690); // SAP, BT[3:0], AP, DSTB, SLP, STB __ili9325_write_reg(0x0011, 0x0227); // R11H=0x0221 at VCI=3.3V, DC1[2:0], DC0[2:0], VC[2:0] Djy_DelayUs(5000); __ili9325_write_reg(0x0012, 0x001d); // External reference voltage= Vci;001d Djy_DelayUs(5000); __ili9325_write_reg(0x0013, 0x0800); // R13H=1D00 when R12H=009D;VDV[4:0] for VCOM amplitude __ili9325_write_reg(0x0029, 0x0014); // R29H=0013 when R12H=009D;VCM[5:0] for VCOMH __ili9325_write_reg(0x002b, 0x000B); // Frame Rate = 96Hz Djy_DelayUs(5000); __ili9325_write_reg(0x0020, 0x0000); // GRAM horizontal Address __ili9325_write_reg(0x0021, 0x0000); // GRAM Vertical Address // ----------- Adjust the Gamma Curve ---------- __ili9325_write_reg(0x0030, 0x0007); __ili9325_write_reg(0x0031, 0x0707); __ili9325_write_reg(0x0032, 0x0006); __ili9325_write_reg(0x0035, 0x0704); __ili9325_write_reg(0x0036, 0x1F04); __ili9325_write_reg(0x0037, 0x0004); __ili9325_write_reg(0x0038, 0x0000); __ili9325_write_reg(0x0039, 0x0706); __ili9325_write_reg(0x003c, 0x0701); __ili9325_write_reg(0x003d, 0x000F); // ------------------ Set GRAM area --------------- __ili9325_write_reg(0x0050, 0x0000); // Horizontal GRAM Start Address __ili9325_write_reg(0x0051, 239); // Horizontal GRAM End Address __ili9325_write_reg(0x0052, 0x0000); // Vertical GRAM Start Address __ili9325_write_reg(0x0053, 319); // Vertical GRAM Start Address __ili9325_write_reg(0x0060, 0x2700); // GS=0 320 line __ili9325_write_reg(0x0061, 0x0001); // NDL,VLE(滚屏允许), REV(灰度翻转) __ili9325_write_reg(0x006a, 0x0000); // set scrolling line // -------------- Partial Display Control --------- __ili9325_write_reg(0x0080, 0x0000); __ili9325_write_reg(0x0081, 0x0000); __ili9325_write_reg(0x0082, 0x0000); __ili9325_write_reg(0x0083, 0x0000); __ili9325_write_reg(0x0084, 0x0000); __ili9325_write_reg(0x0085, 0x0000); // -------------- Panel Control ------------------- __ili9325_write_reg(0x0090, 0x0010); __ili9325_write_reg(0x0092, 0x0000); __ili9325_write_reg(0x0093, 0x0003); __ili9325_write_reg(0x0095, 0x0110); __ili9325_write_reg(0x0097, 0x0000); __ili9325_write_reg(0x0098, 0x0000); // Set GRAM write direction and BGR = 1 // I/D=11 (Horizontal : increment, Vertical : increment) // AM=0 (address is updated in Horizontal writing direction) __ili9325_write_reg(0x0003, 0x1030); __ili9325_write_reg(0x0007, 0x0173); // 262K color and display ON lcd_backlight_on(); }
int main(void) { int c; char buff[100]; int offset = 0; int started = 0; //ctc_clocksInit(12000000,60000000,1); //ctc_mamInit(MAM_FULLY_ENABLED); //ramvectorsInit(); //busywaitInit(); VPBDIV = 0x00000001; /* PCLK = CCLK */ PLLCFG = 0x00000024; /* Fosc=12MHz, CCLK=60MHz */ PLLCON = 0x00000001; /* enable the PLL */ PLLFEED = 0x000000AA; /* feed sequence */ PLLFEED = 0x00000055; while (!(PLLSTAT & 0x00000400)); PLLCON = 3; // enable and connect PLLFEED = 0xAA; PLLFEED = 0x55; vicInit(); uart0Init(); DBG("Initializing USB stack\n"); usbInit(); vcomInit(); DBG("Starting USB communication\n"); interruptsEnable(); usbConnect(); lcdInit(); // echo any character received (do USB stuff in interrupt) while (1) { c = vcomGetchar(); if (c != -1) { // show on console if ((c == 9) || (c == 10) || (c == 13) || ((c >= 32) && (c <= 126))) { uint8_t buf[2]; buf[0] = c; buf[1] = 0; DBG((char*) buf); } else { DBG("."); } vcomPutchar(c); if (c == 13) { DBG("Cmd entered.\n"); buff[offset] = '\0'; offset = 0; if (!strcmp(buff, "start")) { started = 1; } else if (started) { if (!strcmp(buff, "bl-on")) { lcd_backlight_on(); } else if (!strcmp(buff, "bl-off")) { lcd_backlight_off(); } else if (!strcmp(buff, "clear")) { lcdClear(); } else { lcdPrintString(buff); } } } else { buff[offset++] = c; } } } }