Author Topic: Error when compile LPC17XX with TFT2N0369  (Read 11914 times)

Offline dep937

  • Newbie
  • *
  • Posts: 6
    • View Profile
Error when compile LPC17XX with TFT2N0369
« on: August 14, 2012, 08:58:41 PM »
Hi, i finally find the controller for my board, so I tried to compile it, but I get the next error. Which are the values for "GLCD_COMMAND_ADDR" and "GLCD_DATA_ADDR"?

Code: [Select]
compiling GLCD.c...
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(1541): error:  #20: identifier "GLCD_COMMAND_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(1541): error:  #20: identifier "GLCD_DATA_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\GLCD.c(277): warning:  #223-D: function "ENABLE_BACKLIGHT" declared implicitly
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(901): error:  #20: identifier "GLCD_COMMAND_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(901): error:  #20: identifier "GLCD_DATA_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(905): error:  #20: identifier "GLCD_COMMAND_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(905): error:  #20: identifier "GLCD_DATA_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(909): error:  #20: identifier "GLCD_COMMAND_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(909): error:  #20: identifier "GLCD_DATA_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(914): error:  #20: identifier "GLCD_COMMAND_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(914): error:  #20: identifier "GLCD_DATA_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\glcd_cglcd.h(918): error:  #20: identifier "GLCD_COMMAND_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\GLCD.c(1690): error:  #20: identifier "GLCD_DATA_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\GLCD.c(1703): error:  #20: identifier "GLCD_DATA_ADDR" is undefined
..\..\..\uTasker\uGLCDLIB\GLCD.c(2233): error:  #20: identifier "GLCD_DATA_ADDR" is undefined
compiling LCD.c...
compiling mass_storage.c...
Target not created


Thanks, Damian

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3091
    • View Profile
    • uTasker
Re: Error when compile LPC17XX with TFT2N0369
« Reply #1 on: August 14, 2012, 10:07:44 PM »
Hi Damien

It looks as though your board has a Truly LCD on it with integrated controller and memory. This type seems to be used in the Freescael Tower kits and so is supported in the M522xx and Kinetis projects.

The LPC17xx project supports a TFT display (without controller) using the LPC1788 with integrated LCD controller.

To use this display together with an LPC17xx without integrated LCD controller there are two possibilities (maybe also a third using SPI interface but thsi will not be discussed now); either using the external bus interface or bit-banging via ports.
I haven't seen the circuit diagram but expect that the LCD's interface is connected to the EMC (external memeory controller), which is how it is also done in the Freescale tower kits using the Kinetis or Coldfire's FlexBus.

Since this mode hasn't been used before there are no defines for it, meaning that it won't build without adding such an interface.
Below is the set of defines use by the Kinetis K40 board as reference:

Code: [Select]
// Graphic LCD
//
#if defined TFT2N0369_GLCD_MODE                                          // TWR Kit TFT display
    #define GLCD_COMMAND_ADDR     0x60400000
    #define GLCD_DATA_ADDR        0x60410000

    #define BACK_LIGHT_MAX_INTENSITY()    //PTCPAR &= ~(TC_PWM6_FUNCTION); _CONFIG_DRIVE_PORT_OUTPUT_VALUE(TC, PORT_TC_BIT3, PORT_TC_BIT3)
    #define BACK_LIGHT_MIN_INTENSITY()    //PTCPAR &= ~(TC_PWM6_FUNCTION); _CONFIG_DRIVE_PORT_OUTPUT_VALUE(TC, PORT_TC_BIT3, 0)

    #define ENABLE_BACKLIGHT()    BACK_LIGHT_MAX_INTENSITY()
    // Tower kit uses 16 bit FlexBus interface on CS0. The address range is set to 128K because the DC signal is connected on address wire. FlexBus setup as fast as possible in multiplexed mode
    // the 16 bit data appears at AD0..AD15 when the BLS bit is set (rather than AD16..AD31)
    //
        #define CONFIGURE_GLCD()      _CONFIG_PERIPHERAL(A, 9,  (PA_9_FB_AD16  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(A, 10, (PA_10_FB_AD15 | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(A, 24, (PA_24_FB_AD14 | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(A, 25, (PA_25_FB_AD13 | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(A, 26, (PA_26_FB_AD12 | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(A, 27, (PA_27_FB_AD11 | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(A, 28, (PA_28_FB_AD10 | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(D, 10, (PD_10_FB_AD9  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(D, 11, (PD_11_FB_AD8  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(D, 12, (PD_12_FB_AD7  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(D, 13, (PD_13_FB_AD6  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(D, 14, (PD_14_FB_AD5  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(E, 8,  (PE_8_FB_AD4   | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(E, 9,  (PE_9_FB_AD3   | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(E, 10, (PE_10_FB_AD2  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(E, 11, (PE_11_FB_AD1  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(E, 12, (PE_12_FB_AD0  | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(E, 7,  (PE_7_FB_CS0   | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      _CONFIG_PERIPHERAL(D, 15, (PD_15_FB_RW   | PORT_DSE_HIGH | PORT_PS_DOWN_ENABLE)); \
                                      CSAR0  = GLCD_COMMAND_ADDR; \
                                    CSMR0  = (0x00010000 | FB_CS_VALID); \
                                    CSCR0  = (FB_BLS | FB_AA | PORT_SIZE_16); \
                                      BACK_LIGHT_MIN_INTENSITY();

    #define GLCD_RST_H()
    #ifdef _WINDOWS
        #define MAX_GLCD_WRITE_BURST   10000                             // the maximum number of writes to the GLCD before the task yields
    #else
        #define MAX_GLCD_WRITE_BURST   1000                              // the maximum number of writes to the GLCD before the task yields
    #endif

  //#define SUPPORT_TOUCH_SCREEN                                         // touch screen operation
  //#define GLCD_BACKLIGHT_CONTROL                                       // (requires SUPPORT_PWM_MODULE)
  //#define TEMP_HUM_TEST
  //#define VARIABLE_PIXEL_COLOUR                                        // support control of background and pixel colors

    #define _GLCD_BACKLIGHT_TIMER         6                              // PWM channel 6 (TC)
    #define _GLCD_TIMER_MODE_OF_OPERATION (PWM_PRESCALER_128 | PWM_SCALED_CLOCK_INPUT | PWM_POLARITY)
    #define _GLCD_BACKLIGHT_PWM_FREQUENCY (unsigned char)(PWM_US_DELAY(PWM_FREQUENCY_VALUE(2000 * 128)))
#endif


What you need to do is add the same set of defines to your proiject (app_hw_lpc17xx.h)



Note that the define CONFIGURE_GLCD() is used to configure the external bus interface. Thsi will need to be changed to match the interface of your chip. Depending on where the memory range is set up for the values of GLCD_COMMAND_ADDR and GLCD_DATA_ADDR are also defined.

If the EMC is correctly configured the code should then be compatible since all reads and writes are simply memory mapped.

There are some other defines which control backlight intensity which are probably not important although you may need to be abel to control the backlight as ON or OFF via a prot (check the HW).

Good luck!

Regards

Mark



Offline dep937

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Error when compile LPC17XX with TFT2N0369
« Reply #2 on: August 15, 2012, 03:04:07 PM »
Hi Mark, thanks for your answer, my board is some kind of clone of MCB1700, with little changes, the GLCD is controlling by bit banging multiplexing 8 bits, meanwhile the MCB1700 use the 16 bits, the controller of GLCD is SSD1289.
Can you give some tips about what driver I must use, because I am wrong about it.

This is the board, is very cheap ($60 to $70)compared with MCB1700:



In this link are the schematic:

http://www.4shared.com/folder/zwrx0vOA/_online.html

Thanks

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3091
    • View Profile
    • uTasker
Re: Error when compile LPC17XX with TFT2N0369
« Reply #3 on: August 15, 2012, 09:45:05 PM »
Hi Damian

Could you post the schematic here?

The MCB1700 looks to use the serial mode of the display (all 16 data lines are tied to GND).

Does the board manufacturer also supply demonstration code for configuring and using the display?

Regards

Mark

Offline dep937

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Error when compile LPC17XX with TFT2N0369
« Reply #4 on: August 16, 2012, 12:41:11 PM »
Hi Mark, this is a general schematic:



And this is a schematic about the display:



This is the GLCD.h for keil:

Code: [Select]
#ifndef __GLCD_H
#define __GLCD_H

/* Includes ------------------------------------------------------------------*/
#include "LPC17xx.h"

/* Private define ------------------------------------------------------------*/

/* LCD Interface */
#define PIN_EN (1 << 19)
#define PIN_LE (1 << 20)
#define PIN_DIR (1 << 21)
#define PIN_CS           (1 << 22)
#define PIN_RS (1 << 23)
#define PIN_WR (1 << 24)
#define PIN_RD (1 << 25)   

#define LCD_EN(x)   ((x) ? (LPC_GPIO0->FIOSET = PIN_EN) : (LPC_GPIO0->FIOCLR = PIN_EN));
#define LCD_LE(x)   ((x) ? (LPC_GPIO0->FIOSET = PIN_LE) : (LPC_GPIO0->FIOCLR = PIN_LE));
#define LCD_DIR(x)  ((x) ? (LPC_GPIO0->FIOSET = PIN_DIR) : (LPC_GPIO0->FIOCLR = PIN_DIR));
#define LCD_CS(x)   ((x) ? (LPC_GPIO0->FIOSET = PIN_CS) : (LPC_GPIO0->FIOCLR = PIN_CS));
#define LCD_RS(x)   ((x) ? (LPC_GPIO0->FIOSET = PIN_RS) : (LPC_GPIO0->FIOCLR = PIN_RS));
#define LCD_WR(x)   ((x) ? (LPC_GPIO0->FIOSET = PIN_WR) : (LPC_GPIO0->FIOCLR = PIN_WR));
#define LCD_RD(x)   ((x) ? (LPC_GPIO0->FIOSET = PIN_RD) : (LPC_GPIO0->FIOCLR = PIN_RD));

/* LCD color */
#define Blanco         0xFFFF
#define Negro          0x0000
#define Gris           0xF7DE
#define Azul           0x001F
#define Azul2          0x051F
#define Rojo           0xF800
#define Magenta        0xF81F
#define Verde          0x07E0
#define Cyan           0x7FFF
#define Amarillo       0xFFE0

#define HZ_LIB         0
#define ASCII_LIB      1

#define RGB565CONVERT(red, green, blue)\
(uint16_t)( (( red   >> 3 ) << 11 ) | \
(( green >> 2 ) << 5  ) | \
( blue  >> 3 ))

/* Private function prototypes -----------------------------------------------*/
void LCD_Initializtion(void);
void LCD_Clear(uint16_t Color);
uint16_t LCD_BGR2RGB(uint16_t color);
uint16_t LCD_GetPoint(uint16_t Xpos,uint16_t Ypos);
void LCD_SetPoint(uint16_t Xpos,uint16_t Ypos,uint16_t point);
void LCD_DrawPoint(uint16_t Xpos,uint16_t Ypos,uint16_t point);
void LCD_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t color);
void LCD_SetWindows(uint16_t xStart,uint16_t yStart,uint16_t xLong,uint16_t yLong);
void LCD_DrawPicture(uint16_t StartX,uint16_t StartY,uint16_t EndX,uint16_t EndY,unsigned char *pic);
void GUI_Text(uint16_t Xpos, uint16_t Ypos, uint8_t *str,uint16_t Color, uint16_t bkColor);
void PutChar(unsigned short Xpos,unsigned short Ypos,unsigned char c,unsigned short charColor,unsigned short bkColor);
void PutChinese(uint16_t Xpos,uint16_t Ypos,uint8_t *str,uint16_t Color,uint16_t bkColor);
void GUI_Chinese(uint16_t Xpos, uint16_t Ypos, uint8_t *str,uint16_t Color, uint16_t bkColor);
void LCD_Boton(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Boton1(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Boton2(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov0(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov1(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov2(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov3(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov4(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov5(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov6(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov7(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Mov8(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_Imagen1(uint16_t x,uint16_t y,uint16_t pixel);
void LCD_cubo(uint16_t l,uint16_t a,uint16_t c,uint16_t x,uint16_t y);

void LCD_Background(void);

#endif

And this is the GLCD.c:

Code: [Select]
#include "GLCD.h"
#include "HzLib.h"
#include "AsciiLib.h"
#include "Background.h"
#include "SEL_0.h"
#include "SEL_1.h"
#include <math.h>

/* Private variables ---------------------------------------------------------*/
static uint16_t DeviceCode;

#define LCD_REG              (*((volatile unsigned short *) 0x60000000)) /* RS = 0 */
//#define LCD_RAM              (*((volatile unsigned short *) 0x60020000)) /* RS = 1 */

static void LCD_Configuration(void)
{
  /* Configure the LCD Control pins */

  /* EN = P0.19 , LE = P0.20 , DIR = P0.21 , CS = P0.22 , RS = P0.23 , RS = P0.23 */
  /* RS = P0.23 , WR = P0.24 , RD = P0.25 , DB[0.7] = P2.0...P2.7 , DB[8.15]= P2.0...P2.7 */ 
  LPC_GPIO0->FIODIR   |= 0x03f80000;
  LPC_GPIO0->FIOSET    = 0x03f80000;
}

static __inline void LCD_Send (uint16_t byte)
{
  LPC_GPIO2->FIODIR |= 0xFF;          /* P2.0...P2.7 Output */
  LCD_DIR(1)       /* Interface A->B */
  LCD_EN(0)                           /* Enable 2A->2B */
  LPC_GPIO2->FIOPIN =  byte;          /* Write D0..D7 */
  LCD_LE(1)                         
  LCD_LE(0)   /* latch D0..D7 */
  LPC_GPIO2->FIOPIN =  byte >> 8;     /* Write D8..D15 */
}

void wait_delay(int count)
{
  while(count--);
}

static __inline uint16_t LCD_Read (void)
{
  uint16_t value;

  LPC_GPIO2->FIODIR &= ~(0xFF);              /* P2.0...P2.7 Input */
  LCD_DIR(0);                /* Interface B->A */
  LCD_EN(0);                                /* Enable 2B->2A */
  wait_delay(80);    /* delay some times */
  value = LPC_GPIO2->FIOPIN0;                   /* Read D8..D15 */
  LCD_EN(1);                                /* Enable 1B->1A */
  wait_delay(80);    /* delay some times */
  value = (value << 8) | LPC_GPIO2->FIOPIN0;       /* Read D0..D7 */
  LCD_DIR(1);
  return  value;
}

static __inline void LCD_WriteIndex(uint16_t index)
{
  LCD_CS(0);
  LCD_RS(0);
  LCD_RD(1);
  LCD_Send( index );
  wait_delay(70);
  LCD_WR(0); 
  wait_delay(1);
  LCD_WR(1);
  LCD_CS(1);
}

static __inline void LCD_WriteData(uint16_t data)
{
  LCD_CS(0);
  LCD_RS(1);   
  LCD_Send( data );
  LCD_WR(0);     
  wait_delay(1);
  LCD_WR(1);
  LCD_CS(1);
}

static __inline uint16_t LCD_ReadData(void)
{
  uint16_t value;
 
  LCD_CS(0);
  LCD_RS(1);
  LCD_WR(1);
  LCD_RD(0);
  value = LCD_Read();

  LCD_RD(1);
  LCD_CS(1);

  return value;
}

static __inline void LCD_WriteReg(uint16_t LCD_Reg,uint16_t LCD_RegValue)
{
  /* Write 16-bit Index, then Write Reg */ 
  LCD_WriteIndex(LCD_Reg);         
  /* Write 16-bit Reg */
  LCD_WriteData(LCD_RegValue); 
}

static __inline uint16_t LCD_ReadReg(uint16_t LCD_Reg)
{
  uint16_t LCD_RAM;

  /* Write 16-bit Index (then Read Reg) */
  LCD_WriteIndex(LCD_Reg);
  /* Read 16-bit Reg */
  LCD_RAM = LCD_ReadData();     
  return LCD_RAM;
}

static void LCD_SetCursor(uint16_t Xpos,uint16_t Ypos)
{
  if(DeviceCode==0x8989)
  {
LCD_WriteReg(0x004e,Ypos);            /* Line */
    LCD_WriteReg(0x004f,0x13f-Xpos);          /* Row */
  }
  else if(DeviceCode==0x9919)
  {
    LCD_WriteReg(0x004e,Ypos);            /* Line */
    LCD_WriteReg(0x004f,0x13f-Xpos);          /* Row */
  }
  else
  {
    LCD_WriteReg(0x0020,Ypos);            /* Line */
    LCD_WriteReg(0x0021,0x13f-Xpos);          /* Row */
  }
}

static void LCD_Delay(uint16_t nCount)
{
 uint16_t TimingDelay;
 while(nCount--)
   {
    for(TimingDelay=0;TimingDelay<10000;TimingDelay++);
   }
}

void LCD_Initializtion()
{
  LCD_Configuration();
  LCD_Delay(5);  /* delay 50 ms */
  DeviceCode = LCD_ReadReg(0x0000); /* ¶ÁÈ¡ÆÁID */
  if(DeviceCode==0x9325 || DeviceCode==0x9328) /* ²»Í¬ÆÁÇý¶¯IC ³õʼ»¯²»Í¬ */
  {
    LCD_WriteReg(0x00e7,0x0010);     
    LCD_WriteReg(0x0000,0x0001);  /* start internal osc */
    LCD_WriteReg(0x0001,0x0100);     
    LCD_WriteReg(0x0002,0x0700); /* power on sequence */
LCD_WriteReg(0x0003,(1<<12)|(1<<5)|(1<<4)|(0<<3) ); /* importance */
    LCD_WriteReg(0x0004,0x0000);                                   
    LCD_WriteReg(0x0008,0x0207);            
    LCD_WriteReg(0x0009,0x0000);         
    LCD_WriteReg(0x000a,0x0000); /* display setting */       
    LCD_WriteReg(0x000c,0x0001); /* display setting */       
    LCD_WriteReg(0x000d,0x0000);        
    LCD_WriteReg(0x000f,0x0000);
    /* Power On sequence */
    LCD_WriteReg(0x0010,0x0000);   
    LCD_WriteReg(0x0011,0x0007);
    LCD_WriteReg(0x0012,0x0000);                                                                 
    LCD_WriteReg(0x0013,0x0000);                 
    LCD_Delay(5);  /* delay 50 ms */
    LCD_WriteReg(0x0010,0x1590);   
    LCD_WriteReg(0x0011,0x0227);
    LCD_Delay(5);  /* delay 50 ms */
    LCD_WriteReg(0x0012,0x009c);                 
    LCD_Delay(5);  /* delay 50 ms */
    LCD_WriteReg(0x0013,0x1900);   
    LCD_WriteReg(0x0029,0x0023);
    LCD_WriteReg(0x002b,0x000e);
    LCD_Delay(5);  /* delay 50 ms */
    LCD_WriteReg(0x0020,0x0000);                                                           
    LCD_WriteReg(0x0021,0x0000);           
    LCD_Delay(5);  /* delay 50 ms */
    LCD_WriteReg(0x0030,0x0007);
    LCD_WriteReg(0x0031,0x0707);   
    LCD_WriteReg(0x0032,0x0006);
    LCD_WriteReg(0x0035,0x0704);
    LCD_WriteReg(0x0036,0x1f04);
    LCD_WriteReg(0x0037,0x0004);
    LCD_WriteReg(0x0038,0x0000);       
    LCD_WriteReg(0x0039,0x0706);     
    LCD_WriteReg(0x003c,0x0701);
    LCD_WriteReg(0x003d,0x000f);
    LCD_Delay(5);  /* delay 50 ms */
    LCD_WriteReg(0x0050,0x0000);       
    LCD_WriteReg(0x0051,0x00ef);   
    LCD_WriteReg(0x0052,0x0000);     
    LCD_WriteReg(0x0053,0x013f);
    LCD_WriteReg(0x0060,0xa700);       
    LCD_WriteReg(0x0061,0x0001);
    LCD_WriteReg(0x006a,0x0000);
    LCD_WriteReg(0x0080,0x0000);
    LCD_WriteReg(0x0081,0x0000);
    LCD_WriteReg(0x0082,0x0000);
    LCD_WriteReg(0x0083,0x0000);
    LCD_WriteReg(0x0084,0x0000);
    LCD_WriteReg(0x0085,0x0000);
     
    LCD_WriteReg(0x0090,0x0010);     
    LCD_WriteReg(0x0092,0x0000); 
    LCD_WriteReg(0x0093,0x0003);
    LCD_WriteReg(0x0095,0x0110);
    LCD_WriteReg(0x0097,0x0000);       
    LCD_WriteReg(0x0098,0x0000); 
    /* display on sequence */   
    LCD_WriteReg(0x0007,0x0133);
   
    LCD_WriteReg(0x0020,0x0000);  /* ÐÐÊ×Ö·0 */                                                         
    LCD_WriteReg(0x0021,0x0000);  /* ÁÐÊ×Ö·0 */     
  }
  else if(DeviceCode==0x9320 || DeviceCode==0x9300)
  {
    LCD_WriteReg(0x00,0x0000);
LCD_WriteReg(0x01,0x0100); /* Driver Output Contral */
LCD_WriteReg(0x02,0x0700); /* LCD Driver Waveform Contral */
LCD_WriteReg(0x03,0x1018); /* Entry Mode Set */

LCD_WriteReg(0x04,0x0000); /* Scalling Contral */
    LCD_WriteReg(0x08,0x0202); /* Display Contral */
LCD_WriteReg(0x09,0x0000); /* Display Contral 3.(0x0000) */
LCD_WriteReg(0x0a,0x0000); /* Frame Cycle Contal.(0x0000) */
    LCD_WriteReg(0x0c,(1<<0)); /* Extern Display Interface Contral */
LCD_WriteReg(0x0d,0x0000); /* Frame Maker Position */
LCD_WriteReg(0x0f,0x0000); /* Extern Display Interface Contral 2. */

    LCD_Delay(10);  /* delay 100 ms */
LCD_WriteReg(0x07,0x0101); /* Display Contral */
    LCD_Delay(10);  /* delay 100 ms */

LCD_WriteReg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4)); /* Power Control 1.(0x16b0) */
LCD_WriteReg(0x11,0x0007); /* Power Control 2 */
LCD_WriteReg(0x12,(1<<8)|(1<<4)|(0<<0)); /* Power Control 3.(0x0138) */
LCD_WriteReg(0x13,0x0b00); /* Power Control 4 */
LCD_WriteReg(0x29,0x0000); /* Power Control 7 */

LCD_WriteReg(0x2b,(1<<14)|(1<<4));

LCD_WriteReg(0x50,0);       /* Set X Start */
LCD_WriteReg(0x51,239);     /* Set X End */
LCD_WriteReg(0x52,0);     /* Set Y Start */
LCD_WriteReg(0x53,319);     /* Set Y End */

LCD_WriteReg(0x60,0x2700); /* Driver Output Control */
LCD_WriteReg(0x61,0x0001); /* Driver Output Control */
LCD_WriteReg(0x6a,0x0000); /* Vertical Srcoll Control */

LCD_WriteReg(0x80,0x0000); /* Display Position? Partial Display 1 */
LCD_WriteReg(0x81,0x0000); /* RAM Address Start? Partial Display 1 */
LCD_WriteReg(0x82,0x0000); /* RAM Address End-Partial Display 1 */
LCD_WriteReg(0x83,0x0000); /* Displsy Position? Partial Display 2 */
LCD_WriteReg(0x84,0x0000); /* RAM Address Start? Partial Display 2 */
LCD_WriteReg(0x85,0x0000); /* RAM Address End? Partial Display 2 */

    LCD_WriteReg(0x90,(0<<7)|(16<<0)); /* Frame Cycle Contral.(0x0013) */
LCD_WriteReg(0x92,0x0000); /* Panel Interface Contral 2.(0x0000) */
LCD_WriteReg(0x93,0x0001); /* Panel Interface Contral 3. */
    LCD_WriteReg(0x95,0x0110); /* Frame Cycle Contral.(0x0110) */
LCD_WriteReg(0x97,(0<<8));
LCD_WriteReg(0x98,0x0000); /* Frame Cycle Contral */

    LCD_WriteReg(0x07,0x0173);
  }
  else if(DeviceCode==0x9331)
  {
LCD_WriteReg(0x00E7, 0x1014);
LCD_WriteReg(0x0001, 0x0100);   /* set SS and SM bit */
LCD_WriteReg(0x0002, 0x0200);   /* set 1 line inversion */
LCD_WriteReg(0x0003, 0x1030);   /* set GRAM write direction and BGR=1 */
LCD_WriteReg(0x0008, 0x0202);   /* set the back porch and front porch */
    LCD_WriteReg(0x0009, 0x0000);   /* set non-display area refresh cycle ISC[3:0] */
LCD_WriteReg(0x000A, 0x0000);   /* FMARK function */
LCD_WriteReg(0x000C, 0x0000);   /* RGB interface setting */
LCD_WriteReg(0x000D, 0x0000);   /* Frame marker Position */
LCD_WriteReg(0x000F, 0x0000);   /* RGB interface polarity */
/* Power On sequence */
LCD_WriteReg(0x0010, 0x0000);   /* SAP, BT[3:0], AP, DSTB, SLP, STB */
LCD_WriteReg(0x0011, 0x0007);   /* DC1[2:0], DC0[2:0], VC[2:0] */
LCD_WriteReg(0x0012, 0x0000);   /* VREG1OUT voltage */
LCD_WriteReg(0x0013, 0x0000);   /* VDV[4:0] for VCOM amplitude */
    LCD_Delay(20);                  /* delay 200 ms */
LCD_WriteReg(0x0010, 0x1690);   /* SAP, BT[3:0], AP, DSTB, SLP, STB */
LCD_WriteReg(0x0011, 0x0227);   /* DC1[2:0], DC0[2:0], VC[2:0] */
    LCD_Delay(5);                   /* delay 50 ms */
LCD_WriteReg(0x0012, 0x000C);   /* Internal reference voltage= Vci */
    LCD_Delay(5);                    /* delay 50 ms */
LCD_WriteReg(0x0013, 0x0800);   /* Set VDV[4:0] for VCOM amplitude */
LCD_WriteReg(0x0029, 0x0011);   /* Set VCM[5:0] for VCOMH */
LCD_WriteReg(0x002B, 0x000B);   /* Set Frame Rate */
    LCD_Delay(5);                   /* delay 50 ms */
LCD_WriteReg(0x0020, 0x0000);   /* GRAM horizontal Address */
LCD_WriteReg(0x0021, 0x0000);   /* GRAM Vertical Address */
/* Adjust the Gamma Curve */
LCD_WriteReg(0x0030, 0x0000);
LCD_WriteReg(0x0031, 0x0106);
LCD_WriteReg(0x0032, 0x0000);
LCD_WriteReg(0x0035, 0x0204);
LCD_WriteReg(0x0036, 0x160A);
LCD_WriteReg(0x0037, 0x0707);
LCD_WriteReg(0x0038, 0x0106);
LCD_WriteReg(0x0039, 0x0707);
LCD_WriteReg(0x003C, 0x0402);
LCD_WriteReg(0x003D, 0x0C0F);
/* Set GRAM area */
LCD_WriteReg(0x0050, 0x0000);   /* Horizontal GRAM Start Address */
LCD_WriteReg(0x0051, 0x00EF);   /* Horizontal GRAM End Address */
LCD_WriteReg(0x0052, 0x0000);   /* Vertical GRAM Start Address */
LCD_WriteReg(0x0053, 0x013F);   /* Vertical GRAM Start Address */
LCD_WriteReg(0x0060, 0x2700);   /* Gate Scan Line */
LCD_WriteReg(0x0061, 0x0001);   /*  NDL,VLE, REV */
LCD_WriteReg(0x006A, 0x0000);   /* set scrolling line */
/* Partial Display Control */
LCD_WriteReg(0x0080, 0x0000);
LCD_WriteReg(0x0081, 0x0000);
LCD_WriteReg(0x0082, 0x0000);
LCD_WriteReg(0x0083, 0x0000);
LCD_WriteReg(0x0084, 0x0000);
LCD_WriteReg(0x0085, 0x0000);
/* Panel Control */
LCD_WriteReg(0x0090, 0x0010);
LCD_WriteReg(0x0092, 0x0600);
LCD_WriteReg(0x0007,0x0021);
    LCD_Delay(5);                   /* delay 50 ms */
LCD_WriteReg(0x0007,0x0061);
    LCD_Delay(5);                   /* delay 50 ms */
LCD_WriteReg(0x0007,0x0133);    /* 262K color and display ON */
    LCD_Delay(5);                   /* delay 50 ms */
  }
  else if(DeviceCode==0x9919)
  {
    /* POWER ON &RESET DISPLAY OFF */
LCD_WriteReg(0x28,0x0006);
LCD_WriteReg(0x00,0x0001);
LCD_WriteReg(0x10,0x0000);
LCD_WriteReg(0x01,0x72ef);
LCD_WriteReg(0x02,0x0600);
LCD_WriteReg(0x03,0x6a38);
LCD_WriteReg(0x11,0x6874);
LCD_WriteReg(0x0f,0x0000);    /* RAM WRITE DATA MASK */
LCD_WriteReg(0x0b,0x5308);    /* RAM WRITE DATA MASK */
LCD_WriteReg(0x0c,0x0003);
LCD_WriteReg(0x0d,0x000a);
LCD_WriteReg(0x0e,0x2e00); 
LCD_WriteReg(0x1e,0x00be);
LCD_WriteReg(0x25,0x8000);
LCD_WriteReg(0x26,0x7800);
LCD_WriteReg(0x27,0x0078);
LCD_WriteReg(0x4e,0x0000);
LCD_WriteReg(0x4f,0x0000);
LCD_WriteReg(0x12,0x08d9);
/* Adjust the Gamma Curve */
LCD_WriteReg(0x30,0x0000);
LCD_WriteReg(0x31,0x0104);
LCD_WriteReg(0x32,0x0100);
    LCD_WriteReg(0x33,0x0305);
    LCD_WriteReg(0x34,0x0505);
LCD_WriteReg(0x35,0x0305);
    LCD_WriteReg(0x36,0x0707);
    LCD_WriteReg(0x37,0x0300);
LCD_WriteReg(0x3a,0x1200);
LCD_WriteReg(0x3b,0x0800);
    LCD_WriteReg(0x07,0x0033);
  }
  else if(DeviceCode==0x1505)
  {
    /* second release on 3/5  ,luminance is acceptable,water wave appear during camera preview */
    LCD_WriteReg(0x0007,0x0000);
    LCD_Delay(5);                   /* delay 50 ms */
    LCD_WriteReg(0x0012,0x011C);    /* why need to set several times? */
    LCD_WriteReg(0x00A4,0x0001);    /* NVM */
    LCD_WriteReg(0x0008,0x000F);
    LCD_WriteReg(0x000A,0x0008);
    LCD_WriteReg(0x000D,0x0008);   
    /* GAMMA CONTROL */
    LCD_WriteReg(0x0030,0x0707);
    LCD_WriteReg(0x0031,0x0007);
    LCD_WriteReg(0x0032,0x0603);
    LCD_WriteReg(0x0033,0x0700);
    LCD_WriteReg(0x0034,0x0202);
    LCD_WriteReg(0x0035,0x0002);
    LCD_WriteReg(0x0036,0x1F0F);
    LCD_WriteReg(0x0037,0x0707);
    LCD_WriteReg(0x0038,0x0000);
    LCD_WriteReg(0x0039,0x0000);
    LCD_WriteReg(0x003A,0x0707);
    LCD_WriteReg(0x003B,0x0000);
    LCD_WriteReg(0x003C,0x0007);
    LCD_WriteReg(0x003D,0x0000);
    LCD_Delay(5);                   /* delay 50 ms */
    LCD_WriteReg(0x0007,0x0001);
    LCD_WriteReg(0x0017,0x0001);    /* Power supply startup enable */
    LCD_Delay(5);                   /* delay 50 ms */
    /* power control */
    LCD_WriteReg(0x0010,0x17A0);
    LCD_WriteReg(0x0011,0x0217);    /* reference voltage VC[2:0]   Vciout = 1.00*Vcivl */
    LCD_WriteReg(0x0012,0x011E);    /* Vreg1out = Vcilvl*1.80   is it the same as Vgama1out ? */
    LCD_WriteReg(0x0013,0x0F00);    /* VDV[4:0]-->VCOM Amplitude VcomL = VcomH - Vcom Ampl */
    LCD_WriteReg(0x002A,0x0000); 
    LCD_WriteReg(0x0029,0x000A);    /* Vcomh = VCM1[4:0]*Vreg1out    gate source voltage?? */
    LCD_WriteReg(0x0012,0x013E);    /* power supply on */
    /* Coordinates Control */
    LCD_WriteReg(0x0050,0x0000);
    LCD_WriteReg(0x0051,0x00EF);
    LCD_WriteReg(0x0052,0x0000);
    LCD_WriteReg(0x0053,0x013F);
    /* Pannel Image Control */
    LCD_WriteReg(0x0060,0x2700);
    LCD_WriteReg(0x0061,0x0001);
    LCD_WriteReg(0x006A,0x0000);
    LCD_WriteReg(0x0080,0x0000);
    /* Partial Image Control */
    LCD_WriteReg(0x0081,0x0000);
    LCD_WriteReg(0x0082,0x0000);
    LCD_WriteReg(0x0083,0x0000);
    LCD_WriteReg(0x0084,0x0000);
    LCD_WriteReg(0x0085,0x0000);
    /* Panel Interface Control */
    LCD_WriteReg(0x0090,0x0013);      /* frenqucy */
    LCD_WriteReg(0x0092,0x0300);
    LCD_WriteReg(0x0093,0x0005);
    LCD_WriteReg(0x0095,0x0000);
    LCD_WriteReg(0x0097,0x0000);
    LCD_WriteReg(0x0098,0x0000);
 
    LCD_WriteReg(0x0001,0x0100);
    LCD_WriteReg(0x0002,0x0700);
    LCD_WriteReg(0x0003,0x1030);
    LCD_WriteReg(0x0004,0x0000);
    LCD_WriteReg(0x000C,0x0000);
    LCD_WriteReg(0x000F,0x0000);
    LCD_WriteReg(0x0020,0x0000);
    LCD_WriteReg(0x0021,0x0000);
    LCD_WriteReg(0x0007,0x0021);
    LCD_Delay(20);                   /* delay 200 ms */
    LCD_WriteReg(0x0007,0x0061);
    LCD_Delay(20);                   /* delay 200 ms */
    LCD_WriteReg(0x0007,0x0173);
    LCD_Delay(20);                   /* delay 200 ms */
  }
  else if(DeviceCode==0x8989)
  {
    LCD_WriteReg(0x0000,0x0001);    LCD_Delay(5);   /* ´ò¿ª¾§Õñ */
    LCD_WriteReg(0x0003,0xA8A4);    LCD_Delay(5);   
    LCD_WriteReg(0x000C,0x0000);    LCD_Delay(5);   
    LCD_WriteReg(0x000D,0x080C);    LCD_Delay(5);   
    LCD_WriteReg(0x000E,0x2B00);    LCD_Delay(5);   
    LCD_WriteReg(0x001E,0x00B0);    LCD_Delay(5);   
    LCD_WriteReg(0x0001,0x2B3F);    LCD_Delay(5);   /* Çý¶¯Êä³ö¿ØÖÆ320*240 0x2B3F */
    LCD_WriteReg(0x0002,0x0600);    LCD_Delay(5);
    LCD_WriteReg(0x0010,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0011,0x6070);    LCD_Delay(5);   /* ¶¨ÒåÊý¾Ý¸ñʽ 16λɫ ºáÆÁ 0x6070 */
    LCD_WriteReg(0x0005,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0006,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0016,0xEF1C);    LCD_Delay(5);
    LCD_WriteReg(0x0017,0x0003);    LCD_Delay(5);
    LCD_WriteReg(0x0007,0x0133);    LCD_Delay(5);         
    LCD_WriteReg(0x000B,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x000F,0x0000);    LCD_Delay(5);   /* ɨÃ迪ʼµØÖ· */
    LCD_WriteReg(0x0041,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0042,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0048,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0049,0x013F);    LCD_Delay(5);
    LCD_WriteReg(0x004A,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x004B,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0044,0xEF00);    LCD_Delay(5);
    LCD_WriteReg(0x0045,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0046,0x013F);    LCD_Delay(5);
    LCD_WriteReg(0x0030,0x0707);    LCD_Delay(5);
    LCD_WriteReg(0x0031,0x0204);    LCD_Delay(5);
    LCD_WriteReg(0x0032,0x0204);    LCD_Delay(5);
    LCD_WriteReg(0x0033,0x0502);    LCD_Delay(5);
    LCD_WriteReg(0x0034,0x0507);    LCD_Delay(5);
    LCD_WriteReg(0x0035,0x0204);    LCD_Delay(5);
    LCD_WriteReg(0x0036,0x0204);    LCD_Delay(5);
    LCD_WriteReg(0x0037,0x0502);    LCD_Delay(5);
    LCD_WriteReg(0x003A,0x0302);    LCD_Delay(5);
    LCD_WriteReg(0x003B,0x0302);    LCD_Delay(5);
    LCD_WriteReg(0x0023,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0024,0x0000);    LCD_Delay(5);
    LCD_WriteReg(0x0025,0x8000);    LCD_Delay(5);
    LCD_WriteReg(0x004f,0);        /* ÐÐÊ×Ö·0 */
    LCD_WriteReg(0x004e,0);        /* ÁÐÊ×Ö·0 */
  }
  LCD_Delay(5);  /* delay 50 ms */
}

void LCD_SetWindows(uint16_t xStart,uint16_t yStart,uint16_t xLong,uint16_t yLong)
{
  LCD_SetCursor(xStart,yStart);
  LCD_WriteReg(0x0050,xStart);         /* ˮƽGRAMÆðʼλÖà */
  LCD_WriteReg(0x0051,xStart+xLong-1); /* ˮƽGRAMÖÕֹλÖà */
  LCD_WriteReg(0x0052,yStart);         /* ´¹Ö±GRAMÆðʼλÖà */
  LCD_WriteReg(0x0053,yStart+yLong-1); /* ´¹Ö±GRAMÖÕֹλÖà */
}

void LCD_Clear(uint16_t Color)
{
  uint32_t index=0;
  LCD_SetCursor(0,0);
  LCD_WriteIndex(0x0022);
  for(index=0;index<76800;index++)
  {
     LCD_WriteData(Color);
  }
}

uint16_t LCD_GetPoint(uint16_t Xpos,uint16_t Ypos)
{
  uint16_t dummy;

  LCD_SetCursor(Xpos,Ypos);
  LCD_WriteIndex(0x0022);
  dummy = LCD_ReadData();   /* ¿Õ¶ÁÒ»´Î */
  dummy = LCD_ReadData();

  if( DeviceCode==0x7783 || DeviceCode==0x4531 || DeviceCode==0x8989 )
    return dummy;
  else
    return LCD_BGR2RGB( dummy );
}

void LCD_SetPoint(uint16_t Xpos,uint16_t Ypos,uint16_t point)
{
  LCD_SetCursor(Xpos,Ypos);
  LCD_WriteReg(0x0022,point);
}


void LCD_DrawPoint(uint16_t Xpos,uint16_t Ypos,uint16_t point)
{
  LCD_SetCursor(Xpos,Ypos);
  LCD_WriteReg(0x0022,point);
}

void LCD_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t color)
{
  uint16_t x,y;
  uint16_t dx;      /* abs(x1 - x0) */
  uint16_t dy;      /* abs(y1 - y0) */

if(y0==y1)
{
if(x0<=x1)
{
x=x0;
}
else
{
x=x1;
x1=x0;
}
  while(x <= x1)
  {
    LCD_SetPoint(x,y0,color);
    x++;
  }
  return;
}
else if(y0>y1)
{
dy=y0-y1;
}
else
{
dy=y1-y0;
}
 
  if(x0==x1)
{
if(y0<=y1)
{
y=y0;
}
else
{
y=y1;
y1=y0;
}
  while(y <= y1)
  {
    LCD_SetPoint(x0,y,color);
    y++;
  }
  return;
}
else if(x0 > x1)
  {
dx=x0-x1;
  x = x1;
  x1 = x0;
  y = y1;
  y1 = y0;
  }
  else
  {
dx=x1-x0;
  x = x0;
  y = y0;
  }

  if(dx == dy)
  {
  while(x <= x1)
  {

    x++;
if(y>y1)
{
y--;
}
else
{
    y++;
}
    LCD_SetPoint(x,y,color);
  }
  }
  else
  {
  LCD_SetPoint(x, y, color);
  if(y < y1)
  {
    if(dx > dy)
    {
    int16_t p = dy * 2 - dx;
    int16_t twoDy = 2 * dy;
    int16_t twoDyMinusDx = 2 * (dy - dx);
    while(x < x1)
    {
      x++;
      if(p < 0)
      {
      p += twoDy;
      }
      else
      {
      y++;
      p += twoDyMinusDx;
      }
      LCD_SetPoint(x, y,color);
    }
    }
    else
    {
    int16_t p = dx * 2 - dy;
    int16_t twoDx = 2 * dx;
    int16_t twoDxMinusDy = 2 * (dx - dy);
    while(y < y1)
    {
      y++;
      if(p < 0)
      {
      p += twoDx;
      }
      else
      {
      x++;
      p+= twoDxMinusDy;
      }
      LCD_SetPoint(x, y, color);
    }
    }
  }
  else
  {
    if(dx > dy)
    {
    int16_t p = dy * 2 - dx;
    int16_t twoDy = 2 * dy;
    int16_t twoDyMinusDx = 2 * (dy - dx);
    while(x < x1)
    {
      x++;
      if(p < 0)
      {
      p += twoDy;
      }
      else
      {
      y--;
      p += twoDyMinusDx;
    }
      LCD_SetPoint(x, y,color);
    }
    }
    else
    {
    int16_t p = dx * 2 - dy;
    int16_t twoDx = 2 * dx;
    int16_t twoDxMinusDy = 2 * (dx - dy);
    while(y1 < y)
    {
      y--;
      if(p < 0)
      {
      p += twoDx;
      }
      else
      {
      x++;
      p+= twoDxMinusDy;
    }
      LCD_SetPoint(x, y,color);
    }
    }
  }
  }
}

uint16_t LCD_BGR2RGB(uint16_t color)
{
  uint16_t  r, g, b, rgb;

  b = ( color>>0 )  & 0x1f;
  g = ( color>>5 )  & 0x3f;
  r = ( color>>11 ) & 0x1f;
 
  rgb =  (b<<11) + (g<<5) + (r<<0);

  return( rgb );
}

#if ASCII_LIB > 0

void PutChar(unsigned short Xpos,unsigned short Ypos,unsigned char c,unsigned short charColor,unsigned short bkColor)
{
  unsigned short i=0;
  unsigned short j=0;
  unsigned char buffer[16];
  unsigned char tmp_char=0;
  GetASCIICode(buffer,c);  /* È¡×ÖÄ£Êý¾Ý */
  for (i=0;i<16;i++)
  {
    tmp_char=buffer[i];
    for (j=0;j<8;j++)
    {
      if ( ((tmp_char >> (7-j)) & 0x01) == 0x01)
        {
          LCD_SetPoint(Xpos+j,Ypos+i,charColor);  /* ×Ö·ûÑÕÉ« */
        }
        else
        {
          LCD_SetPoint(Xpos+j,Ypos+i,bkColor);  /* ±³¾°ÑÕÉ« */
        }
    }
  }
}

void GUI_Text(uint16_t Xpos, uint16_t Ypos, uint8_t *str,uint16_t Color, uint16_t bkColor)
{
uint8_t TempChar;
 do
  {
    TempChar=*str++;
    PutChar(Xpos,Ypos,TempChar,Color,bkColor);
    if (Xpos<232)
    {
      Xpos+=8;
    }
    else if (Ypos<304)
    {
      Xpos=0;
      Ypos+=16;
    }
    else
    {
      Xpos=0;
      Ypos=0;
    }
  }
  while (*str!=0);
}
#endif

static __inline void LCD_WriteRAM_Prepare(void)
{
  LCD_REG = 0x22;
}


static __inline void LCD_WriteRAM(uint16_t RGB_Code)
{

uint16_t LCD_RAM;
/* Write 16-bit GRAM Reg */
  LCD_RAM = RGB_Code;
}

void LCD_DrawPicture(uint16_t StartX,uint16_t StartY,uint16_t EndX,uint16_t EndY,unsigned char *pic)
{
  uint16_t  x;
  //LCD_SetCursor(StartX,StartY);
  LCD_SetCursor(0,0);
  LCD_WriteIndex(0x0022);
  for(x=0;x<76800;x++)
  {
     LCD_WriteData(*pic);
  }
}

void LCD_Background(void)
{
uint32_t index=0;
  LCD_SetCursor(0,0);
  LCD_WriteIndex(0x0022);
  for(index=0;index<76800;index++)
  {
     LCD_WriteData(name[index]);
  }
}

All the information to download is here: http://www.wayengineer.com/download/boardata/POWERAVR-LPC1768.zip, something is in chinese, anything that you need, let me know.

Damian

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3091
    • View Profile
    • uTasker
Re: Error when compile LPC17XX with TFT2N0369
« Reply #5 on: August 16, 2012, 02:17:32 PM »
Damian

Thanks.

The configuration and read/writes are given in the supplied code. This means that you could effectively use parts of this code as follows:

#define CONFIGURE_GLCD()
-> do the same configuration as they do in LCD_Configuration() [LPC register names may need to be modified for compatibility]

The function fnCommandGlcd_2() is used to write to the display control registers -> you need to change the content to do the same as they do in LCD_WriteReg()

Writes to the display image itself are performed using fnWriteGLCD_data_pair() -> it looks as though the content of this needs to be the same as their LCD_WriteData()

There may be some other details besides but this should basically enable the existing code to configure and write to the display.
You can also compare the configuration sequences since the controller may not be identical - possibly it will be necessary to follow their example here but there is a good chance that this will not absolutely be necessary - I notice that they check for different display types by reading an identification register.

Since this involves a bit of development work you will need to ensure that the changes build correctly and then step through the code to make sure that it is doing each job correctly. If it doesn't work the first time you can compare the configuration with their example and try adding/modifying if it looks that there is something special needed for the particular display type.

In their code there are defines for
#define LCD_REG              (*((volatile unsigned short *) 0x60000000)) /* RS = 0 */
//#define LCD_RAM              (*((volatile unsigned short *) 0x60020000)) /* RS = 1 */


and this register is also used in the code but I think that this may be something left over from a reference project using external memeory interface. Probably these code parts are not actually used since the data lines are abviously being bit-banged on GPIO2.

Good luck!

Regards

Mark



Offline dep937

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Error when compile LPC17XX with TFT2N0369
« Reply #6 on: October 22, 2012, 02:41:54 PM »
Hi Mark, I made that my GLCD woks, but for this I replace the glcd_toshiba, that is the default, with my own declarations.
Code: [Select]
#include "Background2.h"


//const unsigned long  TableL[8] = {0x01234567, 0x89abcdef, 0xfedcba98, 0x76543210, 0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff};

static unsigned short int byte2;
static unsigned short int DeviceCode;



#if !defined _GLCD_SAMSUNG && !defined OLED_GLCD_MODE && !defined TFT_GLCD_MODE && !defined NOKIA_GLCD_MODE & !defined CGLCD_GLCD_MODE && !defined KITRONIX_GLCD_MODE && !defined MB785_GLCD_MODE && !defined TFT2N0369_GLCD_MODE
    #if !defined _GLCD_TOSHIBA_DEFINES
        #define GLCD_BUSY()                 ((fnReadGLCD_cmd() & 0x3) != 0x3)// LCD busy check
        #define X_BYTES                     (GLCD_X/8)                   // the number of bytes holding the X-pixels
        #define Y_BYTES                     GLCD_Y                       // the number of rows of X_BYTES holding the Y rows
        #define DISPLAY_LEFT_PIXEL          0 
        #define DISPLAY_TOP_PIXEL           0
        #define DISPLAY_RIGHT_PIXEL         (GLCD_X - 1)
        #define DISPLAY_BOTTOM_PIXEL        (GLCD_Y - 1)
        #define UPDATE_WIDTH                ((X_BYTES + 7)/8)
        #define UPDATE_HEIGHT               Y_BYTES

        // GLCD commands - Toshiba
        //
        #define SET_ADDRESS_POINTER         0x24
        #define SET_TEXT_HOME_ADDRESS       0x40
        #define SET_TEXT_HORIZ_BYTES        0x41
        #define SET_GRAPHICS_HOME_ADDRESS   0x42
        #define SET_GRAPHICS_HORIZ_BYTES    0x43
        #define GRAPHIC_MODE_XOR            0x81
        #define DISABLE_TEXT_DISABLE_CURSOR 0x98
        #define WRITE_DATA_INC              0xc0

#define LCD_REG         volatile unsigned short 0x60000000 //     (*((volatile unsigned short *) 0x60000000))
        // Local prototypes
        //
         static void fnCommandGlcd_1(unsigned char ucCommand, unsigned char  ucParameter);
         static void fnCommandGlcd_2(unsigned char ucCommand, unsigned short usParameter);
         static void fnWriteGLCD_cmd(unsigned char ucByte);
         static void fnWriteGLCD_data(unsigned char ucByte);
         static unsigned char fnReadGLCD_cmd(void);


static unsigned short int LCD_ReadReg(unsigned short int LCD_Reg);
void wait_delay(int count);
static void LCD_Send(unsigned short int byte);
static unsigned short int LCD_ReadData(void);
static unsigned short int LCD_Read(void);
static void LCD_WriteIndex(unsigned short int index);
static void LCD_Delay(unsigned short int nCount);
void GLCD_Initialization(void);
void LCD_Clear(void);
void LCD_Background(void);

        #define _GLCD_TOSHIBA_DEFINES                                    // include only once
    #endif

    #ifdef _GLCD_COMMANDS                                                // link in Toshiba specific interface commands

void wait_delay(int count)
{
while(count--);
}

static void LCD_Send(unsigned short int byte)
{

byte2 = byte;
GLCD_DATAASOUTPUT();          /* P2.0...P2.7 Output */
GLCD_DIR_H();       /* Interface A->B */
GLCD_EN_L();                           /* Enable 2A->2B */
GLCD_DATAOUT(byte);         /* Write D0..D7 */
GLCD_LE_H();                         
GLCD_LE_L();   /* latch D0..D7 */
GLCD_DATAOUT(byte >> 8);     /* Write D8..D15 */
}

static unsigned short int LCD_Read(void)
{
unsigned short int value;

GLCD_DATAASINPUT();              /* P2.0...P2.7 Input */
GLCD_DIR_L();                /* Interface B->A */
GLCD_EN_L();                                /* Enable 2B->2A */
wait_delay(80);    /* delay some times */
value = (unsigned char)GLCD_DATAIN();                   /* Read D8..D15 */
GLCD_EN_H();                                /* Enable 1B->1A */
wait_delay(80);    /* delay some times */
value = (value << 8) | (unsigned char)GLCD_DATAIN() ;       /* Read D0..D7 */
GLCD_DIR_H();
return  value;
}

static void LCD_WriteIndex(unsigned short int index)
{
GLCD_CS_L();
GLCD_RS_L();
GLCD_RD_H();
LCD_Send( index );
wait_delay(70);
GLCD_WR_L(); 
wait_delay(1);
GLCD_WR_H();
GLCD_CS_H();
}

static unsigned short int LCD_ReadData(void)
{
unsigned short int value;
 
GLCD_CS_L();
GLCD_RS_H();
GLCD_WR_H();
GLCD_RD_L();
value = LCD_Read();

GLCD_RD_H();
GLCD_CS_H();

return value;
}

static unsigned short int LCD_ReadReg(unsigned short int LCD_Reg)
{
unsigned short LCD_RAM;

/* Write 16-bit Index (then Read Reg) */
LCD_WriteIndex(LCD_Reg);
/* Read 16-bit Reg */
LCD_RAM = LCD_ReadData();     
return LCD_RAM;
}


// Read data from the GLCD. It is assumed that RD/WR lines are initially high and that the data bus is being driven
// The data bus is driven again on exit and RD/WR lines set high again
//
static unsigned char fnReadGLCD_cmd(void)
{
unsigned char ucByte;
//GLCD_CD_H();                                                         // set C/D line high for command
GLCD_DATAASINPUT();                                                  // set the data bus high impedent
GLCD_RD_L();                                                         // drive the read line low
GLCD_DELAY_READ();                                                   // wait tACC so that the GLCD can drive the value on to the data bus
ucByte = (unsigned char)GLCD_DATAIN();                               // read the value from the bus
GLCD_RD_H();                                                         // set the read line high again
GLCD_DATAASOUTPUT();                                                 // drive the data bus again
return (ucByte);                                                     // return the value that was read
}

// Write an 8 bit data byte. It is assumed that the RD/WR lines are initially high and return then high after completion
//
static void fnWriteGLCD_data(unsigned char ucByte)
{
//    GLCD_CD_L();                                                         // set C/D line low for data
GLCD_WR_L();                                                         // set the WR line low
GLCD_DATAOUT(ucByte);                                                // set the data value on the bus
GLCD_DELAY_WRITE();                                                  // ensure tDS delay before removing the write line
GLCD_WR_H();
}

// Write an 8 bit command byte. It is assumed that the RD/WR lines are initially high and return them high after completion.
// The data bus is considered to be always driven.
//
static void fnWriteGLCD_cmd(unsigned char ucByte)
{
//    GLCD_CD_H();                                                         // set C/D line high for command
GLCD_WR_L();                                                         // set the WR line low
GLCD_DATAOUT(ucByte);                                                // set the data value on the bus
GLCD_DELAY_WRITE();                                                  // ensure tDS delay before removing the write line
GLCD_WR_H();
}

// This routine is used to write two parameter data bytes plus a command byte.
// The GLCD may be busy for some time after certain commands
//
static void fnCommandGlcd_2(unsigned char ucCommand, unsigned short usParameter)
{
while (GLCD_BUSY()) {}                                               // wait until the GLCD can accept further writes
fnWriteGLCD_data((unsigned char)usParameter);                        // write low data byte
while (GLCD_BUSY()) {}                                               // wait until the GLCD can accept further writes
fnWriteGLCD_data((unsigned char)(usParameter >> 8));                 // write high data byte
while (GLCD_BUSY()) {}                                               // wait until the GLCD can accept further writes
fnWriteGLCD_cmd(ucCommand);                                          // write the command
}

// This routine is used to write one parameter data bytes plus a command byte.
// The GLCD may be busy for some time after certain commands.
//
static void fnCommandGlcd_1(unsigned char ucCommand, unsigned char ucParameter)
{
while (GLCD_BUSY()) {}                                               // wait until the GLCD can accept further writes
fnWriteGLCD_data(ucParameter);                                       // write parameter byte
while (GLCD_BUSY()) {}                                               // wait until the GLCD can accept further writes
fnWriteGLCD_cmd(ucCommand);                                          // write the command
}

static void LCD_Delay(unsigned short int nCount)
{
unsigned short int TimingDelay;
while(nCount--)
{
for(TimingDelay=0;TimingDelay<10000;TimingDelay++);
}
}

static void LCD_WriteData(unsigned short int data)
{
GLCD_CS_L();
GLCD_RS_H();   
LCD_Send( data );
GLCD_WR_L();     
wait_delay(1);
GLCD_WR_H();
GLCD_CS_H();
}

static void LCD_WriteReg(unsigned short int LCD_Reg,unsigned short int LCD_RegValue)
{
/* Write 16-bit Index, then Write Reg */ 
LCD_WriteIndex(LCD_Reg);         
/* Write 16-bit Reg */
LCD_WriteData(LCD_RegValue); 
}

void GLCD_Initialization()
{
//GLCD_Configuration();
LCD_Delay(5);  /* delay 50 ms */
DeviceCode = LCD_ReadReg(0x0000); /* ¶ÁÈ¡ÆÁID */
if(DeviceCode==0x8989)
{
LCD_WriteReg(0x0000,0x0001);    LCD_Delay(5);   /* ´ò¿ª¾§Õñ */
LCD_WriteReg(0x0003,0xA8A4);    LCD_Delay(5);   
LCD_WriteReg(0x000C,0x0000);    LCD_Delay(5);   
LCD_WriteReg(0x000D,0x080C);    LCD_Delay(5);   
LCD_WriteReg(0x000E,0x2B00);    LCD_Delay(5);   
LCD_WriteReg(0x001E,0x00B0);    LCD_Delay(5);   
LCD_WriteReg(0x0001,0x2B3F);    LCD_Delay(5);   /* Çý¶¯Êä³ö¿ØÖÆ320*240 0x2B3F */
LCD_WriteReg(0x0002,0x0600);    LCD_Delay(5);
LCD_WriteReg(0x0010,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0011,0x6070);    LCD_Delay(5);   /* ¶¨ÒåÊý¾Ý¸ñʽ 16λɫ ºáÆÁ 0x6070 */
LCD_WriteReg(0x0005,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0006,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0016,0xEF1C);    LCD_Delay(5);
LCD_WriteReg(0x0017,0x0003);    LCD_Delay(5);
LCD_WriteReg(0x0007,0x0133);    LCD_Delay(5);         
LCD_WriteReg(0x000B,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x000F,0x0000);    LCD_Delay(5);   /* ɨÃ迪ʼµØÖ· */
LCD_WriteReg(0x0041,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0042,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0048,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0049,0x013F);    LCD_Delay(5);
LCD_WriteReg(0x004A,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x004B,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0044,0xEF00);    LCD_Delay(5);
LCD_WriteReg(0x0045,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0046,0x013F);    LCD_Delay(5);
LCD_WriteReg(0x0030,0x0707);    LCD_Delay(5);
LCD_WriteReg(0x0031,0x0204);    LCD_Delay(5);
LCD_WriteReg(0x0032,0x0204);    LCD_Delay(5);
LCD_WriteReg(0x0033,0x0502);    LCD_Delay(5);
LCD_WriteReg(0x0034,0x0507);    LCD_Delay(5);
LCD_WriteReg(0x0035,0x0204);    LCD_Delay(5);
LCD_WriteReg(0x0036,0x0204);    LCD_Delay(5);
LCD_WriteReg(0x0037,0x0502);    LCD_Delay(5);
LCD_WriteReg(0x003A,0x0302);    LCD_Delay(5);
LCD_WriteReg(0x003B,0x0302);    LCD_Delay(5);
LCD_WriteReg(0x0023,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0024,0x0000);    LCD_Delay(5);
LCD_WriteReg(0x0025,0x8000);    LCD_Delay(5);
LCD_WriteReg(0x004f,0);        /* ÐÐÊ×Ö·0 */
LCD_WriteReg(0x004e,0);        /* ÁÐÊ×Ö·0 */
}
LCD_Delay(5);  /* delay 50 ms */
}

static void LCD_SetCursor(unsigned short int Xpos,unsigned short int Ypos)
{
LCD_WriteReg(0x004e,Ypos);            /* Line */
LCD_WriteReg(0x004f,0x13f-Xpos);          /* Row */
}

void LCD_Clear(void)//(unsigned short int Color)
{
unsigned long int index=0;
LCD_SetCursor(0,0);
LCD_WriteIndex(0x0022);
for(index=0;index<76800;index++)
{
LCD_WriteData(0x07E0);
}
}

void LCD_Background(void)
{
unsigned long int index=0;
  LCD_SetCursor(0,0);
  LCD_WriteIndex(0x0022);
  for(index=0;index<76800;index++)
  {
     LCD_WriteData(Back[index]);
  }
}
    #endif

#endif

Also I modified this lines in app_hw_lpc17xx.h

Code: [Select]
//#define DATA_LINES             (PORT3_BIT7 | PORT3_BIT6 | PORT3_BIT5 | PORT3_BIT4 | PORT3_BIT3 | PORT3_BIT2 | PORT3_BIT1 | PORT3_BIT0)
#define DATA_LINES             (PORT2_BIT7 | PORT2_BIT6 | PORT2_BIT5 | PORT2_BIT4 | PORT2_BIT3 | PORT2_BIT2 | PORT2_BIT1 | PORT2_BIT0)

#if defined NOKIA_GLCD_MODE                                              // backlight and reset
    #define LCD_BL             PORT3_BIT26
    #define GLCD_RST           PORT3_BIT25
    #define CONFIGURE_GLCD()   _CONFIG_DRIVE_PORT_OUTPUT_VALUE(3, (GLCD_RST | LCD_BL), 0);
    #define GLCD_RST_H()       _SETBITS(3, GLCD_RST)
    #define GLCD_RST_L()       _CLEARBITS(3, GLCD_RST)
    #define ENABLE_BACKLIGHT() _SETBITS(3, LCD_BL)
    #ifdef _WINDOWS
        #define MAX_GLCD_WRITE_BURST   1000                              // the maximum number of writes to the GLCD before the task yields
    #else
        #define MAX_GLCD_WRITE_BURST   70                                // the maximum number of writes to the GLCD before the task yields
    #endif
#elif defined _GLCD_SAMSUNG
    #define GLCD_RST           PORT1_BIT31                               // reset
    #define GLCD_RS            PORT1_BIT30                               // GLCD Register Select
    #define GLCD_RW            PORT1_BIT29                               // GLCD Read/Write
    #define GLCD_ENA           PORT1_BIT28                               // GLCD Enable

    #define GLCD_CS0           PORT1_BIT27                               // LCD Controller 0 Chip Select - 2 controller chips for 128 x 64
    #define GLCD_CS1           PORT1_BIT26                               // LCD Controller 1 Chip Select

    #define CONFIGURE_GLCD()   _CONFIG_DRIVE_PORT_OUTPUT_VALUE(1, (GLCD_RST | GLCD_RW | GLCD_ENA | GLCD_RS | GLCD_CS0 | GLCD_CS1), (GLCD_RW)); _CONFIG_PORT_INPUT(3, DATA_LINES);

    #define GLCD_RS_H()        _SETBITS(1, GLCD_RS)
    #define GLCD_RS_L()        _CLEARBITS(1, GLCD_RS)

    #define GLCD_RW_H()        _SETBITS(1, GLCD_RW)
    #define GLCD_RW_L()        _CLEARBITS(1, GLCD_RW)

    #define GLCD_CS0_H()       _SETBITS(1, GLCD_CS0) 
    #define GLCD_CS0_L()       _CLEARBITS(1, GLCD_CS0)

    #define GLCD_CS1_H()       _SETBITS(1, GLCD_CS1) 
    #define GLCD_CS1_L()       _CLEARBITS(1, GLCD_CS1)

    #define GLCD_DELAY_WRITE()                                           // no write delay since the data is stable for long enough at full speed
    #define GLCD_DELAY_READ()  GLCD_RW_H()                               // one extra operation to ensure set up time of read

    #define GLCD_RST_H()       _SETBITS(1, GLCD_RST)
    #define GLCD_RST_L()       _CLEARBITS(1, GLCD_RST)

    #define GLCD_ENA_H()       _SETBITS(1, GLCD_ENA) 
    #define GLCD_ENA_L()       _CLEARBITS(1, GLCD_ENA)

    #ifdef _WINDOWS
        #define MAX_GLCD_WRITE_BURST   1000                              // the maximum number of writes to the GLCD before the task yields
    #else
        #define MAX_GLCD_WRITE_BURST   80                                // the maximum number of writes to the GLCD before the task yields
    #endif
#else                                                                    // Toshiba type GLCD
    /*#define GLCD_RST           PORT1_BIT31
    #define GLCD_C_D           PORT1_BIT30
    #define GLCD_WR            PORT1_BIT29
    #define GLCD_RD            PORT1_BIT28
    #define CONFIGURE_GLCD()   _CONFIG_DRIVE_PORT_OUTPUT_VALUE(1, (GLCD_RST | GLCD_WR | GLCD_RD | GLCD_C_D), (GLCD_WR | GLCD_RD | GLCD_C_D)); _CONFIG_PORT_INPUT(3, DATA_LINES);
    #define GLCD_RST_H()       _SETBITS(1, GLCD_RST)
    #define GLCD_RST_L()       _CLEARBITS(1, GLCD_RST)

    #define GLCD_WR_H()        _SETBITS(1, GLCD_WR)
    #define GLCD_WR_L()        _CLEARBITS(1, GLCD_WR)

    #define GLCD_CD_H()        _SETBITS(1, GLCD_C_D)
    #define GLCD_CD_L()        _CLEARBITS(1, GLCD_C_D)

    #define GLCD_RD_H()        _SETBITS(1, GLCD_RD)
    #define GLCD_RD_L()        _CLEARBITS(1, GLCD_RD)

    #define GLCD_DELAY_WRITE() //GLCD_WR_L()                             // no write delay since the data is stable for long enough at full speed
    #define GLCD_DELAY_READ()  GLCD_RD_L()                               // one extra operation to ensure set up time of read
*/

#define GLCD_EN            PORT0_BIT19
    #define GLCD_LE            PORT0_BIT20
    #define GLCD_DIR           PORT0_BIT21
#define GLCD_CS            PORT0_BIT22
    #define GLCD_RS            PORT0_BIT23
    #define GLCD_WR            PORT0_BIT24
#define GLCD_RD            PORT0_BIT25

    #define CONFIGURE_GLCD()   _CONFIG_DRIVE_PORT_OUTPUT_VALUE(0, (GLCD_EN | GLCD_LE | GLCD_DIR | GLCD_CS | GLCD_RS | GLCD_WR | GLCD_RD), (GLCD_EN | GLCD_LE | GLCD_DIR | GLCD_CS | GLCD_RS | GLCD_WR | GLCD_RD)); _CONFIG_PORT_INPUT(2, DATA_LINES);
   
#define GLCD_EN_H()       _SETBITS(0, GLCD_EN)
    #define GLCD_EN_L()       _CLEARBITS(0, GLCD_EN)

    #define GLCD_LE_H()        _SETBITS(0, GLCD_LE)
    #define GLCD_LE_L()        _CLEARBITS(0, GLCD_LE)

    #define GLCD_DIR_H()        _SETBITS(0, GLCD_DIR)
    #define GLCD_DIR_L()        _CLEARBITS(0, GLCD_DIR)

    #define GLCD_CS_H()        _SETBITS(0, GLCD_CS)
    #define GLCD_CS_L()        _CLEARBITS(0, GLCD_CS)

    #define GLCD_RS_H()        _SETBITS(0, GLCD_RS)
    #define GLCD_RS_L()        _CLEARBITS(0, GLCD_RS)

    #define GLCD_WR_H()        _SETBITS(0, GLCD_WR)
    #define GLCD_WR_L()        _CLEARBITS(0, GLCD_WR)

    #define GLCD_RD_H()        _SETBITS(0, GLCD_RD)
    #define GLCD_RD_L()        _CLEARBITS(0, GLCD_RD)
   
#define GLCD_DELAY_WRITE() //GLCD_WR_L()                             // no write delay since the data is stable for long enough at full speed
    #define GLCD_DELAY_READ()  GLCD_RD_L()                               // one extra operation to ensure set up time of read

    #ifdef _WINDOWS
        #define MAX_GLCD_WRITE_BURST   1000                              // the maximum number of writes to the GLCD before the task yields
    #else
        #define MAX_GLCD_WRITE_BURST   20                                // the maximum number of writes to the GLCD before the task yields
    #endif
#endif

#define GLCD_DATAASOUTPUT()    _DRIVE_PORT_OUTPUT(2, DATA_LINES)
#define GLCD_DATAASINPUT()     _FLOAT_PORT(2, DATA_LINES)

#define GLCD_DATAOUT(data)     _WRITE_PORT_MASK(2, data, DATA_LINES)
#define GLCD_DATAIN()          _READ_PORT(2)


If you wanted , I can upload all the uTasker modified. Sorry by delay to public my code, but i was working in another stuff.

Thanks