How do I display image on ER-5517 connected to Arduino Mega

As the title suggests, I am trying to display an image on a 480x480 TFT LCD display. I am using the example code downloaded from the Buydisplay website. I have no issues modifying the example code to add lines, boxes, circles, text etc, and to manipulate the images that are held in memory (move the image around the screen, or display a portion of the image, etc). But I can't change the default image(s) to my own image(s). I'm hoping someone can help guide me.

I purchased the small square 4" LCD display, plus the arduino shield and LCD controller from Buydisplay. The website for the specific display and example code is:

The example zip file contains a 5Mb bin file (PicFlashFont.bin) that presumably holds all the images, but I don't know how to modify the file (or even see what's in it). If I make any changes to the bin file, it doesn't seem to affect anything. It's like the images were "flashed" onto the shield(?) when I first compiled the code, but the file is now ignored. I want to avoid using the SD card if at all possible. Does anyone know what I need to do in install my own images?

(sorry for not pasting all the code here, but I don't know which part(s) are relevant.)

Which is why we always say post all your code.

You might want to look at this How to get the best out of this forum before you proceed any further.

That's why I posted a link to the code (example.zip). I thought it would be easier to download it at the source.

Having said that, I can narrow the question down a bit more after fighting with it all yesterday. Essentially, I need to put a bmp onto the flash memory of the LCD. So my question is simply...how do I do that? I have two main pictures, both around 200x350, and I'll have a dozen or so small images that will be overlaid at various times. I plan on combining the images into a single picture that I can access whatever chunk I need.

I know using the SD card would be easier from a programming point of view, but ultimately I will not have access to the SD card. It will be buried in the hardware and not accessible. The usb cable will be all I have access to.

There are four main files (LCD_init.h, LCD.h, LCD.cpp and Right_Display) :

#ifndef LCD_init_h
#define LCD_init_h
#include "Arduino.h"
//#include <avr/pgmspace.h>
#include <SPI.h> 

#define  SPI_CS     2
#define  SPI_CLK    1  // DUE   13
#define  SPI_DI     0 //  DUE   11 

#define  SPI_CS_RES   digitalWrite(SPI_CS, LOW)
#define  SPI_CS_SET   digitalWrite(SPI_CS, HIGH)
#define  SPI_CLK_RES   digitalWrite(SPI_CLK, LOW)
#define  SPI_CLK_SET   digitalWrite(SPI_CLK, HIGH)
#define  SPI_DI_RES   digitalWrite(SPI_DI, LOW)
#define  SPI_DI_SET   digitalWrite(SPI_DI, HIGH)

void HW_SPI_Send(unsigned char i)
{ 
  SPI.transfer( i);
}

//RGB+9b_SPI(rise)
 void SW_SPI_Send(unsigned char i)
{  
   unsigned char n;
   
   for(n=0; n<8; n++)			
   {       
			SPI_CLK_RES;
			if(i&0x80)SPI_DI_SET ;
                        else SPI_DI_RES ;
			SPI_CLK_SET;
			i<<=1;
   }
}

void SPI_WriteComm(unsigned char i)
{
    SPI_CS_RES;
    SPI_DI_RES;//DI=0 COMMAND
 
    SPI_CLK_RES;
    SPI_CLK_SET;
  //  HW_SPI_Send(i);
    SW_SPI_Send(i);	
    SPI_CS_SET;	
}

void SPI_WriteData(unsigned char i)
{ 
    SPI_CS_RES;
    SPI_DI_SET;//DI=1 DATA
    SPI_CLK_RES;
    SPI_CLK_SET;
  //  HW_SPI_Send(i);   
    SW_SPI_Send(i);
    SPI_CS_SET;  		
} 

void ST7701S_Initial(void)
{  
    pinMode(SPI_CS,   OUTPUT);
    digitalWrite(SPI_CS, HIGH);
    pinMode(SPI_CLK,   OUTPUT);
    digitalWrite(SPI_CLK, LOW);
    pinMode(SPI_DI,   OUTPUT);
    digitalWrite(SPI_DI, LOW);  
	
	SPI_WriteComm(0xFF);
	SPI_WriteData(0x77);
	SPI_WriteData(0x01);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x13);
	SPI_WriteComm(0xEF);
	SPI_WriteData(0x08);
	SPI_WriteComm(0xFF);
	SPI_WriteData(0x77);
	SPI_WriteData(0x01);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x10);
	SPI_WriteComm(0xC0);
	SPI_WriteData(0x3B);
	SPI_WriteData(0x00);
	SPI_WriteComm(0xC1);
	SPI_WriteData(0x0D);
	SPI_WriteData(0x02);
	SPI_WriteComm(0xC2);
	SPI_WriteData(0x21);
	SPI_WriteData(0x08);
	SPI_WriteComm(0xCD);
	SPI_WriteData(0x08);//18-bit/pixel: MDT=0:D[21:16]=R,D[13:8]=G,D[5:0]=B(CDH=00) ;
	                 //MDT=1:D[17:12]=R,D[11:6]=G,D[5:0]=B(CDH=08) ;
	SPI_WriteComm(0xB0);
	SPI_WriteData(0x00);
	SPI_WriteData(0x11);
	SPI_WriteData(0x18);
	SPI_WriteData(0x0E);
	SPI_WriteData(0x11);
	SPI_WriteData(0x06);
	SPI_WriteData(0x07);
	SPI_WriteData(0x08);
	SPI_WriteData(0x07);
	SPI_WriteData(0x22);
	SPI_WriteData(0x04);
	SPI_WriteData(0x12);
	SPI_WriteData(0x0F);
	SPI_WriteData(0xAA);
	SPI_WriteData(0x31);
	SPI_WriteData(0x18);
	SPI_WriteComm(0xB1);
	SPI_WriteData(0x00);
	SPI_WriteData(0x11);
	SPI_WriteData(0x19);
	SPI_WriteData(0x0E);
	SPI_WriteData(0x12);
	SPI_WriteData(0x07);
	SPI_WriteData(0x08);
	SPI_WriteData(0x08);
	SPI_WriteData(0x08);
	SPI_WriteData(0x22);
	SPI_WriteData(0x04);
	SPI_WriteData(0x11);
	SPI_WriteData(0x11);
	SPI_WriteData(0xA9);
	SPI_WriteData(0x32);
	SPI_WriteData(0x18);
	SPI_WriteComm(0xFF);
	SPI_WriteData(0x77);
	SPI_WriteData(0x01);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x11);
	SPI_WriteComm(0xB0);
	SPI_WriteData(0x60);
	SPI_WriteComm(0xB1);
	SPI_WriteData(0x30);
	SPI_WriteComm(0xB2);
	SPI_WriteData(0x87);
	SPI_WriteComm(0xB3);
	SPI_WriteData(0x80);
	SPI_WriteComm(0xB5);
	SPI_WriteData(0x49);
	SPI_WriteComm(0xB7);
	SPI_WriteData(0x85);
	SPI_WriteComm(0xB8);
	SPI_WriteData(0x21);
	SPI_WriteComm(0xC1);
	SPI_WriteData(0x78);
	SPI_WriteComm(0xC2);
	SPI_WriteData(0x78);
	delay(20);
	SPI_WriteComm(0xE0);
	SPI_WriteData(0x00);
	SPI_WriteData(0x1B);
	SPI_WriteData(0x02);
	SPI_WriteComm(0xE1);
	SPI_WriteData(0x08);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x07);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x44);
	SPI_WriteData(0x44);
	SPI_WriteComm(0xE2);
	SPI_WriteData(0x11);
	SPI_WriteData(0x11);
	SPI_WriteData(0x44);
	SPI_WriteData(0x44);
	SPI_WriteData(0xED);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0xEC);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteComm(0xE3);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x11);
	SPI_WriteData(0x11);
	SPI_WriteComm(0xE4);
	SPI_WriteData(0x44);
	SPI_WriteData(0x44);
	SPI_WriteComm(0xE5);
	SPI_WriteData(0x0A);
	SPI_WriteData(0xE9);
	SPI_WriteData(0xD8);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x0C);
	SPI_WriteData(0xEB);
	SPI_WriteData(0xD8);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x0E);
	SPI_WriteData(0xED);
	SPI_WriteData(0xD8);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x10);
	SPI_WriteData(0xEF);
	SPI_WriteData(0xD8);
	SPI_WriteData(0xA0);
	SPI_WriteComm(0xE6);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x11);
	SPI_WriteData(0x11);
	SPI_WriteComm(0xE7);
	SPI_WriteData(0x44);
	SPI_WriteData(0x44);
	SPI_WriteComm(0xE8);
	SPI_WriteData(0x09);
	SPI_WriteData(0xE8);
	SPI_WriteData(0xD8);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x0B);
	SPI_WriteData(0xEA);
	SPI_WriteData(0xD8);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x0D);
	SPI_WriteData(0xEC);
	SPI_WriteData(0xD8);
	SPI_WriteData(0xA0);
	SPI_WriteData(0x0F);
	SPI_WriteData(0xEE);
	SPI_WriteData(0xD8);
	SPI_WriteData(0xA0);
	SPI_WriteComm(0xEB);
	SPI_WriteData(0x02);
	SPI_WriteData(0x00);
	SPI_WriteData(0xE4);
	SPI_WriteData(0xE4);
	SPI_WriteData(0x88);
	SPI_WriteData(0x00);
	SPI_WriteData(0x40);
	SPI_WriteComm(0xEC);
	SPI_WriteData(0x3C);
	SPI_WriteData(0x00);
	SPI_WriteComm(0xED);
	SPI_WriteData(0xAB);
	SPI_WriteData(0x89);
	SPI_WriteData(0x76);
	SPI_WriteData(0x54);
	SPI_WriteData(0x02);
	SPI_WriteData(0xFF);
	SPI_WriteData(0xFF);
	SPI_WriteData(0xFF);
	SPI_WriteData(0xFF);
	SPI_WriteData(0xFF);
	SPI_WriteData(0xFF);
	SPI_WriteData(0x20);
	SPI_WriteData(0x45);
	SPI_WriteData(0x67);
	SPI_WriteData(0x98);
	SPI_WriteData(0xBA);
	SPI_WriteComm(0xEF);
	SPI_WriteData(0x10);
	SPI_WriteData(0x0D);
	SPI_WriteData(0x04);
	SPI_WriteData(0x08);
	SPI_WriteData(0x3F);
	SPI_WriteData(0x1F);
	SPI_WriteComm(0xFF);
	SPI_WriteData(0x77);
	SPI_WriteData(0x01);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteComm(0x3A);
	SPI_WriteData(0x66);//55/50=16bit(RGB565);66=18bit(RGB666);77或默认不写3AH是=24bit(RGB888)
	
	SPI_WriteComm(0xFF);
	SPI_WriteData(0x77);
	SPI_WriteData(0x01);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x13);
	SPI_WriteComm(0xE8);
	SPI_WriteData(0x00);
	SPI_WriteData(0x0E);
	SPI_WriteComm(0xFF);
	SPI_WriteData(0x77);
	SPI_WriteData(0x01);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteComm(0x11);
	delay(120);
	SPI_WriteComm(0xFF);
	SPI_WriteData(0x77);
	SPI_WriteData(0x01);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x13);
	SPI_WriteComm(0xE8);
	SPI_WriteData(0x00);
	SPI_WriteData(0x0C);
	delay(10);
	SPI_WriteComm(0xE8);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteComm(0xFF);
	SPI_WriteData(0x77);
	SPI_WriteData(0x01);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	SPI_WriteData(0x00);
	
	SPI_WriteComm(0x36);
	SPI_WriteData(0x00);
	
	SPI_WriteComm(0x3A);
	SPI_WriteData(0x66);
	
	SPI_WriteComm(0x21);
//	SPI_WriteComm(0x2A);
	SPI_WriteComm(0x29);
	delay(20);
}
#endif

#ifndef LCD_h
#define LCD_h
#include "Arduino.h"
#include <avr/pgmspace.h>
#include <SPI.h>

#define Arduino_SPI     1 //1:use SPI to drive

#define layer1_start_addr 0 		 
#define layer2_start_addr 460800   
#define layer3_start_addr 921600    
#define layer4_start_addr 1382400
#define layer5_start_addr 1843200 
#define layer6_start_addr 2304000   
#define layer7_start_addr 2764800   
#define layer8_start_addr 3225600
#define layer9_start_addr 3686400
#define layer10_start_addr 4147200
#define layer11_start_addr 4608000

#define LCD_XSIZE_TFT    480
#define LCD_YSIZE_TFT    480

#define LCD_VBPD         20
#define LCD_VFPD         12
#define LCD_VSPW         3
#define LCD_HBPD         20
#define LCD_HFPD         20
#define LCD_HSPW         20

#define LCD_PCLK_Falling_Rising     0      // 1:FallingEdge    0:RisingEdge
#define LCD_HSYNC_Active_Polarity   0      // 1:HighLevel    0:LowLevel
#define LCD_VSYNC_Active_Polarity   0      // 1:HighLevel    0:LowLevel
#define LCD_DE_Active_Polarity      1      // 1:HighLevel    0:LowLevel

#define cSetb0    0x01
#define cSetb1    0x02
#define cSetb2    0x04
#define cSetb3    0x08
#define cSetb4    0x10
#define cSetb5    0x20
#define cSetb6    0x40
#define cSetb7    0x80
#define cClrb0    0xfe
#define cClrb1    0xfd
#define cClrb2    0xfb
#define cClrb3    0xf7
#define cClrb4    0xef
#define cClrb5    0xdf
#define cClrb6    0xbf
#define cClrb7    0x7f

#define Black   0x0000
#define White   0xffff
#define Red     0xf800
#define Green   0x07e0
#define Blue    0x001f
#define Yellow  Red|Green
#define Cyan    Green|Blue
#define Purple  Red|Blue
#define LIGHTRED      0xfc10
#define LIGHTGREEN    0x87f0
#define LIGHTBLUE     0x841f
#define LIGHTYELLOW   0xfff0
 
const unsigned char pic_80x80[] PROGMEM ={
//
//Image size:80 X 80 X 16BPP=12800 bytes.
//80x80 hex data deleted since I'm not using it and it takes too much room to post
};

class ER5517Basic
{
	private:
		
	public:
	void SPIInit();
	void SPISetCs(int cs);
	unsigned char SPIRwByte(unsigned char value);
	void SPI_CmdWrite(int cmd);
	void SPI_DataWrite(int data);
	void SPI_DataWrite_Pixel(int data);
	int SPI_StatusRead(void);
	int SPI_DataRead(void);
	void SPI_RegisterWrite(unsigned char Cmd,unsigned char Data);
	unsigned char SPI_RegisterRead(unsigned char Cmd);
	void IICInit();	
	void IIC_CmdWrite(int cmd);
	void IIC_DataWrite(int data);
	void IIC_DataWrite_Pixel(int data);
	int IIC_StatusRead(void);
	int IIC_DataRead(void);
	void IIC_RegisterWrite(unsigned char Cmd,unsigned char Data);
	unsigned char IIC_RegisterRead(unsigned char Cmd);
	void Parallel_Init(void);
	void LCD_CmdWrite(unsigned char cmd);
	void LCD_DataWrite(unsigned char data);
	void LCD_DataWrite_Pixel(unsigned int data);
	unsigned char LCD_StatusRead(void);
	unsigned int LCD_DataRead(void);
	void LCD_RegisterWrite(unsigned char Cmd,unsigned char Data);
	unsigned char LCD_RegisterRead(unsigned char Cmd);


	void TFT_18bit(void);
	void Host_Bus_16bit(void);
	void RGB_16b_16bpp(void);
	void MemRead_Left_Right_Top_Down(void);
	void Graphic_Mode(void);
        void Text_Mode(void);
	void Memory_Select_SDRAM(void);
	void HSCAN_L_to_R(void);
	void VSCAN_T_to_B(void);
	void PDATA_Set_RGB(void);
	void PCLK_Rising(void);
	void PCLK_Falling(void);
	void HSYNC_Low_Active(void);
	void HSYNC_High_Active(void);
	void VSYNC_Low_Active(void);
	void VSYNC_High_Active(void);
	void DE_Low_Active(void);
	void DE_High_Active(void);
	void Set_PCLK(unsigned char val);
	void Set_HSYNC_Active(unsigned char val);
	void Set_VSYNC_Active(unsigned char val);
	void Set_DE_Active(unsigned char val);
	void LCD_HorizontalWidth_VerticalHeight(unsigned short WX,unsigned short HY);
	void LCD_Horizontal_Non_Display(unsigned short WX);
	void LCD_HSYNC_Start_Position(unsigned short WX);
	void LCD_HSYNC_Pulse_Width(unsigned short WX);
	void LCD_Vertical_Non_Display(unsigned short HY);
	void LCD_VSYNC_Start_Position(unsigned short HY);
	void LCD_VSYNC_Pulse_Width(unsigned short HY);
	void Select_Main_Window_16bpp(void);
	void Memory_XY_Mode(void); 
  void Memory_Linear_Mode(void);
	void Memory_16bpp_Mode(void);
	void MemWrite_Left_Right_Top_Down(void);
	void HW_Reset(void);
	void System_Check_Temp(void);
	void PLL_Initial(void);
	void SDRAM_initail(void);
	void initial(void);
	void Display_ON(void);
	void Main_Image_Start_Address(unsigned long Addr);
	void Main_Image_Width(unsigned short WX);
	void Main_Window_Start_XY(unsigned short WX,unsigned short HY);
	void Canvas_Image_Start_address(unsigned long Addr);
	void Canvas_image_width(unsigned short WX);
	void Active_Window_XY(unsigned short WX,unsigned short HY);
	void Active_Window_WH(unsigned short WX,unsigned short HY);
	void Foreground_color_65k(unsigned short temp);
  void Background_color_65k(unsigned short temp);
  void Check_SDRAM_Ready(void);
	void Check_Busy_Draw(void);
	void Check_2D_Busy(void);
	void Check_Mem_WR_FIFO_not_Full(void);
	void Check_Mem_WR_FIFO_Empty(void);
	void Check_Mem_RD_FIFO_not_Full(void);
	void Check_Mem_RD_FIFO_not_Empty(void);
	void DrawSquare_Fill(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned long ForegroundColor);
  void DrawCircle_Fill(unsigned short X1,unsigned short Y1,unsigned short R,unsigned long ForegroundColor );
	void Enable_SFlash_SPI(void);
	void Goto_Pixel_XY(unsigned short WX,unsigned short HY);
  void Goto_Text_XY(unsigned short WX,unsigned short HY);
	void DMA_24bit_Block(unsigned char SCS,unsigned char Clk,unsigned short X1,unsigned short Y1,unsigned short X_W,unsigned short Y_H,unsigned short P_W,unsigned long Addr);
	void DMA_24bit_Linear(unsigned char SCS,unsigned char Clk,unsigned long flash_addr,unsigned long memory_addr,unsigned long data_num);
	void DrawPixel(unsigned short x,unsigned short y,unsigned short color);
	void Show_String(char *str);
	void Show_picture(unsigned long numbers,const unsigned char *data);

////////////////////////////////////////////////////////////////////////
	////**** [ Function : Draw ] ****////
	//**[67h]**//
	void Start_Line(void);
	void Start_Triangle(void);
	void Start_Triangle_Fill(void);
	//**[68h]~[73h]**//
	void Line_Start_XY(unsigned short WX,unsigned short HY);		
	void Line_End_XY(unsigned short WX,unsigned short HY);			
	void Triangle_Point1_XY(unsigned short WX,unsigned short HY);	
	void Triangle_Point2_XY(unsigned short WX,unsigned short HY);	
	void Triangle_Point3_XY (unsigned short WX,unsigned short HY);	
	void Square_Start_XY(unsigned short WX,unsigned short HY);		
	void Square_End_XY(unsigned short WX,unsigned short HY);		
	//**[76h]**//
	void Start_Circle_or_Ellipse(void);
	void Start_Circle_or_Ellipse_Fill(void);
	void Start_Left_Down_Curve(void);
	void Start_Left_Up_Curve(void);
	void Start_Right_Up_Curve(void);
	void Start_Right_Down_Curve(void);
	void Start_Left_Down_Curve_Fill(void);
	void Start_Left_Up_Curve_Fill(void);
	void Start_Right_Up_Curve_Fill(void);
	void Start_Right_Down_Curve_Fill(void);
	void Start_Square(void);
	void Start_Square_Fill(void);
	void Start_Circle_Square(void);
	void Start_Circle_Square_Fill(void);
	//**[77h]~[7Eh]**//
	void Circle_Center_XY(unsigned short WX,unsigned short HY);				
	void Ellipse_Center_XY(unsigned short WX,unsigned short HY);			
	void Circle_Radius_R(unsigned short WX);								
	void Ellipse_Radius_RxRy(unsigned short WX,unsigned short HY);			
	void Circle_Square_Radius_RxRy(unsigned short WX,unsigned short HY);	

	////////////////////////////////////////////////////////////////////////
	////**** [ Function : PWM ] ****////
	//**[84h]**//
	void Set_PWM_Prescaler_1_to_256(unsigned short WX);
	//**[85h]**//
	void Select_PWM1_Clock_Divided_By_1(void);
	void Select_PWM1_Clock_Divided_By_2(void);
	void Select_PWM1_Clock_Divided_By_4(void);
	void Select_PWM1_Clock_Divided_By_8(void);
	void Select_PWM0_Clock_Divided_By_1(void);
	void Select_PWM0_Clock_Divided_By_2(void);
	void Select_PWM0_Clock_Divided_By_4(void);
	void Select_PWM0_Clock_Divided_By_8(void);
	//[85h].[bit3][bit2]
	void Select_PWM1_is_ErrorFlag(void);
	void Select_PWM1(void);
	void Select_PWM1_is_Osc_Clock(void);
	//[85h].[bit1][bit0]
	void Select_PWM0_is_GPIO_C7(void);
	void Select_PWM0(void);
	void Select_PWM0_is_Core_Clock(void);
	//**[86h]**//
	//[86h]PWM1
	void Enable_PWM1_Inverter(void);
	void Disable_PWM1_Inverter(void);
	void Auto_Reload_PWM1(void);
	void One_Shot_PWM1(void);
	void Start_PWM1(void);
	void Stop_PWM1(void);
	//[86h]PWM0
	void Enable_PWM0_Dead_Zone(void);
	void Disable_PWM0_Dead_Zone(void);
	void Enable_PWM0_Inverter(void);
	void Disable_PWM0_Inverter(void);
	void Auto_Reload_PWM0(void);
	void One_Shot_PWM0(void);
	void Start_PWM0(void);
	void Stop_PWM0(void);
	//**[87h]**//
	void Set_Timer0_Dead_Zone_Length(unsigned char temp);
	//**[88h][89h]**//
	void Set_Timer0_Compare_Buffer(unsigned short WX);
	//**[8Ah][8Bh]**//
	void Set_Timer0_Count_Buffer(unsigned short WX);
	//**[8Ch][8Dh]**//
	void Set_Timer1_Compare_Buffer(unsigned short WX);
	//**[8Eh][8Fh]**//
	void Set_Timer1_Count_Buffer(unsigned short WX);

	////////////////////////////////////////////////////////////////////////
	////**** [ Function : BTE ] ****////
	//**[90h]**//

	//[90h]=========================================================================
	void BTE_Enable(void);
	void BTE_Disable(void);

	void Check_BTE_Busy(void);

	void Pattern_Format_8X8(void);
	void Pattern_Format_16X16(void);

	//[91h]=========================================================================
	void BTE_ROP_Code(unsigned char setx);
	void BTE_Operation_Code(unsigned char setx);

	//[92h]=========================================================================
	void BTE_S0_Color_8bpp(void);
	void BTE_S0_Color_16bpp(void);
	void BTE_S0_Color_24bpp(void);

	void BTE_S1_Color_8bpp(void);
	void BTE_S1_Color_16bpp(void);
	void BTE_S1_Color_24bpp(void);
	void BTE_S1_Color_Constant(void);
	void BTE_S1_Color_8bit_Alpha(void);
	void BTE_S1_Color_16bit_Alpha(void);

	void BTE_Destination_Color_8bpp(void);
	void BTE_Destination_Color_16bpp(void);
	void BTE_Destination_Color_24bpp(void);

	//[93h][94h][95h][96h]=========================================================================
	void BTE_S0_Memory_Start_Address(unsigned long Addr);	

	//[97h][98h]=========================================================================
	void BTE_S0_Image_Width(unsigned short WX);	

	//[99h][9Ah][9Bh][9Ch]=========================================================================
	void BTE_S0_Window_Start_XY(unsigned short WX,unsigned short HY);	

	//[9Dh][9Eh][9Fh][A0h]=========================================================================
	void BTE_S1_Memory_Start_Address(unsigned long Addr);
	void S1_Constant_color_256(unsigned char temp);
	void S1_Constant_color_65k(unsigned short temp);
	void S1_Constant_color_16M(unsigned long temp);	

	//[A1h][A2h]=========================================================================
	void BTE_S1_Image_Width(unsigned short WX);	

	//[A3h][A4h][A5h][A6h]=========================================================================
	void BTE_S1_Window_Start_XY(unsigned short WX,unsigned short HY);	

	//[A7h][A8h][A9h][AAh]=========================================================================
	void BTE_Destination_Memory_Start_Address(unsigned long Addr);	

	//[ABh][ACh]=========================================================================
	void BTE_Destination_Image_Width(unsigned short WX);	

	//[ADh][AEh][AFh][B0h]=========================================================================
	void BTE_Destination_Window_Start_XY(unsigned short WX,unsigned short HY);	

	//[B1h][B2h][B3h][B4h]=========================================================================
	void BTE_Window_Size(unsigned short WX, unsigned short WY);

	//[B5h]=========================================================================
	void BTE_Alpha_Blending_Effect(unsigned char temp);


	//**[B5h]**//

	////////////////////////////////////////////////////////////////////////
	////**** [ Function : Serial Flash ] ****////


	//REG[B6h] Serial flash DMA Controller REG (DMA_CTRL) 
	void Start_SFI_DMA(void);
	void Check_Busy_SFI_DMA(void);

	//REG[B7h] Serial Flash/ROM Controller Register (SFL_CTRL) 
	void Select_SFI_0(void);
	void Select_SFI_1(void);
	void Select_SFI_Font_Mode(void);
	void Select_SFI_DMA_Mode(void);
	void Select_SFI_24bit_Address(void);
	void Select_SFI_32bit_Address(void);
	void Select_SFI_Waveform_Mode_0(void);
	void Select_SFI_Waveform_Mode_3(void);
	void Select_SFI_0_DummyRead(void);
	void Select_SFI_8_DummyRead(void);
	void Select_SFI_16_DummyRead(void);
	void Select_SFI_24_DummyRead(void);
	void Select_SFI_Single_Mode(void);
	void Select_SFI_Dual_Mode0(void);
	void Select_SFI_Dual_Mode1(void);

	//REG[B8h] SPI master Tx /Rx FIFO Data Register (SPIDR) 
	unsigned char SPI_Master_FIFO_Data_Put(unsigned char Data);
	unsigned char SPI_Master_FIFO_Data_Get(void);

	//REG[B9h] SPI master Control Register (SPIMCR2) 
	void Mask_SPI_Master_Interrupt_Flag(void);
	void Select_nSS_drive_on_xnsfcs0(void);
	void Select_nSS_drive_on_xnsfcs1(void);
	void nSS_Inactive(void);
	void nSS_Active(void);
	void OVFIRQEN_Enable(void);
	void EMTIRQEN_Enable(void);
	void Reset_CPOL(void);
	void Set_CPOL(void);
	void Reset_CPHA(void);
	void Set_CPHA(void);

	//REG[BAh] SPI master Status Register (SPIMSR)
	unsigned char Tx_FIFO_Empty_Flag(void);
	unsigned char Tx_FIFO_Full_Flag(void);
	unsigned char Rx_FIFO_Empty_Flag(void);
	unsigned char Rx_FIFO_full_flag(void);
	unsigned char OVFI_Flag(void);
	void Clear_OVFI_Flag(void);
	unsigned char EMTI_Flag(void);
	void Clear_EMTI_Flag(void);

	//REG[BB] SPI Clock period (SPIDIV) 
	void SPI_Clock_Period(unsigned char temp);


	//**[BCh][BDh][BEh][BFh]**//
	void SFI_DMA_Source_Start_Address(unsigned long Addr);
	//**[C0h][C1h][C2h][C3h]**//
	void SFI_DMA_Destination_Start_Address(unsigned long Addr);
	void SFI_DMA_Destination_Upper_Left_Corner(unsigned short WX,unsigned short HY);
	//**[C4h][C5h]**//
	void SFI_DMA_Destination_Width(unsigned short WX);
	//**[C6h][C7h][C8h][C9h]**//
	void SFI_DMA_Transfer_Number(unsigned long Addr);
	void SFI_DMA_Transfer_Width_Height(unsigned short WX,unsigned short HY);
	//**[CAh][CBh]**//
	void SFI_DMA_Source_Width(unsigned short WX);

	////////////////////////////////////////////////////////////////////////
	////**** [ Function : Font ] ****////
	//**[CCh]**//

	void Font_Select_UserDefine_Mode(void);
	void CGROM_Select_Internal_CGROM(void);
	void CGROM_Select_Genitop_FontROM(void);
	void Font_Select_8x16_16x16(void);
	void Font_Select_12x24_24x24(void);
	void Font_Select_16x32_32x32(void);
	void Internal_CGROM_Select_ISOIEC8859_1(void);
	void Internal_CGROM_Select_ISOIEC8859_2(void);
	void Internal_CGROM_Select_ISOIEC8859_3(void);
	void Internal_CGROM_Select_ISOIEC8859_4(void);
	//**[CDh]**//
	void Enable_Font_Alignment(void);
	void Disable_Font_Alignment(void);
	void Font_Background_select_Transparency(void);
	void Font_Background_select_Color(void);
	void Font_0_degree(void);
	void Font_90_degree(void);
	void Font_Width_X1(void);
	void Font_Width_X2(void);
	void Font_Width_X3(void);
	void Font_Width_X4(void);
	void Font_Height_X1(void);
	void Font_Height_X2(void);
	void Font_Height_X3(void);
	void Font_Height_X4(void);

	//**[CFh]**//
	void Set_GTFont_Decoder(unsigned char temp);
	//**[D0h]**//
	void Font_Line_Distance(unsigned char temp);
	//**[D1h]**//
	void Set_Font_to_Font_Width(unsigned char temp);
        //[DBh]~[DEh]=========================================================================
  void CGRAM_Start_address(unsigned long Addr);

};
extern ER5517Basic ER5517;
#endif

#include "Arduino.h"
#include "LCD.h"
#include <SPI.h>

#define  LCM_RESET  9
#define  LCM_CS     10

// ------------------------------------------------------------ SPI Drive --------------------------------------------------------------------
#if Arduino_SPI
void ER5517Basic::SPIInit()
{
	pinMode(LCM_CS, OUTPUT);
	SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
	SPI.begin();
}
void ER5517Basic::SPISetCs(int cs)
{
	if(cs)
		digitalWrite(LCM_CS,HIGH);
	else
	  digitalWrite(LCM_CS,LOW);
}
unsigned char ER5517Basic::SPIRwByte(unsigned char value)
{
	unsigned char rec;
	rec = SPI.transfer(value);
	return rec;
}
void ER5517Basic::SPI_CmdWrite(int cmd)
{
  ER5517.SPISetCs(0);    //SS_RESET;
  ER5517.SPIRwByte(0x00);
  ER5517.SPIRwByte(cmd);
  ER5517.SPISetCs(1);    //SS_SET;
}
void ER5517Basic::SPI_DataWrite(int data)
{
  ER5517.SPISetCs(0);    //SS_RESET;
  ER5517.SPIRwByte(0x80);
  ER5517.SPIRwByte(data);
  ER5517.SPISetCs(1);    //SS_SET;
}
void ER5517Basic::SPI_DataWrite_Pixel(int data)
{
  ER5517.SPISetCs(0);    //SS_RESET;
  ER5517.SPIRwByte(0x80);
  ER5517.SPIRwByte(data);
  ER5517.SPISetCs(1);    //SS_SET;
  
  ER5517.SPISetCs(0);    //SS_RESET;
  ER5517.SPIRwByte(0x80);
  ER5517.SPIRwByte(data>>8);
  ER5517.SPISetCs(1);    //SS_SET;
}
int ER5517Basic::SPI_StatusRead(void)
{
  int temp = 0;
  ER5517.SPISetCs(0);    //SS_RESET;
  ER5517.SPIRwByte(0x40);
  temp = ER5517.SPIRwByte(0x00);
  ER5517.SPISetCs(1);    //SS_SET;
  return temp;
}

int ER5517Basic::SPI_DataRead(void)
{
  int temp = 0;
  ER5517.SPISetCs(0);    //SS_RESET;
  ER5517.SPIRwByte(0xc0);
  temp = ER5517.SPIRwByte(0x00);
  ER5517.SPISetCs(1);    //SS_SET;
  return temp;
}
#endif

//-----------------------------------------------------------------------------------------------------------------------------------

void ER5517Basic::Parallel_Init(void)
{
	#if Arduino_SPI
	ER5517.SPIInit();
	#endif
	
	#if Arduino_IIC
	ER5517.IICInit();
	#endif
}
void ER5517Basic::LCD_CmdWrite(unsigned char cmd)
{
	#if Arduino_SPI
	ER5517.SPI_CmdWrite(cmd);
	#endif
	
	#if Arduino_IIC
	ER5517.IIC_CmdWrite(cmd);
	#endif
}

void ER5517Basic::LCD_DataWrite(unsigned char data)
{
	#if Arduino_SPI
	ER5517.SPI_DataWrite(data);
	#endif
	
	#if Arduino_IIC
	ER5517.IIC_DataWrite(data);
	#endif
}

void ER5517Basic::LCD_DataWrite_Pixel(unsigned int data)
{
	#if Arduino_SPI
	ER5517.SPI_DataWrite_Pixel(data);
	#endif
	
	#if Arduino_IIC
	ER5517.IIC_DataWrite_Pixel(data);
	#endif
}


unsigned char ER5517Basic::LCD_StatusRead(void)
{
	unsigned char temp = 0;
	
	#if Arduino_SPI
	temp = ER5517.SPI_StatusRead();
	#endif
	
	#if Arduino_IIC
	temp = ER5517.IIC_StatusRead();
	#endif
	
	return temp;
}

unsigned int ER5517Basic::LCD_DataRead(void)
{
	unsigned int temp = 0;

	#if Arduino_SPI
	temp = ER5517.SPI_DataRead();
	#endif
	
	#if Arduino_IIC
	temp = ER5517.IIC_DataRead();
	#endif
	
	return temp;
}
void ER5517Basic::LCD_RegisterWrite(unsigned char Cmd,unsigned char Data)
{
	ER5517.LCD_CmdWrite(Cmd);
	ER5517.LCD_DataWrite(Data);
}  
//---------------------//
unsigned char ER5517Basic::LCD_RegisterRead(unsigned char Cmd)
{
	unsigned char temp;
	
	ER5517.LCD_CmdWrite(Cmd);
	temp=ER5517.LCD_DataRead();
	return temp;
}


void ER5517Basic::Check_SDRAM_Ready(void)
{
/*  0: SDRAM is not ready for access
  1: SDRAM is ready for access    */  
  unsigned char temp;
  do
  {
    temp=ER5517.LCD_StatusRead();
  }
  while( (temp&0x04) == 0x00 );
}
void ER5517Basic::TFT_18bit(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x01);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb4;
    temp |= cSetb3;
  ER5517.LCD_DataWrite(temp);  
}



void ER5517Basic::Host_Bus_16bit(void)
{
/*  Parallel Host Data Bus Width Selection
    0: 8-bit Parallel Host Data Bus.
    1: 16-bit Parallel Host Data Bus.*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x01);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::RGB_16b_16bpp(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x02);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb7;
  temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::MemRead_Left_Right_Top_Down(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x02);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb5;
  temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Graphic_Mode(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x03);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Memory_Select_SDRAM(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x03);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb1;
    temp &= cClrb0; // B
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::HSCAN_L_to_R(void)
{
/*  
Horizontal Scan Direction
0 : From Left to Right
1 : From Right to Left
PIP window will be disabled when HDIR set as 1.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x12);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::VSCAN_T_to_B(void)
{
/*  
Vertical Scan direction
0 : From Top to Bottom
1 : From bottom to Top
PIP window will be disabled when VDIR set as 1.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x12);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb3;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::PDATA_Set_RGB(void)
{
/*  
parallel PDATA[23:0] Output Sequence
000b : RGB.
001b : RBG.
010b : GRB.
011b : GBR.
100b : BRG.
101b : BGR.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x12);
  temp = ER5517.LCD_DataRead();
    temp &=0xf8;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::PCLK_Rising(void)   
{
/*
PCLK Inversion
0: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK falling edge.
1: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK rising edge.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x12);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb7;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::PCLK_Falling(void)
{
/*
PCLK Inversion
0: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK falling edge.
1: PDAT, DE, HSYNC etc. Drive(/ change) at PCLK rising edge.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x12);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb7;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::HSYNC_Low_Active(void)
{
/*  
HSYNC Polarity
0 : Low active.
1 : High active.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x13);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb7;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::HSYNC_High_Active(void)
{
/*  
HSYNC Polarity
0 : Low active.
1 : High active.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x13);
  temp = ER5517.LCD_DataRead();   
  temp |= cSetb7;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::VSYNC_Low_Active(void)
{
/*  
VSYNC Polarity
0 : Low active.
1 : High active.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x13);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb6; 
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::VSYNC_High_Active(void)
{
/*  
VSYNC Polarity
0 : Low active.
1 : High active.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x13);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::DE_Low_Active(void)
{
/*  
DE Polarity
0 : High active.
1 : Low active.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x13);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb5;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::DE_High_Active(void)
{
/*  
DE Polarity
0 : High active.
1 : Low active.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x13);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb5;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Set_PCLK(unsigned char val)
{
  if(val == 1)  ER5517.PCLK_Falling();
  else      ER5517.PCLK_Rising();
}

void ER5517Basic::Set_HSYNC_Active(unsigned char val)
{
  if(val == 1)  ER5517.HSYNC_High_Active();
  else      ER5517.HSYNC_Low_Active();
}

void ER5517Basic::Set_VSYNC_Active(unsigned char val)
{
  if(val == 1)  ER5517.VSYNC_High_Active();
  else      ER5517.VSYNC_Low_Active();
}

void ER5517Basic::Set_DE_Active(unsigned char val)
{
  if(val == 1)  ER5517.DE_High_Active();
  else      ER5517.DE_Low_Active();
}
void ER5517Basic::LCD_HorizontalWidth_VerticalHeight(unsigned short WX,unsigned short HY)
{
  unsigned char temp;
  if(WX<8)
    {
  ER5517.LCD_CmdWrite(0x14);
  ER5517.LCD_DataWrite(0x00);
    
  ER5517.LCD_CmdWrite(0x15);
  ER5517.LCD_DataWrite(WX);
    
    temp=HY-1;
  ER5517.LCD_CmdWrite(0x1A);
  ER5517.LCD_DataWrite(temp);
      
  temp=(HY-1)>>8;
  ER5517.LCD_CmdWrite(0x1B);
  ER5517.LCD_DataWrite(temp);
  }
  else
  {
    temp=(WX/8)-1;
  ER5517.LCD_CmdWrite(0x14);
  ER5517.LCD_DataWrite(temp);
    
    temp=WX%8;
  ER5517.LCD_CmdWrite(0x15);
  ER5517.LCD_DataWrite(temp);
    
    temp=HY-1;
  ER5517.LCD_CmdWrite(0x1A);
  ER5517.LCD_DataWrite(temp);
      
  temp=(HY-1)>>8;
  ER5517.LCD_CmdWrite(0x1B);
  ER5517.LCD_DataWrite(temp);
  }
}
//[16h][17h]=========================================================================
void ER5517Basic::LCD_Horizontal_Non_Display(unsigned short WX)
{
  unsigned char temp;
  if(WX<8)
  {
  ER5517.LCD_CmdWrite(0x16);
  ER5517.LCD_DataWrite(0x00);
    
  ER5517.LCD_CmdWrite(0x17);
  ER5517.LCD_DataWrite(WX);
  }
  else
  {
    temp=(WX/8)-1;
  ER5517.LCD_CmdWrite(0x16);
  ER5517.LCD_DataWrite(temp);
    
    temp=WX%8;
  ER5517.LCD_CmdWrite(0x17);
  ER5517.LCD_DataWrite(temp);
  } 
}
//[18h]=========================================================================
void ER5517Basic::LCD_HSYNC_Start_Position(unsigned short WX)
{
  unsigned char temp;
  if(WX<8)
  {
  ER5517.LCD_CmdWrite(0x18);
  ER5517.LCD_DataWrite(0x00);
  }
  else
  {
    temp=(WX/8)-1;
  ER5517.LCD_CmdWrite(0x18);
  ER5517.LCD_DataWrite(temp);  
  }
}
//[19h]=========================================================================
void ER5517Basic::LCD_HSYNC_Pulse_Width(unsigned short WX)
{
  unsigned char temp;
  if(WX<8)
  {
  ER5517.LCD_CmdWrite(0x19);
  ER5517.LCD_DataWrite(0x00);
  }
  else
  {
    temp=(WX/8)-1;
  ER5517.LCD_CmdWrite(0x19);
  ER5517.LCD_DataWrite(temp);  
  }
}
//[1Ch][1Dh]=========================================================================
void ER5517Basic::LCD_Vertical_Non_Display(unsigned short HY)
{
  unsigned char temp;
    temp=HY-1;
  ER5517.LCD_CmdWrite(0x1C);
  ER5517.LCD_DataWrite(temp);

  ER5517.LCD_CmdWrite(0x1D);
  ER5517.LCD_DataWrite(temp>>8);
}
//[1Eh]=========================================================================
void ER5517Basic::LCD_VSYNC_Start_Position(unsigned short HY)
{
  unsigned char temp;
    temp=HY-1;
  ER5517.LCD_CmdWrite(0x1E);
  ER5517.LCD_DataWrite(temp);
}
//[1Fh]=========================================================================
void ER5517Basic::LCD_VSYNC_Pulse_Width(unsigned short HY)
{
  unsigned char temp;
    temp=HY-1;
  ER5517.LCD_CmdWrite(0x1F);
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Memory_XY_Mode(void) 
{
  unsigned char temp;

  ER5517.LCD_CmdWrite(0x5E);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb2;
  ER5517.LCD_DataWrite(temp);
}

void ER5517Basic::Memory_Linear_Mode(void)	
{

	unsigned char temp;

	ER5517.LCD_CmdWrite(0x5E);
	temp = ER5517.LCD_DataRead();
	temp |= cSetb2;
	ER5517.LCD_DataWrite(temp);
}

void ER5517Basic::Memory_16bpp_Mode(void)  
{
  unsigned char temp;

  ER5517.LCD_CmdWrite(0x5E);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb1;
  temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_Main_Window_16bpp(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x10);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb3;
    temp |= cSetb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Main_Image_Start_Address(unsigned long Addr) 
{
/*
[20h] Main Image Start Address[7:2]
[21h] Main Image Start Address[15:8]
[22h] Main Image Start Address [23:16]
[23h] Main Image Start Address [31:24]
*/
  ER5517.LCD_RegisterWrite(0x20,Addr);
  ER5517.LCD_RegisterWrite(0x21,Addr>>8);
  ER5517.LCD_RegisterWrite(0x22,Addr>>16);
  ER5517.LCD_RegisterWrite(0x23,Addr>>24);
}
void ER5517Basic::Main_Image_Width(unsigned short WX)  
{
/*
[24h] Main Image Width [7:0]
[25h] Main Image Width [12:8]
Unit: Pixel.
It must be divisible by 4. MIW Bit [1:0] tie to ��0�� internally.
The value is physical pixel number. Maximum value is 8188 pixels
*/
  ER5517.LCD_RegisterWrite(0x24,WX);
  ER5517.LCD_RegisterWrite(0x25,WX>>8);
}
//[26h][27h][28h][29h]=========================================================================
void ER5517Basic::Main_Window_Start_XY(unsigned short WX,unsigned short HY)  
{
/*
[26h] Main Window Upper-Left corner X-coordination [7:0]
[27h] Main Window Upper-Left corner X-coordination [12:8]
Reference Main Image coordination.
Unit: Pixel
It must be divisible by 4. MWULX Bit [1:0] tie to ��0�� internally.
X-axis coordination plus Horizontal display width cannot large than 8188.

[28h] Main Window Upper-Left corner Y-coordination [7:0]
[29h] Main Window Upper-Left corner Y-coordination [12:8]
Reference Main Image coordination.
Unit: Pixel
Range is between 0 and 8191.
*/
  ER5517.LCD_RegisterWrite(0x26,WX);
  ER5517.LCD_RegisterWrite(0x27,WX>>8);

  ER5517.LCD_RegisterWrite(0x28,HY);
  ER5517.LCD_RegisterWrite(0x29,HY>>8);
}
void ER5517Basic::Canvas_Image_Start_address(unsigned long Addr) 
{
/*
[50h] Start address of Canvas [7:0]
[51h] Start address of Canvas [15:8]
[52h] Start address of Canvas [23:16]
[53h] Start address of Canvas [31:24]
*/
  ER5517.LCD_RegisterWrite(0x50,Addr);
  ER5517.LCD_RegisterWrite(0x51,Addr>>8);
  ER5517.LCD_RegisterWrite(0x52,Addr>>16);
  ER5517.LCD_RegisterWrite(0x53,Addr>>24);
}
//[54h][55h]=========================================================================
void ER5517Basic::Canvas_image_width(unsigned short WX)  
{
/*
[54h] Canvas image width [7:2]
[55h] Canvas image width [12:8]
*/
  ER5517.LCD_RegisterWrite(0x54,WX);
  ER5517.LCD_RegisterWrite(0x55,WX>>8);
}
//[56h][57h][58h][59h]=========================================================================
void ER5517Basic::Active_Window_XY(unsigned short WX,unsigned short HY)  
{
/*
[56h] Active Window Upper-Left corner X-coordination [7:0]
[57h] Active Window Upper-Left corner X-coordination [12:8]
[58h] Active Window Upper-Left corner Y-coordination [7:0]
[59h] Active Window Upper-Left corner Y-coordination [12:8]
*/
  ER5517.LCD_RegisterWrite(0x56,WX);
  ER5517.LCD_RegisterWrite(0x57,WX>>8);
  
  ER5517.LCD_RegisterWrite(0x58,HY);
  ER5517.LCD_RegisterWrite(0x59,HY>>8);
}
//[5Ah][5Bh][5Ch][5Dh]=========================================================================
void ER5517Basic::Active_Window_WH(unsigned short WX,unsigned short HY)  
{
/*
[5Ah] Width of Active Window [7:0]
[5Bh] Width of Active Window [12:8]
[5Ch] Height of Active Window [7:0]
[5Dh] Height of Active Window [12:8]
*/
  ER5517.LCD_RegisterWrite(0x5A,WX);
  ER5517.LCD_RegisterWrite(0x5B,WX>>8);
 
  ER5517.LCD_RegisterWrite(0x5C,HY);
  ER5517.LCD_RegisterWrite(0x5D,HY>>8);
}
void ER5517Basic::Foreground_color_65k(unsigned short temp)
{
    ER5517.LCD_CmdWrite(0xD2);
  ER5517.LCD_DataWrite(temp>>8);
 
    ER5517.LCD_CmdWrite(0xD3);
  ER5517.LCD_DataWrite(temp>>3);
  
    ER5517.LCD_CmdWrite(0xD4);
  ER5517.LCD_DataWrite(temp<<3);
}

//Input data format:R5G6B6
void ER5517Basic::Background_color_65k(unsigned short temp)
{
    ER5517.LCD_CmdWrite(0xD5);
  ER5517.LCD_DataWrite(temp>>8);
  
    ER5517.LCD_CmdWrite(0xD6);
  ER5517.LCD_DataWrite(temp>>3);
   
    ER5517.LCD_CmdWrite(0xD7);
  ER5517.LCD_DataWrite(temp<<3);
}



void ER5517Basic::Check_Busy_Draw(void)
{
  unsigned char temp;
  do
  {
    temp=ER5517.LCD_StatusRead();
  }
  while(temp&0x08);

}

void ER5517Basic::Check_2D_Busy(void)
{
  do
  {
    
  }
  while( ER5517.LCD_StatusRead()&0x08 );
}


void ER5517Basic::Check_Mem_WR_FIFO_not_Full(void)
{
/*  0: Memory Write FIFO is not full.
  1: Memory Write FIFO is full.   */
  do
  {
    
  }
  while( ER5517.LCD_StatusRead()&0x80 );
}
void ER5517Basic::Check_Mem_WR_FIFO_Empty(void)
{
/*  0: Memory Write FIFO is not empty.
  1: Memory Write FIFO is empty.    */  
  do
  {
    
  }
  while( (ER5517.LCD_StatusRead()&0x40) == 0x00 );
}
void ER5517Basic::Check_Mem_RD_FIFO_not_Full(void)
{
/*  0: Memory Read FIFO is not full.
  1: Memory Read FIFO is full.    */
  do
  {
    
  }
  while( ER5517.LCD_StatusRead()&0x20 );
}
void ER5517Basic::Check_Mem_RD_FIFO_not_Empty(void)
{
/*  0: Memory Read FIFO is not empty.
  1: Memory Read FIFO is empty.
    */
  do
  {
    
  }
  while( ER5517.LCD_StatusRead()&0x10 );
}


void ER5517Basic::DrawSquare_Fill
(
 unsigned short X1                
,unsigned short Y1              
,unsigned short X2                
,unsigned short Y2              
,unsigned long ForegroundColor   
)
{
  ER5517.Foreground_color_65k(ForegroundColor);
  ER5517.Square_Start_XY(X1,Y1);
  ER5517.Square_End_XY(X2,Y2);
  ER5517.Start_Square_Fill();
  ER5517.Check_2D_Busy();
}

void ER5517Basic::DrawCircle_Fill
(
 unsigned short X1                
,unsigned short Y1              
,unsigned short R                            
,unsigned long ForegroundColor 
)

{
  ER5517.Foreground_color_65k(ForegroundColor);
  ER5517.Circle_Center_XY(X1,Y1);
  ER5517.Circle_Radius_R(R);
  ER5517.Start_Circle_or_Ellipse_Fill();
  ER5517.Check_2D_Busy();
}


void ER5517Basic::Enable_SFlash_SPI(void)
{
/*  Serial Flash SPI Interface Enable/Disable
    0: Disable
    1: Enable*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x01);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb1;
  ER5517.LCD_DataWrite(temp);     
}

void ER5517Basic::Goto_Pixel_XY(unsigned short WX,unsigned short HY) 
{
/*
[Write]: Set Graphic Read/Write position
[Read]: Current Graphic Read/Write position
Read back is Read position or Write position depends on
REG[5Eh] bit3, Select to read back Graphic Read/Write position.
When DPRAM Linear mode:Graphic Read/Write Position [31:24][23:16][15:8][7:0]
When DPRAM Active window mode:Graphic Read/Write 
Horizontal Position [12:8][7:0], 
Vertical Position [12:8][7:0].
Reference Canvas image coordination. Unit: Pixel
*/
  ER5517.LCD_RegisterWrite(0x5F,WX);
  ER5517.LCD_RegisterWrite(0x60,WX>>8);
  
  ER5517.LCD_RegisterWrite(0x61,HY);
  ER5517.LCD_RegisterWrite(0x62,HY>>8);
}

void ER5517Basic::Goto_Text_XY(unsigned short WX,unsigned short HY)  
{
/*
Write: Set Text Write position
Read: Current Text Write position
Text Write X-coordination [12:8][7:0]
Text Write Y-coordination [12:8][7:0]
Reference Canvas image coordination.
Unit: Pixel
*/
  ER5517.LCD_RegisterWrite(0x63,WX);
  ER5517.LCD_RegisterWrite(0x64,WX>>8);
  
  ER5517.LCD_RegisterWrite(0x65,HY);
  ER5517.LCD_RegisterWrite(0x66,HY>>8);
}


//[67h]=========================================================================
/*
[bit7]Draw Line / Triangle Start Signal
Write Function
0 : Stop the drawing function.
1 : Start the drawing function.
Read Function
0 : Drawing function complete.
1 : Drawing function is processing.
[bit5]Fill function for Triangle Signal
0 : Non fill.
1 : Fill.
[bit1]Draw Triangle or Line Select Signal
0 : Draw Line
1 : Draw Triangle
*/
void ER5517Basic::Start_Line(void)
{
  ER5517.LCD_CmdWrite(0x67);
  ER5517.LCD_DataWrite(0x80);
  Check_Busy_Draw();
}
void ER5517Basic::Start_Triangle(void)
{
  ER5517.LCD_CmdWrite(0x67);
  ER5517.LCD_DataWrite(0x82);//B1000_0010
  Check_Busy_Draw();
}
void ER5517Basic::Start_Triangle_Fill(void)
{

  ER5517.LCD_CmdWrite(0x67);
  ER5517.LCD_DataWrite(0xA2);//B1010_0010
  Check_Busy_Draw();
}
//[68h][69h][6Ah][6Bh]=========================================================================
void ER5517Basic::Line_Start_XY(unsigned short WX,unsigned short HY)
{
/*
[68h] Draw Line/Square/Triangle Start X-coordination [7:0]
[69h] Draw Line/Square/Triangle Start X-coordination [12:8]
[6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0]
[6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x68);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x69);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x6A);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x6B);
  ER5517.LCD_DataWrite(HY>>8);
}
//[6Ch][6Dh][6Eh][6Fh]=========================================================================
//���յ�
void ER5517Basic::Line_End_XY(unsigned short WX,unsigned short HY)
{
/*
[6Ch] Draw Line/Square/Triangle End X-coordination [7:0]
[6Dh] Draw Line/Square/Triangle End X-coordination [12:8]
[6Eh] Draw Line/Square/Triangle End Y-coordination [7:0]
[6Fh] Draw Line/Square/Triangle End Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x6C);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x6D);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x6E);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x6F);
  ER5517.LCD_DataWrite(HY>>8);
}
//[68h]~[73h]=========================================================================
//�T��-�I1
void ER5517Basic::Triangle_Point1_XY(unsigned short WX,unsigned short HY)
{
/*
[68h] Draw Line/Square/Triangle Start X-coordination [7:0]
[69h] Draw Line/Square/Triangle Start X-coordination [12:8]
[6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0]
[6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x68);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x69);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x6A);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x6B);
  ER5517.LCD_DataWrite(HY>>8);
}
//�T��-�I2
void ER5517Basic::Triangle_Point2_XY(unsigned short WX,unsigned short HY)
{
/*
[6Ch] Draw Line/Square/Triangle End X-coordination [7:0]
[6Dh] Draw Line/Square/Triangle End X-coordination [12:8]
[6Eh] Draw Line/Square/Triangle End Y-coordination [7:0]
[6Fh] Draw Line/Square/Triangle End Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x6C);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x6D);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x6E);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x6F);
  ER5517.LCD_DataWrite(HY>>8);
}
//�T��-�I3
void ER5517Basic::Triangle_Point3_XY (unsigned short WX,unsigned short HY)
{
/*
[70h] Draw Triangle Point 3 X-coordination [7:0]
[71h] Draw Triangle Point 3 X-coordination [12:8]
[72h] Draw Triangle Point 3 Y-coordination [7:0]
[73h] Draw Triangle Point 3 Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x70);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x71);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x72);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x73);
  ER5517.LCD_DataWrite(HY>>8);
}

void ER5517Basic::Square_Start_XY(unsigned short WX,unsigned short HY)
{
/*
[68h] Draw Line/Square/Triangle Start X-coordination [7:0]
[69h] Draw Line/Square/Triangle Start X-coordination [12:8]
[6Ah] Draw Line/Square/Triangle Start Y-coordination [7:0]
[6Bh] Draw Line/Square/Triangle Start Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x68);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x69);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x6A);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x6B);
  ER5517.LCD_DataWrite(HY>>8);
}

void ER5517Basic::Square_End_XY(unsigned short WX,unsigned short HY)
{
/*
[6Ch] Draw Line/Square/Triangle End X-coordination [7:0]
[6Dh] Draw Line/Square/Triangle End X-coordination [12:8]
[6Eh] Draw Line/Square/Triangle End Y-coordination [7:0]
[6Fh] Draw Line/Square/Triangle End Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x6C);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x6D);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x6E);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x6F);
  ER5517.LCD_DataWrite(HY>>8);
}
//[76h]=========================================================================
/*
[bit7]
Draw Circle / Ellipse / Square /Circle Square Start Signal 
Write Function
0 : Stop the drawing function.
1 : Start the drawing function.
Read Function
0 : Drawing function complete.
1 : Drawing function is processing.
[bit6]
Fill the Circle / Ellipse / Square / Circle Square Signal
0 : Non fill.
1 : fill.
[bit5 bit4]
Draw Circle / Ellipse / Square / Ellipse Curve / Circle Square Select
00 : Draw Circle / Ellipse
01 : Draw Circle / Ellipse Curve
10 : Draw Square.
11 : Draw Circle Square.
[bit1 bit0]
Draw Circle / Ellipse Curve Part Select
00 : 
01 : 
10 : 
11 : 
*/
void ER5517Basic::Start_Circle_or_Ellipse(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0x80);//B1000_XXXX
  Check_Busy_Draw();  
}
void ER5517Basic::Start_Circle_or_Ellipse_Fill(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xC0);//B1100_XXXX
  Check_Busy_Draw();  
}
//
void ER5517Basic::Start_Left_Down_Curve(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0x90);//B1001_XX00
  Check_Busy_Draw();  
}
void ER5517Basic::Start_Left_Up_Curve(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0x91);//B1001_XX01
  Check_Busy_Draw();  
}
void ER5517Basic::Start_Right_Up_Curve(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0x92);//B1001_XX10
  Check_Busy_Draw();  
}
void ER5517Basic::Start_Right_Down_Curve(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0x93);//B1001_XX11
  Check_Busy_Draw();  
}
//
void ER5517Basic::Start_Left_Down_Curve_Fill(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xD0);//B1101_XX00
  Check_Busy_Draw();
}
void ER5517Basic::Start_Left_Up_Curve_Fill(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xD1);//B1101_XX01
  Check_Busy_Draw();
}
void ER5517Basic::Start_Right_Up_Curve_Fill(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xD2);//B1101_XX10
  Check_Busy_Draw();
}
void ER5517Basic::Start_Right_Down_Curve_Fill(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xD3);//B1101_XX11
  Check_Busy_Draw();
}
//
void ER5517Basic::Start_Square(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xA0);//B1010_XXXX
  Check_Busy_Draw();
}
void ER5517Basic::Start_Square_Fill(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xE0);//B1110_XXXX
  Check_Busy_Draw();
}
void ER5517Basic::Start_Circle_Square(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xB0);//B1011_XXXX
  Check_Busy_Draw();  
}
void ER5517Basic::Start_Circle_Square_Fill(void)
{
  ER5517.LCD_CmdWrite(0x76);
  ER5517.LCD_DataWrite(0xF0);//B1111_XXXX
  Check_Busy_Draw();  
}
//[77h]~[7Eh]=========================================================================

void ER5517Basic::Circle_Center_XY(unsigned short WX,unsigned short HY)
{
/*
[7Bh] Draw Circle/Ellipse/Circle Square Center X-coordination [7:0]
[7Ch] Draw Circle/Ellipse/Circle Square Center X-coordination [12:8]
[7Dh] Draw Circle/Ellipse/Circle Square Center Y-coordination [7:0]
[7Eh] Draw Circle/Ellipse/Circle Square Center Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x7B);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x7C);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x7D);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x7E);
  ER5517.LCD_DataWrite(HY>>8);
}

void ER5517Basic::Ellipse_Center_XY(unsigned short WX,unsigned short HY)
{
/*
[7Bh] Draw Circle/Ellipse/Circle Square Center X-coordination [7:0]
[7Ch] Draw Circle/Ellipse/Circle Square Center X-coordination [12:8]
[7Dh] Draw Circle/Ellipse/Circle Square Center Y-coordination [7:0]
[7Eh] Draw Circle/Ellipse/Circle Square Center Y-coordination [12:8]
*/
  ER5517.LCD_CmdWrite(0x7B);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x7C);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x7D);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x7E);
  ER5517.LCD_DataWrite(HY>>8);
}

void ER5517Basic::Circle_Radius_R(unsigned short WX)
{
/*
[77h] Draw Circle/Ellipse/Circle Square Major radius [7:0]
[78h] Draw Circle/Ellipse/Circle Square Major radius [12:8]
[79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0]
[7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8]
*/
  ER5517.LCD_CmdWrite(0x77);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x78);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x79);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x7A);
  ER5517.LCD_DataWrite(WX>>8);
}


void ER5517Basic::Ellipse_Radius_RxRy(unsigned short WX,unsigned short HY)
{
/*
[77h] Draw Circle/Ellipse/Circle Square Major radius [7:0]
[78h] Draw Circle/Ellipse/Circle Square Major radius [12:8]
[79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0]
[7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8]
*/
  ER5517.LCD_CmdWrite(0x77);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x78);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x79);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x7A);
  ER5517.LCD_DataWrite(HY>>8);
}


void ER5517Basic::Circle_Square_Radius_RxRy(unsigned short WX,unsigned short HY)
{
/*
[77h] Draw Circle/Ellipse/Circle Square Major radius [7:0]
[78h] Draw Circle/Ellipse/Circle Square Major radius [12:8]
[79h] Draw Circle/Ellipse/Circle Square Minor radius [7:0]
[7Ah] Draw Circle/Ellipse/Circle Square Minor radius [12:8]
*/
  ER5517.LCD_CmdWrite(0x77);
  ER5517.LCD_DataWrite(WX);

  ER5517.LCD_CmdWrite(0x78);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0x79);
  ER5517.LCD_DataWrite(HY);

  ER5517.LCD_CmdWrite(0x7A);
  ER5517.LCD_DataWrite(HY>>8);
}

//[84h]=========================================================================
void ER5517Basic::Set_PWM_Prescaler_1_to_256(unsigned short WX)
{
/*
PWM Prescaler Register
These 8 bits determine prescaler value for Timer 0 and 1.
Time base is ��Core_Freq / (Prescaler + 1)��
*/
  WX=WX-1;
  ER5517.LCD_CmdWrite(0x84);
  ER5517.LCD_DataWrite(WX);
}
//[85h]=========================================================================
void ER5517Basic::Select_PWM1_Clock_Divided_By_1(void)
{
/*
Select MUX input for PWM Timer 1.
00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8;
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb7;
  temp &= cClrb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM1_Clock_Divided_By_2(void)
{
/*
Select MUX input for PWM Timer 1.
00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8;
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb7;
  temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM1_Clock_Divided_By_4(void)
{
/*
Select MUX input for PWM Timer 1.
00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8;
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb7;
  temp &= cClrb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM1_Clock_Divided_By_8(void)
{
/*
Select MUX input for PWM Timer 1.
00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8;
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb7;
  temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM0_Clock_Divided_By_1(void)
{
/*
Select MUX input for PWM Timer 0.
00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8;
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb5;
  temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM0_Clock_Divided_By_2(void)
{
/*
Select MUX input for PWM Timer 0.
00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8;
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb5;
  temp |= cSetb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM0_Clock_Divided_By_4(void)
{
/*
Select MUX input for PWM Timer 0.
00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8;
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb5;
  temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM0_Clock_Divided_By_8(void)
{
/*
Select MUX input for PWM Timer 0.
00 = 1; 01 = 1/2; 10 = 1/4 ; 11 = 1/8;
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb5;
  temp |= cSetb4;
  ER5517.LCD_DataWrite(temp);
}
//[85h].[bit3][bit2]=========================================================================
/*
XPWM[1] pin function control
0X: XPWM[1] output system error flag (REG[00h] bit[1:0], Scan bandwidth insufficient + Memory access out of range)
10: XPWM[1] enabled and controlled by PWM timer 1
11: XPWM[1] output oscillator clock
//If XTEST[0] set high, then XPWM[1] will become panel scan clock input.
*/
void ER5517Basic::Select_PWM1_is_ErrorFlag(void)
{
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb3;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM1(void)
{
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb3;
  temp &= cClrb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM1_is_Osc_Clock(void)
{
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb3;
  temp |= cSetb2;
  ER5517.LCD_DataWrite(temp);
}
//[85h].[bit1][bit0]=========================================================================
/*
XPWM[0] pin function control
0X: XPWM[0] becomes GPIO-C[7]
10: XPWM[0] enabled and controlled by PWM timer 0
11: XPWM[0] output core clock
*/
void ER5517Basic::Select_PWM0_is_GPIO_C7(void)
{
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb1;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM0(void)
{
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb1;
  temp &= cClrb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_PWM0_is_Core_Clock(void)
{
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x85);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb1;
  temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}
//[86h]=========================================================================
//[86h]PWM1
void ER5517Basic::Enable_PWM1_Inverter(void)
{
/*
PWM Timer 1 output inverter on/off.
Determine the output inverter on/off for Timer 1. 
0 = Inverter off 
1 = Inverter on for PWM1
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Disable_PWM1_Inverter(void)
{
/*
PWM Timer 1 output inverter on/off.
Determine the output inverter on/off for Timer 1. 
0 = Inverter off 
1 = Inverter on for PWM1
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Auto_Reload_PWM1(void)
{
/*
PWM Timer 1 auto reload on/off
Determine auto reload on/off for Timer 1. 
0 = One-shot 
1 = Interval mode(auto reload)
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb5;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::One_Shot_PWM1(void)
{
/*
PWM Timer 1 auto reload on/off
Determine auto reload on/off for Timer 1. 
0 = One-shot 
1 = Interval mode(auto reload)
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb5;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Start_PWM1(void)
{
/*
PWM Timer 1 start/stop
Determine start/stop for Timer 1. 
0 = Stop 
1 = Start for Timer 1
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Stop_PWM1(void)
{
/*
PWM Timer 1 start/stop
Determine start/stop for Timer 1. 
0 = Stop 
1 = Start for Timer 1
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
//[86h]PWM0
void ER5517Basic::Enable_PWM0_Dead_Zone(void)
{
/*
PWM Timer 0 Dead zone enable
Determine the dead zone operation. 0 = Disable. 1 = Enable.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb3;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Disable_PWM0_Dead_Zone(void)
{
/*
PWM Timer 0 Dead zone enable
Determine the dead zone operation. 0 = Disable. 1 = Enable.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb3;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Enable_PWM0_Inverter(void)
{
/*
PWM Timer 0 output inverter on/off
Determine the output inverter on/off for Timer 0. 
0 = Inverter off 
1 = Inverter on for PWM0
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Disable_PWM0_Inverter(void)
{
/*
PWM Timer 0 output inverter on/off
Determine the output inverter on/off for Timer 0. 
0 = Inverter off 
1 = Inverter on for PWM0
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Auto_Reload_PWM0(void)
{
/*
PWM Timer 0 auto reload on/off
Determine auto reload on/off for Timer 0. 
0 = One-shot 
1 = Interval mode(auto reload)
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb1;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::One_Shot_PWM0(void)
{
/*
PWM Timer 1 auto reload on/off
Determine auto reload on/off for Timer 1. 
0 = One-shot 
1 = Interval mode(auto reload)
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb1;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Start_PWM0(void)
{
/*
PWM Timer 0 start/stop
Determine start/stop for Timer 0. 
0 = Stop 
1 = Start for Timer 0
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Stop_PWM0(void)
{
/*
PWM Timer 0 start/stop
Determine start/stop for Timer 0. 
0 = Stop 
1 = Start for Timer 0
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x86);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb0;
  ER5517.LCD_DataWrite(temp);
}
//[87h]=========================================================================
void ER5517Basic::Set_Timer0_Dead_Zone_Length(unsigned char temp)
{
/*
Timer 0 Dead zone length register
These 8 bits determine the dead zone length. The 1 unit time of
the dead zone length is equal to that of timer 0.
*/
  ER5517.LCD_CmdWrite(0x87);
  ER5517.LCD_DataWrite(temp);
}
//[88h][89h]=========================================================================
void ER5517Basic::Set_Timer0_Compare_Buffer(unsigned short WX)
{
/*
Timer 0 compare buffer register
Compare buffer register total has 16 bits.
When timer counter equal or less than compare buffer register will cause PWM out
high level if inv_on bit is off.
*/
  ER5517.LCD_CmdWrite(0x88);
  ER5517.LCD_DataWrite(WX);
  ER5517.LCD_CmdWrite(0x89);
  ER5517.LCD_DataWrite(WX>>8);
}
//[8Ah][8Bh]=========================================================================
void ER5517Basic::Set_Timer0_Count_Buffer(unsigned short WX)
{
/*
Timer 0 count buffer register
Count buffer register total has 16 bits.
When timer counter equal to 0 will cause PWM timer reload Count buffer register if reload_en bit set as enable.
It may read back timer counter��s real time value when PWM timer start.
*/
  ER5517.LCD_CmdWrite(0x8A);
  ER5517.LCD_DataWrite(WX);
  ER5517.LCD_CmdWrite(0x8B);
  ER5517.LCD_DataWrite(WX>>8);
}
//[8Ch][8Dh]=========================================================================
void ER5517Basic::Set_Timer1_Compare_Buffer(unsigned short WX)
{
/*
Timer 0 compare buffer register
Compare buffer register total has 16 bits.
When timer counter equal or less than compare buffer register will cause PWM out
high level if inv_on bit is off.
*/
  ER5517.LCD_CmdWrite(0x8C);
  ER5517.LCD_DataWrite(WX);
  ER5517.LCD_CmdWrite(0x8D);
  ER5517.LCD_DataWrite(WX>>8);
}
//[8Eh][8Fh]=========================================================================
void ER5517Basic::Set_Timer1_Count_Buffer(unsigned short WX)
{
/*
Timer 0 count buffer register
Count buffer register total has 16 bits.
When timer counter equal to 0 will cause PWM timer reload Count buffer register if reload_en bit set as enable.
It may read back timer counter��s real time value when PWM timer start.
*/
  ER5517.LCD_CmdWrite(0x8E);
  ER5517.LCD_DataWrite(WX);
  ER5517.LCD_CmdWrite(0x8F);
  ER5517.LCD_DataWrite(WX>>8);
}


//[90h]~[B5h]=========================================================================

//[90h]=========================================================================
void ER5517Basic::BTE_Enable(void)
{ 
/*
BTE Function Enable
0 : BTE Function disable.
1 : BTE Function enable.
*/
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x90);
    temp = ER5517.LCD_DataRead();
    temp |= cSetb4 ;
  ER5517.LCD_DataWrite(temp);  
}

//[90h]=========================================================================
void ER5517Basic::BTE_Disable(void)
{ 
/*
BTE Function Enable
0 : BTE Function disable.
1 : BTE Function enable.
*/
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x90);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb4 ;
  ER5517.LCD_DataWrite(temp);  
}

//[90h]=========================================================================
void ER5517Basic::Check_BTE_Busy(void)
{ 
/*
BTE Function Status
0 : BTE Function is idle.
1 : BTE Function is busy.
*/
  unsigned char temp;   
  do
  {
    temp=ER5517.LCD_StatusRead();
  }while(temp&0x08);

}
//[90h]=========================================================================
void ER5517Basic::Pattern_Format_8X8(void)
{ 
/*
Pattern Format
0 : 8X8
1 : 16X16
*/
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x90);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb0 ;
  ER5517.LCD_DataWrite(temp);
} 
//[90h]=========================================================================
void ER5517Basic::Pattern_Format_16X16(void)
{ 
/*
Pattern Format
0 : 8X8
1 : 16X16
*/
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x90);
    temp = ER5517.LCD_DataRead();
    temp |= cSetb0 ;
    ER5517.LCD_DataWrite(temp);
} 

//[91h]=========================================================================
void ER5517Basic::BTE_ROP_Code(unsigned char setx)
{ 
/*
BTE ROP Code[Bit7:4]
  
0000 : 0(Blackness)
0001 : ~S0.~S1 or ~ ( S0+S1 )
0010 : ~S0.S1
0011 : ~S0
0100 : S0.~S1
0101 : ~S1
0110 : S0^S1
0111 : ~S0+~S1 or ~ ( S0.S1 )
1000 : S0.S1
1001 : ~ ( S0^S1 )
1010 : S1
1011 : ~S0+S1
1100 : S0
1101 : S0+~S1
1110 : S0+S1
1111 : 1 ( Whiteness )
*/
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x91);
    temp = ER5517.LCD_DataRead();
    temp &= 0x0f ;
    temp |= (setx<<4);
    ER5517.LCD_DataWrite(temp);
}
  
//[91h]=========================================================================
void ER5517Basic::BTE_Operation_Code(unsigned char setx)
{ 
/*
BTE Operation Code[Bit3:0]
  
0000 : MPU Write BTE with ROP.
0001 : MPU Read BTE w/o ROP.
0010 : Memory copy (move) BTE in positive direction with ROP.
0011 : Memory copy (move) BTE in negative direction with ROP.
0100 : MPU Transparent Write BTE. (w/o ROP.)
0101 : Transparent Memory copy (move) BTE in positive direction (w/o ROP.)
0110 : Pattern Fill with ROP.
0111 : Pattern Fill with key-chroma
1000 : Color Expansion
1001 : Color Expansion with transparency
1010 : Move BTE in positive direction with Alpha blending
1011 : MPU Write BTE with Alpha blending
1100 : Solid Fill
1101 : Reserved
1110 : Reserved
1111 : Reserved
*/
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x91);
    temp = ER5517.LCD_DataRead();
    temp &= 0xf0 ;
    temp |= setx ;
    ER5517.LCD_DataWrite(temp);

}
//[92h]=========================================================================
void ER5517Basic::BTE_S0_Color_8bpp(void)
{ 
/*
S0 Color Depth
00 : 256 Color
01 : 64k Color
1x : 16M Color
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb6 ;
    temp &= cClrb5 ;
    ER5517.LCD_DataWrite(temp);
} 
//[92h]=========================================================================
void ER5517Basic::BTE_S0_Color_16bpp(void)
{ 
/*
S0 Color Depth
00 : 256 Color
01 : 64k Color
1x : 16M Color
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb6 ;
    temp |= cSetb5 ;
    ER5517.LCD_DataWrite(temp);

} 
//[92h]=========================================================================
void ER5517Basic::BTE_S0_Color_24bpp(void)
{ 
/*
S0 Color Depth
00 : 256 Color
01 : 64k Color
1x : 16M Color
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp |= cSetb6 ;
    //temp |= cSetb5 ;
    ER5517.LCD_DataWrite(temp);
}
//[92h]=========================================================================
void ER5517Basic::BTE_S1_Color_8bpp(void)
{ 
/*
S1 Color Depth
000 : 256 Color
001 : 64k Color
010 : 16M Color
011 : Constant Color
100 : 8 bit pixel alpha blending
101 : 16 bit pixel alpha blending
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb4 ;
    temp &= cClrb3 ;
    temp &= cClrb2 ;
    ER5517.LCD_DataWrite(temp);
} 
//[92h]=========================================================================
void ER5517Basic::BTE_S1_Color_16bpp(void)
{ 
/*
S1 Color Depth
000 : 256 Color
001 : 64k Color
010 : 16M Color
011 : Constant Color
100 : 8 bit pixel alpha blending
101 : 16 bit pixel alpha blending
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb4 ;
    temp &= cClrb3 ;
    temp |= cSetb2 ;
    ER5517.LCD_DataWrite(temp);

}
//[92h]=========================================================================
void ER5517Basic::BTE_S1_Color_24bpp(void)
{ 
/*
S1 Color Depth
000 : 256 Color
001 : 64k Color
010 : 16M Color
011 : Constant Color
100 : 8 bit pixel alpha blending
101 : 16 bit pixel alpha blending
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb4 ;
    temp |= cSetb3 ;
    temp &= cClrb2 ;
    ER5517.LCD_DataWrite(temp);
}

//[92h]=========================================================================
void ER5517Basic::BTE_S1_Color_Constant(void)
{ 
/*
S1 Color Depth
000 : 256 Color
001 : 64k Color
010 : 16M Color
011 : Constant Color
100 : 8 bit pixel alpha blending
101 : 16 bit pixel alpha blending
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb4 ;
    temp |= cSetb3 ;
    temp |= cSetb2 ;
    ER5517.LCD_DataWrite(temp);
}



//[92h]=========================================================================
void ER5517Basic::BTE_S1_Color_8bit_Alpha(void)
{ 
/*
S1 Color Depth
000 : 256 Color
001 : 64k Color
010 : 16M Color
011 : Constant Color
100 : 8 bit pixel alpha blending
101 : 16 bit pixel alpha blending
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp |= cSetb4 ;
    temp &= cClrb3 ;
    temp &= cClrb2 ;
    ER5517.LCD_DataWrite(temp);
}

//[92h]=========================================================================
void ER5517Basic::BTE_S1_Color_16bit_Alpha(void)
{ 
/*
S1 Color Depth
000 : 256 Color
001 : 64k Color
010 : 16M Color
011 : Constant Color
100 : 8 bit pixel alpha blending
101 : 16 bit pixel alpha blending
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp |= cSetb4 ;
    temp &= cClrb3 ;
    temp |= cSetb2 ;
    ER5517.LCD_DataWrite(temp);
}

//[92h]=========================================================================
void ER5517Basic::BTE_Destination_Color_8bpp(void)
{ 
/*
Destination Color Depth
00 : 256 Color
01 : 64k Color
1x : 16M Color
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb1 ;
    temp &= cClrb0 ;
    ER5517.LCD_DataWrite(temp);
} 
//[92h]=========================================================================
void ER5517Basic::BTE_Destination_Color_16bpp(void)
{ 
/*
Destination Color Depth
00 : 256 Color
01 : 64k Color
1x : 16M Color
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp &= cClrb1 ;
    temp |= cSetb0 ;
    ER5517.LCD_DataWrite(temp);

} 
//[92h]=========================================================================
void ER5517Basic::BTE_Destination_Color_24bpp(void)
{ 
/*
Destination Color Depth
00 : 256 Color
10 : 64k Color
1x : 16M Color
*/  
    unsigned char temp;
    ER5517.LCD_CmdWrite(0x92);
    temp = ER5517.LCD_DataRead();
    temp |= cSetb1 ;
    //temp |= cSetb0 ;
    ER5517.LCD_DataWrite(temp);
}


//[93h][94h][95h][96h]=========================================================================
void ER5517Basic::BTE_S0_Memory_Start_Address(unsigned long Addr)  
{
/*
[93h] BTE S0 Memory Start Address [7:0]
[94h] BTE S0 Memory Start Address [15:8]
[95h] BTE S0 Memory Start Address [23:16]
[96h] BTE S0 Memory Start Address [31:24]
Bit [1:0] tie to ��0�� internally.
*/
  ER5517.LCD_RegisterWrite(0x93,Addr);
  ER5517.LCD_RegisterWrite(0x94,Addr>>8);
  ER5517.LCD_RegisterWrite(0x95,Addr>>16);
  ER5517.LCD_RegisterWrite(0x96,Addr>>24);
}


//[97h][98h]=========================================================================
void ER5517Basic::BTE_S0_Image_Width(unsigned short WX)  
{
/*
[97h] BTE S0 Image Width [7:0]
[98h] BTE S0 Image Width [12:8]
Unit: Pixel.
Bit [1:0] tie to ��0�� internally.
*/
  ER5517.LCD_RegisterWrite(0x97,WX);
  ER5517.LCD_RegisterWrite(0x98,WX>>8);
}


//[99h][9Ah][9Bh][9Ch]=========================================================================
void ER5517Basic::BTE_S0_Window_Start_XY(unsigned short WX,unsigned short HY)  
{
/*
[99h] BTE S0 Window Upper-Left corner X-coordination [7:0]
[9Ah] BTE S0 Window Upper-Left corner X-coordination [12:8]
[9Bh] BTE S0 Window Upper-Left corner Y-coordination [7:0]
[9Ch] BTE S0 Window Upper-Left corner Y-coordination [12:8]
*/
  ER5517.LCD_RegisterWrite(0x99,WX);
  ER5517.LCD_RegisterWrite(0x9A,WX>>8);

  ER5517.LCD_RegisterWrite(0x9B,HY);
  ER5517.LCD_RegisterWrite(0x9C,HY>>8);
}




//[9Dh][9Eh][9Fh][A0h]=========================================================================
void ER5517Basic::BTE_S1_Memory_Start_Address(unsigned long Addr)  
{
/*
[9Dh] BTE S1 Memory Start Address [7:0]
[9Eh] BTE S1 Memory Start Address [15:8]
[9Fh] BTE S1 Memory Start Address [23:16]
[A0h] BTE S1 Memory Start Address [31:24]
Bit [1:0] tie to ��0�� internally.
*/
  ER5517.LCD_RegisterWrite(0x9D,Addr);
  ER5517.LCD_RegisterWrite(0x9E,Addr>>8);
  ER5517.LCD_RegisterWrite(0x9F,Addr>>16);
  ER5517.LCD_RegisterWrite(0xA0,Addr>>24);
}


//Input data format:R3G3B2
void ER5517Basic::S1_Constant_color_256(unsigned char temp)
{
    ER5517.LCD_CmdWrite(0x9D);
    ER5517.LCD_DataWrite(temp);

    ER5517.LCD_CmdWrite(0x9E);
    ER5517.LCD_DataWrite(temp<<3);

    ER5517.LCD_CmdWrite(0x9F);
    ER5517.LCD_DataWrite(temp<<6);
}

//Input data format:R5G6B6
void ER5517Basic::S1_Constant_color_65k(unsigned short temp)
{
    ER5517.LCD_CmdWrite(0x9D);
    ER5517.LCD_DataWrite(temp>>8);

    ER5517.LCD_CmdWrite(0x9E);
    ER5517.LCD_DataWrite(temp>>3);

    ER5517.LCD_CmdWrite(0x9F);
    ER5517.LCD_DataWrite(temp<<3);
}

//Input data format:R8G8B8
void ER5517Basic::S1_Constant_color_16M(unsigned long temp)
{
    ER5517.LCD_CmdWrite(0x9D);
    ER5517.LCD_DataWrite(temp>>16);

    ER5517.LCD_CmdWrite(0x9E);
    ER5517.LCD_DataWrite(temp>>8);

    ER5517.LCD_CmdWrite(0x9F);
    ER5517.LCD_DataWrite(temp);
}




//[A1h][A2h]=========================================================================
void ER5517Basic::BTE_S1_Image_Width(unsigned short WX)  
{
/*
[A1h] BTE S1 Image Width [7:0]
[A2h] BTE S1 Image Width [12:8]
Unit: Pixel.
Bit [1:0] tie to ��0�� internally.
*/
  ER5517.LCD_RegisterWrite(0xA1,WX);
  ER5517.LCD_RegisterWrite(0xA2,WX>>8);
}


//[A3h][A4h][A5h][A6h]=========================================================================
void ER5517Basic::BTE_S1_Window_Start_XY(unsigned short WX,unsigned short HY)  
{
/*
[A3h] BTE S1 Window Upper-Left corner X-coordination [7:0]
[A4h] BTE S1 Window Upper-Left corner X-coordination [12:8]
[A5h] BTE S1 Window Upper-Left corner Y-coordination [7:0]
[A6h] BTE S1 Window Upper-Left corner Y-coordination [12:8]
*/
  ER5517.LCD_RegisterWrite(0xA3,WX);
  ER5517.LCD_RegisterWrite(0xA4,WX>>8);

  ER5517.LCD_RegisterWrite(0xA5,HY);
  ER5517.LCD_RegisterWrite(0xA6,HY>>8);
}




//[A7h][A8h][A9h][AAh]=========================================================================
void ER5517Basic::BTE_Destination_Memory_Start_Address(unsigned long Addr) 
{
/*
[A7h] BTE Destination Memory Start Address [7:0]
[A8h] BTE Destination Memory Start Address [15:8]
[A9h] BTE Destination Memory Start Address [23:16]
[AAh] BTE Destination Memory Start Address [31:24]
Bit [1:0] tie to ��0�� internally.
*/
  ER5517.LCD_RegisterWrite(0xA7,Addr);
  ER5517.LCD_RegisterWrite(0xA8,Addr>>8);
  ER5517.LCD_RegisterWrite(0xA9,Addr>>16);
  ER5517.LCD_RegisterWrite(0xAA,Addr>>24);
}


//[ABh][ACh]=========================================================================
void ER5517Basic::BTE_Destination_Image_Width(unsigned short WX) 
{
/*
[ABh] BTE Destination Image Width [7:0]
[ACh] BTE Destination Image Width [12:8]
Unit: Pixel.
Bit [1:0] tie to ��0�� internally.
*/
  ER5517.LCD_RegisterWrite(0xAB,WX);
  ER5517.LCD_RegisterWrite(0xAC,WX>>8);
}


//[ADh][AEh][AFh][B0h]=========================================================================
void ER5517Basic::BTE_Destination_Window_Start_XY(unsigned short WX,unsigned short HY) 
{
/*
[ADh] BTE Destination Window Upper-Left corner X-coordination [7:0]
[AEh] BTE Destination Window Upper-Left corner X-coordination [12:8]
[AFh] BTE Destination Window Upper-Left corner Y-coordination [7:0]
[B0h] BTE Destination Window Upper-Left corner Y-coordination [12:8]
*/
  ER5517.LCD_RegisterWrite(0xAD,WX);
  ER5517.LCD_RegisterWrite(0xAE,WX>>8);

  ER5517.LCD_RegisterWrite(0xAF,HY);
  ER5517.LCD_RegisterWrite(0xB0,HY>>8);
}


//[B1h][B2h][B3h][B4h]===============================================================

void ER5517Basic::BTE_Window_Size(unsigned short WX, unsigned short WY)

{
/*
[B1h] BTE Window Width [7:0]
[B2h] BTE Window Width [12:8]

[B3h] BTE Window Height [7:0]
[B4h] BTE Window Height [12:8]
*/
        ER5517.LCD_RegisterWrite(0xB1,WX);
        ER5517.LCD_RegisterWrite(0xB2,WX>>8);
  
      ER5517.LCD_RegisterWrite(0xB3,WY);
        ER5517.LCD_RegisterWrite(0xB4,WY>>8);
}

//[B5h]=========================================================================
void ER5517Basic::BTE_Alpha_Blending_Effect(unsigned char temp)
{ 
/*
Window Alpha Blending effect for S0 & S1
The value of alpha in the color code ranges from 0.0 to 1.0,
where 0.0 represents a fully transparent color, and 1.0
represents a fully opaque color.
00h: 0
01h: 1/32
02h: 2/32
:
1Eh: 30/32
1Fh: 31/32
2Xh: 1
Output Effect = (S0 image x (1 - alpha setting value)) + (S1 image x alpha setting value)
*/
    ER5517.LCD_CmdWrite(0xB5);
  ER5517.LCD_DataWrite(temp);  
}


//[B6h]=========================================================================
void ER5517Basic::Start_SFI_DMA(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB6);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}

void ER5517Basic::Check_Busy_SFI_DMA(void)
{
  ER5517.LCD_CmdWrite(0xB6);
  do
  {   
  }while((ER5517.LCD_DataRead()&0x01)==0x01);
}


//[B7h]=========================================================================
void ER5517Basic::Select_SFI_0(void)
{
/*[bit7]
Serial Flash/ROM I/F # Select
0: Serial Flash/ROM 0 I/F is selected.
1: Serial Flash/ROM 1 I/F is selected.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb7;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_1(void)
{
/*[bit7]
Serial Flash/ROM I/F # Select
0: Serial Flash/ROM 0 I/F is selected.
1: Serial Flash/ROM 1 I/F is selected.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb7;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_Font_Mode(void)
{
/*[bit6]
Serial Flash /ROM Access Mode
0: Font mode �V for external cgrom
1: DMA mode �V for cgram , pattern , bootstart image or osd
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_DMA_Mode(void)
{
/*[bit6]
Serial Flash /ROM Access Mode
0: Font mode �V for external cgrom
1: DMA mode �V for cgram , pattern , bootstart image or osd
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_24bit_Address(void)
{
/*[bit5]
Serial Flash/ROM Address Mode
0: 24 bits address mode
1: 32 bits address mode
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb5;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_32bit_Address(void)
{
/*[bit5]
Serial Flash/ROM Address Mode
0: 24 bits address mode
1: 32 bits address mode
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb5;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_Waveform_Mode_0(void)
{
/*[bit4]
Serial Flash/ROM Waveform Mode
Mode 0.
Mode 3.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_Waveform_Mode_3(void)
{
/*[bit4]
Serial Flash/ROM Waveform Mode
Mode 0.
Mode 3.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_0_DummyRead(void)
{
/*[bit3][bit2]
Serial Flash /ROM Read Cycle 0 RW
00b: no dummy cycle mode
01b: 1 dummy cycle mode
10b: 2 dummy cycle mode
11b: 4 dummy cycle mode
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
  temp &= 0xF3;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_8_DummyRead(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
  temp &= 0xF3;
    temp |= cSetb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_16_DummyRead(void)
{

  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
  temp &= 0xF3;
    temp |= cSetb3;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_24_DummyRead(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp |= 0x0c;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_Single_Mode(void)
{
/*[bit1][bit0]
Serial Flash /ROM I/F Data Latch Mode Select
0Xb: Single Mode
10b: Dual Mode 0.
11b: Dual Mode 1.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
  temp &= 0xFC;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_Dual_Mode0(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
  temp &= 0xFC;
    temp |= cSetb1;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Select_SFI_Dual_Mode1(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB7);
  temp = ER5517.LCD_DataRead();
    temp |= 0x03;
  ER5517.LCD_DataWrite(temp);
}

//REG[B8h] SPI master Tx /Rx FIFO Data Register (SPIDR) 
unsigned char ER5517Basic::SPI_Master_FIFO_Data_Put(unsigned char Data)
{
    unsigned char temp;
  ER5517.LCD_CmdWrite(0xB8);
  ER5517.LCD_DataWrite(Data);
  while(Tx_FIFO_Empty_Flag()==0); 
  temp = SPI_Master_FIFO_Data_Get();
  return temp;
}

unsigned char ER5517Basic::SPI_Master_FIFO_Data_Get(void)
{
   unsigned char temp;

  while(Rx_FIFO_Empty_Flag()==1);
  ER5517.LCD_CmdWrite(0xB8);
  temp=ER5517.LCD_DataRead();
  //while(Rx_FIFO_full_flag());
   return temp;
}

//REG[B9h] SPI master Control Register (SPIMCR2) 
void ER5517Basic::Mask_SPI_Master_Interrupt_Flag(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);

} 

void ER5517Basic::Select_nSS_drive_on_xnsfcs0(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb5;
  ER5517.LCD_DataWrite(temp);

}

void ER5517Basic::Select_nSS_drive_on_xnsfcs1(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb5;
  ER5517.LCD_DataWrite(temp);
}

//0: inactive (nSS port will goes high) 
void ER5517Basic::nSS_Inactive(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
//1: active (nSS port will goes low) 
void ER5517Basic::nSS_Active(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb4;
  ER5517.LCD_DataWrite(temp);
}

//Interrupt enable for FIFO overflow error [OVFIRQEN] 
void ER5517Basic::OVFIRQEN_Enable(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb3;
  ER5517.LCD_DataWrite(temp);
}
//Interrupt enable for while Tx FIFO empty & SPI engine/FSM idle
void ER5517Basic::EMTIRQEN_Enable(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb2;
  ER5517.LCD_DataWrite(temp);
}


//At CPOL=0 the base value of the clock is zero   
//o  For CPHA=0, data are read on the clock's rising edge (low->high transition) and 
//data are changed on a falling edge (high->low clock transition). 
//o  For CPHA=1, data are read on the clock's falling edge and data are changed on a 
//rising edge. 

//At CPOL=1 the base value of the clock is one (inversion of CPOL=0)   
//o  For CPHA=0, data are read on clock's falling edge and data are changed on a 
//rising edge. 
//o  For CPHA=1, data are read on clock's rising edge and data are changed on a 
//falling edge.

void ER5517Basic::Reset_CPOL(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb1;
  ER5517.LCD_DataWrite(temp);
}

void ER5517Basic::Set_CPOL(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb1;
  ER5517.LCD_DataWrite(temp);
}


void ER5517Basic::Reset_CPHA(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb0;
  ER5517.LCD_DataWrite(temp);
}

void ER5517Basic::Set_CPHA(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xB9);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}


//REG[BAh] SPI master Status Register (SPIMSR) 
unsigned char ER5517Basic::Tx_FIFO_Empty_Flag(void)
{
  ER5517.LCD_CmdWrite(0xBA);
  if((ER5517.LCD_DataRead()&0x80)==0x80)
  return 1;
  else
  return 0;
}

unsigned char ER5517Basic::Tx_FIFO_Full_Flag(void)
{
  ER5517.LCD_CmdWrite(0xBA);
  if((ER5517.LCD_DataRead()&0x40)==0x40)
  return 1;
  else
  return 0;
} 

unsigned char ER5517Basic::Rx_FIFO_Empty_Flag(void)
{
  ER5517.LCD_CmdWrite(0xBA);
  if((ER5517.LCD_DataRead()&0x20)==0x20)
  return 1;
  else
  return 0;
} 

unsigned char ER5517Basic::Rx_FIFO_full_flag(void)
{
   ER5517.LCD_CmdWrite(0xBA);
   if((ER5517.LCD_DataRead()&0x10)==0x10)
   return 1;
   else
   return 0;
} 

unsigned char ER5517Basic::OVFI_Flag(void)
{
   ER5517.LCD_CmdWrite(0xBA);
   if((ER5517.LCD_DataRead()&0x08)==0x08)
   return 1;
   else
   return 0;
}

void ER5517Basic::Clear_OVFI_Flag(void)
{
   unsigned char temp;
   ER5517.LCD_CmdWrite(0xBA);
   temp = ER5517.LCD_DataRead();
   temp |= cSetb3;
   ER5517.LCD_DataWrite(temp);
}

unsigned char ER5517Basic::EMTI_Flag(void)
{
   ER5517.LCD_CmdWrite(0xBA);
   if((ER5517.LCD_DataRead()&0x04)==0x04)
   return 1;
   else
   return 0;
}

void ER5517Basic::Clear_EMTI_Flag(void)
{
   unsigned char temp;
   ER5517.LCD_CmdWrite(0xBA);
   temp = ER5517.LCD_DataRead();
   temp |= cSetb2;
   ER5517.LCD_DataWrite(temp);
}


//REG[BB] SPI Clock period (SPIDIV) 
void ER5517Basic::SPI_Clock_Period(unsigned char temp)
{
   ER5517.LCD_CmdWrite(0xBB);
   ER5517.LCD_DataWrite(temp);
} 

//[BCh][BDh][BEh][BFh]=========================================================================
void ER5517Basic::SFI_DMA_Source_Start_Address(unsigned long Addr)
{
/*
DMA Source START ADDRESS
This bits index serial flash address [7:0][15:8][23:16][31:24]
*/
  ER5517.LCD_CmdWrite(0xBC);
  ER5517.LCD_DataWrite(Addr);
  ER5517.LCD_CmdWrite(0xBD);
  ER5517.LCD_DataWrite(Addr>>8);
  ER5517.LCD_CmdWrite(0xBE);
  ER5517.LCD_DataWrite(Addr>>16);
  ER5517.LCD_CmdWrite(0xBF);
  ER5517.LCD_DataWrite(Addr>>24);
}
//[C0h][C1h][C2h][C3h]=========================================================================
void ER5517Basic::SFI_DMA_Destination_Start_Address(unsigned long Addr)
{
/*
DMA Destination START ADDRESS 
[1:0]Fix at 0
This bits index SDRAM address [7:0][15:8][23:16][31:24]
*/
  ER5517.LCD_CmdWrite(0xC0);
  ER5517.LCD_DataWrite(Addr);
  ER5517.LCD_CmdWrite(0xC1);
  ER5517.LCD_DataWrite(Addr>>8);
  ER5517.LCD_CmdWrite(0xC2);
  ER5517.LCD_DataWrite(Addr>>16);
  ER5517.LCD_CmdWrite(0xC3);
  ER5517.LCD_DataWrite(Addr>>24);
}
//[C0h][C1h][C2h][C3h]=========================================================================
void ER5517Basic::SFI_DMA_Destination_Upper_Left_Corner(unsigned short WX,unsigned short HY)
{
/*
C0h
This register defines DMA Destination Window Upper-Left corner 
X-coordination [7:0] on Canvas area. 
When REG DMACR bit 1 = 1 (Block Mode) 
This register defines Destination address [7:2] in SDRAM. 
C1h
When REG DMACR bit 1 = 0 (Linear Mode) 
This register defines DMA Destination Window Upper-Left corner 
X-coordination [12:8] on Canvas area. 
When REG DMACR bit 1 = 1 (Block Mode) 
This register defines Destination address [15:8] in SDRAM.
C2h
When REG DMACR bit 1 = 0 (Linear Mode) 
This register defines DMA Destination Window Upper-Left corner
Y-coordination [7:0] on Canvas area. 
When REG DMACR bit 1 = 1 (Block Mode) 
This register defines Destination address [23:16] in SDRAM. 
C3h
When REG DMACR bit 1 = 0 (Linear Mode) 
This register defines DMA Destination Window Upper-Left corner 
Y-coordination [12:8] on Canvas area. 
When REG DMACR bit 1 = 1 (Block Mode) 
This register defines Destination address [31:24] in SDRAM. 
*/
 
  ER5517.LCD_CmdWrite(0xC0);
  ER5517.LCD_DataWrite(WX);
  ER5517.LCD_CmdWrite(0xC1);
  ER5517.LCD_DataWrite(WX>>8);
 
  ER5517.LCD_CmdWrite(0xC2);
  ER5517.LCD_DataWrite(HY);
  ER5517.LCD_CmdWrite(0xC3);
  ER5517.LCD_DataWrite(HY>>8);
}



//[C6h][C7h][C8h][C9h]=========================================================================
void ER5517Basic::SFI_DMA_Transfer_Number(unsigned long Addr)
{
/*
Unit : Pixel
When REG DMACR bit 1 = 0 (Linear Mode)
DMA Transfer Number [7:0][15:8][23:16][31:24]

When REG DMACR bit 1 = 1 (Block Mode)
DMA Block Width [7:0][15:8]
DMA Block HIGH[7:0][15:8]
*/
  ER5517.LCD_CmdWrite(0xC6);
  ER5517.LCD_DataWrite(Addr);
  ER5517.LCD_CmdWrite(0xC7);
  ER5517.LCD_DataWrite(Addr>>8);
  ER5517.LCD_CmdWrite(0xC8);
  ER5517.LCD_DataWrite(Addr>>16);
  ER5517.LCD_CmdWrite(0xC9);
  ER5517.LCD_DataWrite(Addr>>24);
}
void ER5517Basic::SFI_DMA_Transfer_Width_Height(unsigned short WX,unsigned short HY)
{
/*
When REG DMACR bit 1 = 0 (Linear Mode)
DMA Transfer Number [7:0][15:8][23:16][31:24]

When REG DMACR bit 1 = 1 (Block Mode)
DMA Block Width [7:0][15:8]
DMA Block HIGH[7:0][15:8]
*/
  ER5517.LCD_CmdWrite(0xC6);
  ER5517.LCD_DataWrite(WX);
  ER5517.LCD_CmdWrite(0xC7);
  ER5517.LCD_DataWrite(WX>>8);

  ER5517.LCD_CmdWrite(0xC8);
  ER5517.LCD_DataWrite(HY);
  ER5517.LCD_CmdWrite(0xC9);
  ER5517.LCD_DataWrite(HY>>8);
}
//[CAh][CBh]=========================================================================
void ER5517Basic::SFI_DMA_Source_Width(unsigned short WX)
{
/*
DMA Source Picture Width [7:0][12:8]
Unit: pixel
*/
  ER5517.LCD_CmdWrite(0xCA);
  ER5517.LCD_DataWrite(WX);
  ER5517.LCD_CmdWrite(0xCB);
  ER5517.LCD_DataWrite(WX>>8);
}

//[CCh]=========================================================================

void ER5517Basic::Font_Select_UserDefine_Mode(void)
{
/*[bit7-6]
User-defined Font /CGROM Font Selection Bit in Text Mode
00 : Internal CGROM
01 : Genitop serial flash
10 : User-defined Font
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb7;
  temp &= cClrb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::CGROM_Select_Internal_CGROM(void)
{
/*[bit7-6]
User-defined Font /CGROM Font Selection Bit in Text Mode
00 : Internal CGROM
01 : Genitop serial flash
10 : User-defined Font
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb7;
    temp &= cClrb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::CGROM_Select_Genitop_FontROM(void)
{
/*[bit7-6]
User-defined Font /CGROM Font Selection Bit in Text Mode
00 : Internal CGROM
01 : Genitop serial flash
10 : User-defined Font
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb7;
    temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Select_8x16_16x16(void)
{
/*[bit5-4]
Font Height Setting
00b : 8x16 / 16x16.
01b : 12x24 / 24x24.
10b : 16x32 / 32x32.
*** User-defined Font width is decided by font code. Genitop
serial flash��s font width is decided by font code or GT Font ROM
control register.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb5;
    temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Select_12x24_24x24(void)
{
/*[bit5-4]
Font Height Setting
00b : 8x16 / 16x16.
01b : 12x24 / 24x24.
10b : 16x32 / 32x32.
*** User-defined Font width is decided by font code. Genitop
serial flash��s font width is decided by font code or GT Font ROM
control register.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb5;
    temp |= cSetb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Select_16x32_32x32(void)
{
/*[bit5-4]
Font Height Setting
00b : 8x16 / 16x16.
01b : 12x24 / 24x24.
10b : 16x32 / 32x32.
*** User-defined Font width is decided by font code. Genitop
serial flash��s font width is decided by font code or GT Font ROM
control register.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb5;
    temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Internal_CGROM_Select_ISOIEC8859_1(void)
{
/*
Font Selection for internal CGROM
When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the
8x16 character sets with the standard coding of ISO/IEC 8859-1~4, 
which supports English and most of European country languages.
00b : ISO/IEC 8859-1.
01b : ISO/IEC 8859-2.
10b : ISO/IEC 8859-3.
11b : ISO/IEC 8859-4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb1;
    temp &= cClrb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Internal_CGROM_Select_ISOIEC8859_2(void)
{
/*
Font Selection for internal CGROM
When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the
8x16 character sets with the standard coding of ISO/IEC 8859-1~4, 
which supports English and most of European country languages.
00b : ISO/IEC 8859-1.
01b : ISO/IEC 8859-2.
10b : ISO/IEC 8859-3.
11b : ISO/IEC 8859-4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb1;
    temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Internal_CGROM_Select_ISOIEC8859_3(void)
{
/*
Font Selection for internal CGROM
When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the
8x16 character sets with the standard coding of ISO/IEC 8859-1~4, 
which supports English and most of European country languages.
00b : ISO/IEC 8859-1.
01b : ISO/IEC 8859-2.
10b : ISO/IEC 8859-3.
11b : ISO/IEC 8859-4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb1;
    temp &= cClrb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Internal_CGROM_Select_ISOIEC8859_4(void)
{
/*
Font Selection for internal CGROM
When FNCR0 B7 = 0 and B5 = 0, Internal CGROM supports the
8x16 character sets with the standard coding of ISO/IEC 8859-1~4, 
which supports English and most of European country languages.
00b : ISO/IEC 8859-1.
01b : ISO/IEC 8859-2.
10b : ISO/IEC 8859-3.
11b : ISO/IEC 8859-4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCC);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb1;
    temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}
//[CDh]=========================================================================
void ER5517Basic::Enable_Font_Alignment(void)
{
/*
Full Alignment Selection Bit
0 : Full alignment disable.
1 : Full alignment enable.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb7;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Disable_Font_Alignment(void)
{
/*
Full Alignment Selection Bit
0 : Full alignment disable.
1 : Full alignment enable.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb7;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Background_select_Transparency(void)
{
/*
Font Transparency
0 : Font with background color.
1 : Font with background transparency.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Background_select_Color(void)
{
/*
Font Transparency
0 : Font with background color.
1 : Font with background transparency.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb6;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_0_degree(void)
{
/*
Font Rotation
0 : Normal
Text direction from left to right then from top to bottom
1 : Counterclockwise 90 degree & horizontal flip
Text direction from top to bottom then from left to right
(it should accommodate with set VDIR as 1)
This attribute can be changed only when previous font write
finished (core_busy = 0)
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_90_degree(void)
{
/*
Font Rotation
0 : Normal
Text direction from left to right then from top to bottom
1 : Counterclockwise 90 degree & horizontal flip
Text direction from top to bottom then from left to right
(it should accommodate with set VDIR as 1)
This attribute can be changed only when previous font write
finished (core_busy = 0)
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb4;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Width_X1(void)
{
/*
Horizontal Font Enlargement
00b : X1.
01b : X2.
10b : X3.
11b : X4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb3;
    temp &= cClrb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Width_X2(void)
{
/*
Horizontal Font Enlargement
00b : X1.
01b : X2.
10b : X3.
11b : X4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb3;
    temp |= cSetb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Width_X3(void)
{
/*
Horizontal Font Enlargement
00b : X1.
01b : X2.
10b : X3.
11b : X4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb3;
    temp &= cClrb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Width_X4(void)
{
/*
Horizontal Font Enlargement
00b : X1.
01b : X2.
10b : X3.
11b : X4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb3;
    temp |= cSetb2;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Height_X1(void)
{
/*
Vertical Font Enlargement
00b : X1.
01b : X2.
10b : X3.
11b : X4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb1;
    temp &= cClrb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Height_X2(void)
{
/*
Vertical Font Enlargement
00b : X1.
01b : X2.
10b : X3.
11b : X4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp &= cClrb1;
    temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Height_X3(void)
{
/*
Vertical Font Enlargement
00b : X1.
01b : X2.
10b : X3.
11b : X4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb1;
    temp &= cClrb0;
  ER5517.LCD_DataWrite(temp);
}
void ER5517Basic::Font_Height_X4(void)
{
/*
Vertical Font Enlargement
00b : X1.
01b : X2.
10b : X3.
11b : X4.
*/
  unsigned char temp;
  ER5517.LCD_CmdWrite(0xCD);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb1;
    temp |= cSetb0;
  ER5517.LCD_DataWrite(temp);
}



//[D0h]=========================================================================
void ER5517Basic::Font_Line_Distance(unsigned char temp)
{
/*[bit4-0]
Font Line Distance Setting
Setting the font character line distance when setting memory font
write cursor auto move. (Unit: pixel)
*/
  ER5517.LCD_CmdWrite(0xD0);
  ER5517.LCD_DataWrite(temp);
}
//[D1h]=========================================================================
void ER5517Basic::Set_Font_to_Font_Width(unsigned char temp)
{
/*[bit5-0]
Font to Font Width Setting (Unit: pixel)
*/
  ER5517.LCD_CmdWrite(0xD1);
  ER5517.LCD_DataWrite(temp);
}


//[DBh]~[DEh]=========================================================================
void ER5517Basic::CGRAM_Start_address(unsigned long Addr)
{
/*
CGRAM START ADDRESS [31:0]
*/	 
  ER5517.LCD_CmdWrite(0xDB);
  ER5517.LCD_DataWrite(Addr);
  ER5517.LCD_CmdWrite(0xDC);
  ER5517.LCD_DataWrite(Addr>>8);
  ER5517.LCD_CmdWrite(0xDD);
  ER5517.LCD_DataWrite(Addr>>16);
  ER5517.LCD_CmdWrite(0xDE);
  ER5517.LCD_DataWrite(Addr>>24);
}



void ER5517Basic::MemWrite_Left_Right_Top_Down(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x02);
  temp = ER5517.LCD_DataRead();
  temp &= cClrb2;
  temp &= cClrb1;
  ER5517.LCD_DataWrite(temp);
}

void ER5517Basic::System_Check_Temp(void)
{
  unsigned char i=0,j=0;
  unsigned char temp=0;
  unsigned char system_ok=0;
  do
  {
    j = ER5517.LCD_StatusRead();
    if((j&0x02)==0x00)    
    {
      delay(2);                  //MCU too fast, necessary
      ER5517.LCD_CmdWrite(0x01);
      delay(2);                  //MCU too fast, necessary
      temp = ER5517.LCD_DataRead();
      if((temp & 0x80) == 0x80)       //Check CCR register's PLL is ready or not
      {
        system_ok=1;
        i=0;
      }
      else
      {
        delay(2); //MCU too fast, necessary
        ER5517.LCD_CmdWrite(0x01);
        delay(2); //MCU too fast, necessary
        ER5517.LCD_DataWrite(0x80);
      }
    }
    else
    {
      system_ok=0;
      i++;
    }
    if(system_ok==0 && i==5)
    {
      ER5517.HW_Reset(); //note1
      i=0;
    }
  }while(system_ok==0);
}

void ER5517Basic::PLL_Initial(void) 
{

  	unsigned short lpllOD_sclk, lpllOD_cclk, lpllOD_mclk;
	unsigned short lpllR_sclk, lpllR_cclk, lpllR_mclk;
	unsigned short lpllN_sclk, lpllN_cclk, lpllN_mclk;

	//Fout = Fin*(N/R)/OD
	//Fout = 10*N/(2*5) = N
	lpllOD_sclk = 2;
	lpllOD_cclk = 2;
	lpllOD_mclk = 2;
	lpllR_sclk  = 5;
	lpllR_cclk  = 5;
	lpllR_mclk  = 5;
	lpllN_sclk  = 20;   //  frequency
	lpllN_cclk  = 100;    // Core CLK:100
	lpllN_mclk  = 100;    // SRAM CLK:100
	  
	ER5517.LCD_CmdWrite(0x05);
	ER5517.LCD_DataWrite((lpllOD_sclk<<6) | (lpllR_sclk<<1) | ((lpllN_sclk>>8)&0x1));
	ER5517.LCD_CmdWrite(0x07);
	ER5517.LCD_DataWrite((lpllOD_mclk<<6) | (lpllR_mclk<<1) | ((lpllN_mclk>>8)&0x1));
	ER5517.LCD_CmdWrite(0x09);
	ER5517.LCD_DataWrite((lpllOD_cclk<<6) | (lpllR_cclk<<1) | ((lpllN_cclk>>8)&0x1));

	ER5517.LCD_CmdWrite(0x06);
	ER5517.LCD_DataWrite(lpllN_sclk);
	ER5517.LCD_CmdWrite(0x08);
	ER5517.LCD_DataWrite(lpllN_mclk);
	ER5517.LCD_CmdWrite(0x0a);
	ER5517.LCD_DataWrite(lpllN_cclk);

	ER5517.LCD_CmdWrite(0x00);
	delayMicroseconds(1);
	ER5517.LCD_DataWrite(0x80);
	delay(1);





    /*  // ==== [SW_(1)]  PLL
    #define OSC_FREQ     10	  // crystal clcok
    #define DRAM_FREQ    100  // SDRAM clock frequency, unti: MHz		  
    #define CORE_FREQ    100  // Core (system) clock frequency, unit: MHz 
    #define SCAN_FREQ     50 // Panel Scan clock frequency, unit: MHz	 


 // Set pixel clock
  if(SCAN_FREQ>=63)        //&&(SCAN_FREQ<=100))
  {
	ER5517.LCD_CmdWrite(0x05);    //PLL Divided by 4
	ER5517.LCD_DataWrite(0x04);
	ER5517.LCD_CmdWrite(0x06);
	ER5517.LCD_DataWrite((SCAN_FREQ*4/OSC_FREQ)-1);
  }
  if((SCAN_FREQ>=32)&&(SCAN_FREQ<=62))
  {           
	ER5517.LCD_CmdWrite(0x05);    //PLL Divided by 8
	ER5517.LCD_DataWrite(0x06);
	ER5517.LCD_CmdWrite(0x06);
	ER5517.LCD_DataWrite((SCAN_FREQ*8/OSC_FREQ)-1);
  }
  if((SCAN_FREQ>=16)&&(SCAN_FREQ<=31))
  {           
	ER5517.LCD_CmdWrite(0x05);    //PLL Divided by 16
	ER5517.LCD_DataWrite(0x16);
	ER5517.LCD_CmdWrite(0x06);
	ER5517.LCD_DataWrite((SCAN_FREQ*16/OSC_FREQ)-1);
  }
  if((SCAN_FREQ>=8)&&(SCAN_FREQ<=15))
  {
	ER5517.LCD_CmdWrite(0x05);    //PLL Divided by 32
	ER5517.LCD_DataWrite(0x26);
	ER5517.LCD_CmdWrite(0x06);
	ER5517.LCD_DataWrite((SCAN_FREQ*32/OSC_FREQ)-1);
  }
  if((SCAN_FREQ>0)&&(SCAN_FREQ<=7))
  {
	ER5517.LCD_CmdWrite(0x05);    //PLL Divided by 64
	ER5517.LCD_DataWrite(0x36);
	ER5517.LCD_CmdWrite(0x06);
	ER5517.LCD_DataWrite((SCAN_FREQ*64/OSC_FREQ)-1);
  }            
 
  
  // Set SDRAM clock
  if(DRAM_FREQ>=125)        //&&(DRAM_FREQ<=166))
  {
	ER5517.LCD_CmdWrite(0x07);    //PLL Divided by 2
	ER5517.LCD_DataWrite(0x02);
	ER5517.LCD_CmdWrite(0x08);
	ER5517.LCD_DataWrite((DRAM_FREQ*2/OSC_FREQ)-1);
  }
  if((DRAM_FREQ>=63)&&(DRAM_FREQ<=124))   //&&(DRAM_FREQ<=166)
  {
	ER5517.LCD_CmdWrite(0x07);    //PLL Divided by 4
	ER5517.LCD_DataWrite(0x04);
	ER5517.LCD_CmdWrite(0x08);
	ER5517.LCD_DataWrite((DRAM_FREQ*4/OSC_FREQ)-1);
  }
  if((DRAM_FREQ>=31)&&(DRAM_FREQ<=62))
  {           
	ER5517.LCD_CmdWrite(0x07);    //PLL Divided by 8
	ER5517.LCD_DataWrite(0x06);
	ER5517.LCD_CmdWrite(0x08);
	ER5517.LCD_DataWrite((DRAM_FREQ*8/OSC_FREQ)-1);
  }
  if(DRAM_FREQ<=30)
  {
	ER5517.LCD_CmdWrite(0x07);    //PLL Divided by 8
	ER5517.LCD_DataWrite(0x06);
	ER5517.LCD_CmdWrite(0x08); //
	ER5517.LCD_DataWrite((30*8/OSC_FREQ)-1);
  }
 

  // Set Core clock
  if(CORE_FREQ>=125)
  {
	ER5517.LCD_CmdWrite(0x09);    //PLL Divided by 2
	ER5517.LCD_DataWrite(0x02);
	ER5517.LCD_CmdWrite(0x0A);
	ER5517.LCD_DataWrite((CORE_FREQ*2/OSC_FREQ)-1);
  }
  if((CORE_FREQ>=63)&&(CORE_FREQ<=124))     
  {
	ER5517.LCD_CmdWrite(0x09);    //PLL Divided by 4
	ER5517.LCD_DataWrite(0x04);
	ER5517.LCD_CmdWrite(0x0A);
	ER5517.LCD_DataWrite((CORE_FREQ*4/OSC_FREQ)-1);
  }
  if((CORE_FREQ>=31)&&(CORE_FREQ<=62))
  {           
	ER5517.LCD_CmdWrite(0x09);    //PLL Divided by 8
	ER5517.LCD_DataWrite(0x06);
	ER5517.LCD_CmdWrite(0x0A);
	ER5517.LCD_DataWrite((CORE_FREQ*8/OSC_FREQ)-1);
  }
  if(CORE_FREQ<=30)
  {
	ER5517.LCD_CmdWrite(0x09);    //PLL Divided by 8
	ER5517.LCD_DataWrite(0x06);
	ER5517.LCD_CmdWrite(0x0A); // 
	ER5517.LCD_DataWrite((30*8/OSC_FREQ)-1);
  }

	ER5517.LCD_CmdWrite(0x01);
	ER5517.LCD_CmdWrite(0x00);
	delay(1);
	ER5517.LCD_CmdWrite(0x80);
	//Enable_PLL();

	delay(1);	//
 */
}


void ER5517Basic::SDRAM_initail(void)
{
  unsigned short sdram_itv;
  
  ER5517.LCD_RegisterWrite(0xe0,0x29);      
  ER5517.LCD_RegisterWrite(0xe1,0x03); //CAS:2=0x02�ACAS:3=0x03
  sdram_itv = (64000000 / 8192) / (1000/60) ;
  sdram_itv-=2;

  ER5517.LCD_RegisterWrite(0xe2,sdram_itv);
  ER5517.LCD_RegisterWrite(0xe3,sdram_itv >>8);
  ER5517.LCD_RegisterWrite(0xe4,0x01);
  ER5517.Check_SDRAM_Ready();
  delay(1);
}
void ER5517Basic::HW_Reset(void)
{
	pinMode(LCM_RESET, OUTPUT);
  digitalWrite(LCM_RESET, LOW);
  delay(100);
  digitalWrite(LCM_RESET, HIGH);
  delay(200);
}

void ER5517Basic::initial(void)
{

    ER5517.PLL_Initial();
  
    ER5517.SDRAM_initail();

//**[01h]**//
    ER5517.TFT_18bit();
  ER5517.Host_Bus_16bit(); //Host bus 16bit
      
//**[02h]**//
  ER5517.RGB_16b_16bpp();
  ER5517.MemWrite_Left_Right_Top_Down(); 
      
//**[03h]**//
  ER5517.Graphic_Mode();
  ER5517.Memory_Select_SDRAM();

  ER5517.HSCAN_L_to_R();     //REG[12h]:from left to right
  ER5517.VSCAN_T_to_B();       //REG[12h]:from top to bottom
  ER5517.PDATA_Set_RGB();        //REG[12h]:Select RGB output

  ER5517.Set_PCLK(LCD_PCLK_Falling_Rising);   //LCD_PCLK_Falling_Rising
  ER5517.Set_HSYNC_Active(LCD_HSYNC_Active_Polarity);
  ER5517.Set_VSYNC_Active(LCD_VSYNC_Active_Polarity);
  ER5517.Set_DE_Active(LCD_DE_Active_Polarity);
 
  ER5517.LCD_HorizontalWidth_VerticalHeight(LCD_XSIZE_TFT ,LCD_YSIZE_TFT);
  ER5517.LCD_Horizontal_Non_Display(LCD_HBPD);                          
  ER5517.LCD_HSYNC_Start_Position(LCD_HFPD);                              
  ER5517.LCD_HSYNC_Pulse_Width(LCD_HSPW);                              
  ER5517.LCD_Vertical_Non_Display(LCD_VBPD);                               
  ER5517.LCD_VSYNC_Start_Position(LCD_VFPD);                               
  ER5517.LCD_VSYNC_Pulse_Width(LCD_VSPW);                              
      
  ER5517.Select_Main_Window_16bpp();

  ER5517.Memory_XY_Mode(); //Block mode (X-Y coordination addressing)
  ER5517.Memory_16bpp_Mode();
  ER5517.Select_Main_Window_16bpp();
}
void ER5517Basic::Display_ON(void)
{
/*  
Display ON/OFF
0b: Display Off.
1b: Display On.
*/
  unsigned char temp;
  
  ER5517.LCD_CmdWrite(0x12);
  temp = ER5517.LCD_DataRead();
  temp |= cSetb6;
  ER5517.LCD_DataWrite(temp);
}

void ER5517Basic::DMA_24bit_Block
(
 unsigned char SCS         // Select SPI : SCS��0       SCS��1
,unsigned char Clk         // SPI Clock = System Clock /{(Clk+1)*2}
,unsigned short X1         // Transfer to SDRAM address:X1
,unsigned short Y1         // Transfer to SDRAM address:Y1
,unsigned short X_W        // DMA data width
,unsigned short Y_H        // DMA data height
,unsigned short P_W        // Picture's width
,unsigned long Addr        // Flash address
)
{
  ER5517.Enable_SFlash_SPI();                            
  if(SCS == 0)  ER5517.Select_SFI_0();                   // Select SPI0
  if(SCS == 1)  ER5517.Select_SFI_1();                   // Select SPI1
	
  ER5517.Memory_XY_Mode();                     
  ER5517.Select_SFI_DMA_Mode();                          // Select SPI DMA mode
  ER5517.SPI_Clock_Period(Clk);                          // Select SPI clock

  ER5517.Goto_Pixel_XY(X1,Y1);                           // Setting the location of memory in the graphic mode
  ER5517.SFI_DMA_Destination_Upper_Left_Corner(X1,Y1);   // DMA destination(SDRAM address)
  ER5517.SFI_DMA_Transfer_Width_Height(X_W,Y_H);         // Setting Block data: width&height
  ER5517.SFI_DMA_Source_Width(P_W);                      // Setting the width of the source data
  ER5517.SFI_DMA_Source_Start_Address(Addr);             // Setting the FLASH address of the source data

  ER5517.Start_SFI_DMA();                                
  ER5517.Check_Busy_SFI_DMA();                        
}


void ER5517Basic::DMA_24bit_Linear
(
 unsigned char SCS             
,unsigned char Clk             
,unsigned long flash_addr     
,unsigned long memory_addr  
,unsigned long data_num      
)
{

  
  ER5517.Enable_SFlash_SPI();                            
  if(SCS == 0)  ER5517.Select_SFI_0();                   // Select SPI0
  if(SCS == 1)  ER5517.Select_SFI_1();                   // Select SPI1
	
  ER5517.Memory_Linear_Mode();                   
  ER5517.Select_SFI_DMA_Mode();                          // Select SPI DMA mode
  ER5517.SPI_Clock_Period(Clk);                          // Select SPI clock  
  	
                            
  ER5517.SFI_DMA_Destination_Start_Address(memory_addr);  	 
  ER5517.SFI_DMA_Transfer_Number(data_num);                 
  ER5517.SFI_DMA_Source_Start_Address(flash_addr);         
  ER5517.Check_Busy_SFI_DMA(); 
  ER5517.Start_SFI_DMA();
  ER5517.Check_Busy_SFI_DMA();
  ER5517.Memory_XY_Mode();
}


void ER5517Basic::Text_Mode(void)
{
  unsigned char temp;
  ER5517.LCD_CmdWrite(0x03);
  temp = ER5517.LCD_DataRead();
    temp |= cSetb2;
  ER5517.LCD_DataWrite(temp);
}

void ER5517Basic::Show_String(char *str)
{   
    Text_Mode();     
    ER5517.LCD_CmdWrite(0x04);
    while(*str != '\0')
    {
      ER5517.LCD_DataWrite(*str);
      Check_Mem_WR_FIFO_not_Full();
      ++str;   
    }
    Check_2D_Busy();

    Graphic_Mode(); //back to graphic mode;
}

void ER5517Basic::DrawPixel(unsigned short x,unsigned short y,unsigned short color)
{  
 //   ER5517.Goto_Pixel_XY(x,y);
    ER5517.LCD_CmdWrite(0x04); 
    ER5517.LCD_DataWrite(color);
    Check_Mem_WR_FIFO_not_Full();
    ER5517.LCD_DataWrite(color>>8);
    Check_Mem_WR_FIFO_not_Full();  
}  


void ER5517Basic::Show_picture(unsigned long numbers,const unsigned char *datap)
{   
  unsigned long i;

  ER5517.LCD_CmdWrite(0x04);  
  for(i=0;i<numbers*2;i+=2)
  {
    ER5517.LCD_DataWrite(pgm_read_byte(&datap[i+1]));
    Check_Mem_WR_FIFO_not_Full();
    ER5517.LCD_DataWrite(pgm_read_byte(&datap[i]));
    Check_Mem_WR_FIFO_not_Full();
  }

}

ER5517Basic ER5517=ER5517Basic();

/***************************************************
//Web: http://www.buydisplay.com
EastRising Technology Co.,LTD
Examples for ER-TFT40-3  Display test
Display is Hardward SPI 4-Wire SPI Interface and 5V Power Supply
Tested and worked with:
Works with Arduino 1.6.0 IDE  
Test ok: Arduino UNO,Arduino MEGA2560 ,Arduino DUE
If using the DUE board, please disconnect the metal pins of IO0 and IO1, 
and connect the adapter board's IO0 to IO11, IO1 to IO13,and modify the IO definition in the LCD_init.H file
****************************************************/

#include <SPI.h>
#include <Wire.h>
#include "LCD.h"
#include "LCD_init.h"

#define Picture_1_Addr	0
int nPoint;

void setup() 
{ 
  delay(100);
  ER5517.Parallel_Init();
  ER5517.HW_Reset();
  ER5517.System_Check_Temp();
  delay(100);

  while(ER5517.LCD_StatusRead()&0x02);
  ER5517.initial();
  ST7701S_Initial(); 
  ER5517.Display_ON();

  nPoint = 0;
}

void LCD_BTE_Memory_Copy(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr
                        ,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W     
                        ,unsigned short XDes,unsigned short YDes,unsigned int ROP_Code,unsigned short X_W,unsigned short Y_H)
{
  ER5517.BTE_S0_Color_16bpp();
  ER5517.BTE_S0_Memory_Start_Address(S0_Addr);
  ER5517.BTE_S0_Image_Width(S0_W);
  ER5517.BTE_S0_Window_Start_XY(XS0,YS0);

  ER5517.BTE_S1_Color_16bpp();
  ER5517.BTE_S1_Memory_Start_Address(S1_Addr);
  ER5517.BTE_S1_Image_Width(S1_W); 
  ER5517.BTE_S1_Window_Start_XY(XS1,YS1);

  ER5517.BTE_Destination_Color_16bpp();
  ER5517.BTE_Destination_Memory_Start_Address(Des_Addr);
  ER5517.BTE_Destination_Image_Width(Des_W);
  ER5517.BTE_Destination_Window_Start_XY(XDes,YDes);	
   
  ER5517.BTE_ROP_Code(ROP_Code);	
  ER5517.BTE_Operation_Code(0x02); //BTE Operation: Memory copy (move) with ROP.
  ER5517.BTE_Window_Size(X_W,Y_H); 
  ER5517.BTE_Enable();
  ER5517.Check_BTE_Busy();

}

void LCD_Select_Outside_Font_Init( unsigned char SCS,unsigned char Clk,unsigned long FlashAddr,unsigned long MemoryAddr
                                  ,unsigned long Num,unsigned char Size,unsigned char XxN,unsigned char YxN
                                  ,unsigned char ChromaKey,unsigned char Alignment)
{
/*	if(Size==16)	ER5517.Font_Select_8x16_16x16();
	if(Size==24)	ER5517.Font_Select_12x24_24x24();
	if(Size==32)	ER5517.Font_Select_16x32_32x32();

	//(*)
	if(XxN==1)	ER5517.Font_Width_X1();
	if(XxN==2)	ER5517.Font_Width_X2();
	if(XxN==3)	ER5517.Font_Width_X3();
	if(XxN==4)	ER5517.Font_Width_X4();

	//(*)	
	if(YxN==1)	ER5517.Font_Height_X1();
	if(YxN==2)	ER5517.Font_Height_X2();
	if(YxN==3)	ER5517.Font_Height_X3();
	if(YxN==4)	ER5517.Font_Height_X4();

	//(*)
	if(ChromaKey==0)	ER5517.Font_Background_select_Color();	
	if(ChromaKey==1)	ER5517.Font_Background_select_Transparency();	

	//(*)
	if(Alignment==0)	ER5517.Disable_Font_Alignment();
	if(Alignment==1)	ER5517.Enable_Font_Alignment();	
	
	ER5517.DMA_24bit_Linear(SCS,Clk,FlashAddr,MemoryAddr,Num);
	ER5517.CGRAM_Start_address(MemoryAddr);        
 */
}

void LCD_Print_Outside_Font_String( unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned char *c)
{
/*	unsigned short temp_H = 0;
	unsigned short temp_L = 0;
	unsigned short temp = 0;
	unsigned int i = 0;
	
  ER5517.Text_Mode();
  ER5517.Font_Select_UserDefine_Mode();
  ER5517.Foreground_color_65k(FontColor);
  ER5517.Background_color_65k(BackGroundColor);
  ER5517.Goto_Text_XY(x,y);
	
	while(c[i] != '\0')
  { 
		if(c[i] < 0xa1)
		{
		  ER5517.CGROM_Select_Internal_CGROM();
		  ER5517.LCD_CmdWrite(0x04);
		  ER5517.LCD_DataWrite(c[i]);
		  ER5517.Check_Mem_WR_FIFO_not_Full();  
			i += 1;
		}
		else
		{
		  ER5517.Font_Select_UserDefine_Mode();
		  ER5517.LCD_CmdWrite(0x04);
			temp_H = ((c[i] - 0xa1) & 0x00ff) * 94;
			temp_L = c[i+1] - 0xa1;
			temp = temp_H + temp_L + 0x8000;
		  ER5517.LCD_DataWrite((temp>>8)&0xff);
		  ER5517.Check_Mem_WR_FIFO_not_Full();
		  ER5517.LCD_DataWrite(temp&0xff);
		  ER5517.Check_Mem_WR_FIFO_not_Full();
			i += 2;		
		}
	}
	
  ER5517.Check_2D_Busy();
  ER5517.Graphic_Mode(); //back to graphic mode;
  */
}

void loop() 
{
  unsigned int i;
  ER5517.Select_Main_Window_16bpp();
  ER5517.Main_Image_Start_Address(layer1_start_addr);       
  ER5517.Main_Image_Width(LCD_XSIZE_TFT);
  ER5517.Main_Window_Start_XY(0,0);
  ER5517.Canvas_Image_Start_address(layer1_start_addr);
  ER5517.Canvas_image_width(LCD_XSIZE_TFT);
  ER5517.Active_Window_XY(0,0);
  ER5517.Active_Window_WH(LCD_XSIZE_TFT,LCD_YSIZE_TFT); 

  ER5517.Foreground_color_65k(Black);
  ER5517.Line_Start_XY(0,0);
  ER5517.Line_End_XY(LCD_XSIZE_TFT-1,LCD_YSIZE_TFT-1);
  ER5517.Start_Square_Fill();

  ER5517.Foreground_color_65k(Yellow);
  ER5517.Line_Start_XY(0,80);
  ER5517.Line_End_XY(LCD_XSIZE_TFT-1,80);
  ER5517.Start_Line();

  while(1)
  {
    ER5517.Background_color_65k(Black);
    ER5517.Foreground_color_65k(White);  
    ER5517.CGROM_Select_Internal_CGROM();
 
    ER5517.DMA_24bit_Block(1,0,100,100,200,350,LCD_XSIZE_TFT,(Picture_1_Addr+nPoint));

    nPoint=nPoint+2;
    if(nPoint>8000) 
    {
      nPoint = 0;
    }

  }
}


So what is stopping you from writing code that reads the serial input and starts a download to the SD card?

You will have to write the code to do this in your language of choice on your PC. Most people use the free multi platform called Processing.

Thanks for the reply, Mike. I didn't know that was an option. I will definitely consider it, though my programming skills are likely insufficient. This option will also require that I completely disassemble my dash unit in order to install the SD card... something I was trying to avoid. But not so bad if I only have to do it once.

Having said that, perhaps you or someone can answer a question...

I downloaded the example program. It contained a .bin file with 5 full screen pictures, a gif and some fonts. When compiling the program, the contents of this .bin file was somehow transferred to the flash memory on the LCD. I can easily modify the .bin file using image2lcd. I would love to just modify the .bin file with my required images. However, when I tried this there was no change to the images in the flash memory!? Can someone explain to me how the images were initially transferred to the flash memory and why changing the .bin file doesn't seem to work.

Then what you tried did not do what you wanted to do.

How is this .bin file formatted? Note this is almost certianly not the same as a .png file.

To the best of my knowledge, the .bin file contains the raw image data (16 bit format) with no header information. The same applies for the gif and the fonts also contained in the file

But as there was no change in the image when you tried to replace this with a .png file, you were simply not replacing anything.

If you were you would see some sort of change, if it were only rubbish.

I'm not sure why you keep mentioning a .png file. I never said anything about a .png file. I replaced the .bin file with another .bin file created by image2LCD. The data in the original bin file and the new bin file contained 16 bit images (I also tried it with several other image formats just in case) with no header data, just raw image data.

After changing the .bin file I recompiled and uploaded the program. At this point, you are correct, there was no change. Hence the question about how compiling transfers the .bin file in the first place?

Have you read this which seems to be the same display as you have:-

Note what it says about the computer requirements. What processor are you trying to use?
A quote from that page says:-

You cannot use these with an everyday microcontroller unless it specifically has support for RGB-666 displays, so please do not purchase unless you know for sure that it can plug into a driver board with the correct pinout as well

Also note it is a lot more expensive than the one in the link you provided.

I can't seem to find one to buy in the UK. Ebay has nothing either.

The shipping from BuyDisplayes exceeds the cost of the display and the "compulsory" options bring the price up to $20.11

No but that is a flat format image file so using one should show some sort of image and a bit of odd looking noise from the format information.

I did download the examples and look at the .bin file with a Hex editor (called 0xED) but nothing jumped out at me saying this was an image.

What is this "image2lcd" that you talk of. I assume it is some sort of app can you link to it please? And what makes you think this is suitable for your display?

All I can advise is that you read all the data sheets you can from both the Adafruit and BuyDisplays site, and see if that gives you the information you need.

Have you read this which seems to be the same display as you have

Not yet, but I'll go through it and see if there is any useful info.

What processor are you trying to use?

I'm using the LCD with their controller, plus their mega shield. It all works great and is extremely fast. Full screen images come up almost instantly.

I did download the examples and look at the .bin file with a Hex editor (called 0xED) but nothing jumped out at me saying this was an image

I'm using a hex editor called winvi. There is also a text file which gives the addresses of the various items within the .bin file. If you do the math, it equates to the images.

What is this "image2lcd" that you talk of. I assume it is some sort of app can you link to it please?

It's an app that converts images to .bin files. It also allows you to change the image to any format before the conversion. Here's a link:

All I can advise is that you read all the data sheets you can from both the Adafruit and BuyDisplays site, and see if that gives you the information you need.

I appreciate the effort. I've read all their documentation and unfortunately, can't find anything helpful yet.

I've installed the SD card, so I can now look at that as an option...though I haven't been able to figure out how to access files on it yet. I still feel the best option would be figuring out how to upload new images to the flash memory, but right now I'll take what I can get.

I tried it but typically arrogantly it doesn't mention what sort of machine it runs on. Looks like it is a Windoes application.

Note also a .bin file is not a standard thing, it is just any file holding binary data, so I would not expect it to conform with the .bin file your display uses.

I'm probably going to tell you something you already know but here are some thoughts.

You say you have text file that gives the starting addresses of each of your images in the .bin file that means you can count the number of bytes for each image. What would be nice would be if you can identify one of those images as being full screen in other words 480 x 480 pixels and doing a byte count. Also if they are not all full screen images there has to be information in the file somewhere that tells the program what size the images are.

Normally a display would run at RGB 565, if your display is running RGB 565 the image data will be 2 bytes for every pixel of image data so that works out to 480 X 480 = 230400 pixels, 230400 pixels X 2 = 460800 pixels for a full screen image.

The value of 460800 is important because if you look at the file I assume to be LCD.h it has 11 Layer defines and the values defined are multiples of 460800 so that makes me think the image data is indeed RGB 565. Thats pretty cool if your display has 11 layers and each one can contain an image.

image2lcd might be ok I have never used it but here are a couple of alternatives

Here is a link to an online converter that takes bmp's or png's and gives you a RGB 565 file, problem is it is limited to 300KB file size.

http://www.rinkydinkelectronics.com/t_imageconverter565.php

another link to a video tutorial

Yes, it's a Windows app.

I came to the same conclusion. But it always brings me back to the same problem...how did the compiling of the program trigger the uploading of this image data to the flash memory? Why can't I change the image data in the bin file and get the new images uploaded to the flash memory?

Simply because you are not providing your alternate .bin file in the same format as the code is expecting.

If you look at the .bin file that is used by default, you will see that there is a text file that tells you what section is at what offset from the start. These are called "pointers" which means it is an offset to where certain information is supplied, like the image files.

Now if you want to replace something in that .bin file, you have to construct these pointers anew, you can't just leave them as they are. Trying to replace the .bin file with something that has been produced by another program is going to produce a file that does not produce the same format. When your code comes to try and read that, it probably finds those pointers do not correspond with what it is expecting and so gives up.

In order to know how to construct a valid .bin file you will have to work out exactly how you .bin file is constructed, in other words from the information you have, which is a working .bin file and a text list of pointers. This process is called "reverse engineering".

A .bin file is just a file where arbitrary data is stored, normally used as an intermediate stage in the compilation process. The writers of your software are using it in a very special way, which at the moment, as far as we know, is not explained anywhere.

Try reading https://www.buydisplay.com/download/ic/LT7680.pdf
It explains all the working of the basic display controller. This is contains the full information about this complex chip all the modes it can run in, the effects it can produce and what determines how it works.

It is very heavy going but at least you can get a handle on what all those seemingly arbitrary writes are doing at the start of the code. The information is there, but I feel that sadly you will not be able to understand it.

Perhaps I wasn't clear on all that I had tried and found out. I'm totally clear on the .bin concept. I actually proved that it is image data, and in a 16 bit format. Unless there is a hidden checksum (which is unlikely as the image data in the bin file did not contain any header information) changing the data directly within the middle of the image data should result with an embedded portion of a picture, or at least some garbage in the middle of the image. I tried much more than "just changing the bin file with some other arbitrary file". I verified that the data was 16 bit image data and changed a small portion of the image with 16 bit image data. However, none of the .bin file was transferred when I recompiled the program. So there is another mechanism in play that I clearly need to figure out. I know it can be done....because it was done.

Yes...I already read the document you mentioned. Excellent information in it, but unfortunately it didn't answer my questions. But I'll put my crayons and comic books away and re-read it.

I've reached out to the BuyDisplay engineers to see if they have any advice.

The BuyDisplay engineer got back to me. The example .bin file images are actually uploaded at the factory using a standard hardware SPI flash programmer. The bin file can contain images in 8 bit, 16 bit, 24 bit or 32 bit format. The bin file generator is available for download from the Levetop website. The flash memory is 128Mb...definitely worthwhile using.

Let us know how you get on with this when you try it.

Quick update.

I purchased a ch341 flash programmer. (About $15. And despite the multitude of videos and reports, you do not need to modify these for 3.3v.) For this controller board, you can connect direct to the flash chip, or add jumper pins in the space provided. I soldered in the pins so that I can keep a cable connected for future programming when the display is fully installed in my dash. I used NeoProgrammer. (You need to install the drivers from the ch341 flash programmer software first). I used the .bin software from Levetop to convert and combine my image files (UartTFT.exe to convert the files to bins). I used 16 bit (RGB 565) successfully with the display. Supposedly you can use 24 bit images, but I struggled with that, so I went back to the 16 bit images which are more than I needed anyway.

The LCD is one of the best I've used. Can be viewed clearly from any angle. Initial loading is a bit slow, but once everything is running the full screen images display instantly. Lots of sleep mode options anyway. Displaying images from flash memory is simple, with a single line of code.

Now for a one strange issue....

For some reason, I need to keep the ch341 programmer plugged into the cable. If I remove it, the images get a little distorted, like they are dropping from 16 bit to 8 bit. When it gets plugged back in, the problem goes away. !!??!! Sounds like a grounding issue, but I may have to pass that one to the BuyDisplay engineers to figure out. Worst case, I'll just leave it plugged in and install in inside the dash. It's tiny.

3 Likes