3
« on: October 22, 2012, 02:41:54 PM »
Hi Mark, I made that my GLCD woks, but for this I replace the glcd_toshiba, that is the default, with my own declarations.
#include "Background2.h"
//const unsigned long TableL[8] = {0x01234567, 0x89abcdef, 0xfedcba98, 0x76543210, 0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff};
static unsigned short int byte2;
static unsigned short int DeviceCode;
#if !defined _GLCD_SAMSUNG && !defined OLED_GLCD_MODE && !defined TFT_GLCD_MODE && !defined NOKIA_GLCD_MODE & !defined CGLCD_GLCD_MODE && !defined KITRONIX_GLCD_MODE && !defined MB785_GLCD_MODE && !defined TFT2N0369_GLCD_MODE
#if !defined _GLCD_TOSHIBA_DEFINES
#define GLCD_BUSY() ((fnReadGLCD_cmd() & 0x3) != 0x3)// LCD busy check
#define X_BYTES (GLCD_X/8) // the number of bytes holding the X-pixels
#define Y_BYTES GLCD_Y // the number of rows of X_BYTES holding the Y rows
#define DISPLAY_LEFT_PIXEL 0
#define DISPLAY_TOP_PIXEL 0
#define DISPLAY_RIGHT_PIXEL (GLCD_X - 1)
#define DISPLAY_BOTTOM_PIXEL (GLCD_Y - 1)
#define UPDATE_WIDTH ((X_BYTES + 7)/8)
#define UPDATE_HEIGHT Y_BYTES
// GLCD commands - Toshiba
//
#define SET_ADDRESS_POINTER 0x24
#define SET_TEXT_HOME_ADDRESS 0x40
#define SET_TEXT_HORIZ_BYTES 0x41
#define SET_GRAPHICS_HOME_ADDRESS 0x42
#define SET_GRAPHICS_HORIZ_BYTES 0x43
#define GRAPHIC_MODE_XOR 0x81
#define DISABLE_TEXT_DISABLE_CURSOR 0x98
#define WRITE_DATA_INC 0xc0
#define LCD_REG volatile unsigned short 0x60000000 // (*((volatile unsigned short *) 0x60000000))
// Local prototypes
//
static void fnCommandGlcd_1(unsigned char ucCommand, unsigned char ucParameter);
static void fnCommandGlcd_2(unsigned char ucCommand, unsigned short usParameter);
static void fnWriteGLCD_cmd(unsigned char ucByte);
static void fnWriteGLCD_data(unsigned char ucByte);
static unsigned char fnReadGLCD_cmd(void);
static unsigned short int LCD_ReadReg(unsigned short int LCD_Reg);
void wait_delay(int count);
static void LCD_Send(unsigned short int byte);
static unsigned short int LCD_ReadData(void);
static unsigned short int LCD_Read(void);
static void LCD_WriteIndex(unsigned short int index);
static void LCD_Delay(unsigned short int nCount);
void GLCD_Initialization(void);
void LCD_Clear(void);
void LCD_Background(void);
#define _GLCD_TOSHIBA_DEFINES // include only once
#endif
#ifdef _GLCD_COMMANDS // link in Toshiba specific interface commands
void wait_delay(int count)
{
while(count--);
}
static void LCD_Send(unsigned short int byte)
{
byte2 = byte;
GLCD_DATAASOUTPUT(); /* P2.0...P2.7 Output */
GLCD_DIR_H(); /* Interface A->B */
GLCD_EN_L(); /* Enable 2A->2B */
GLCD_DATAOUT(byte); /* Write D0..D7 */
GLCD_LE_H();
GLCD_LE_L(); /* latch D0..D7 */
GLCD_DATAOUT(byte >> 8); /* Write D8..D15 */
}
static unsigned short int LCD_Read(void)
{
unsigned short int value;
GLCD_DATAASINPUT(); /* P2.0...P2.7 Input */
GLCD_DIR_L(); /* Interface B->A */
GLCD_EN_L(); /* Enable 2B->2A */
wait_delay(80); /* delay some times */
value = (unsigned char)GLCD_DATAIN(); /* Read D8..D15 */
GLCD_EN_H(); /* Enable 1B->1A */
wait_delay(80); /* delay some times */
value = (value << 8) | (unsigned char)GLCD_DATAIN() ; /* Read D0..D7 */
GLCD_DIR_H();
return value;
}
static void LCD_WriteIndex(unsigned short int index)
{
GLCD_CS_L();
GLCD_RS_L();
GLCD_RD_H();
LCD_Send( index );
wait_delay(70);
GLCD_WR_L();
wait_delay(1);
GLCD_WR_H();
GLCD_CS_H();
}
static unsigned short int LCD_ReadData(void)
{
unsigned short int value;
GLCD_CS_L();
GLCD_RS_H();
GLCD_WR_H();
GLCD_RD_L();
value = LCD_Read();
GLCD_RD_H();
GLCD_CS_H();
return value;
}
static unsigned short int LCD_ReadReg(unsigned short int LCD_Reg)
{
unsigned short LCD_RAM;
/* Write 16-bit Index (then Read Reg) */
LCD_WriteIndex(LCD_Reg);
/* Read 16-bit Reg */
LCD_RAM = LCD_ReadData();
return LCD_RAM;
}
// Read data from the GLCD. It is assumed that RD/WR lines are initially high and that the data bus is being driven
// The data bus is driven again on exit and RD/WR lines set high again
//
static unsigned char fnReadGLCD_cmd(void)
{
unsigned char ucByte;
//GLCD_CD_H(); // set C/D line high for command
GLCD_DATAASINPUT(); // set the data bus high impedent
GLCD_RD_L(); // drive the read line low
GLCD_DELAY_READ(); // wait tACC so that the GLCD can drive the value on to the data bus
ucByte = (unsigned char)GLCD_DATAIN(); // read the value from the bus
GLCD_RD_H(); // set the read line high again
GLCD_DATAASOUTPUT(); // drive the data bus again
return (ucByte); // return the value that was read
}
// Write an 8 bit data byte. It is assumed that the RD/WR lines are initially high and return then high after completion
//
static void fnWriteGLCD_data(unsigned char ucByte)
{
// GLCD_CD_L(); // set C/D line low for data
GLCD_WR_L(); // set the WR line low
GLCD_DATAOUT(ucByte); // set the data value on the bus
GLCD_DELAY_WRITE(); // ensure tDS delay before removing the write line
GLCD_WR_H();
}
// Write an 8 bit command byte. It is assumed that the RD/WR lines are initially high and return them high after completion.
// The data bus is considered to be always driven.
//
static void fnWriteGLCD_cmd(unsigned char ucByte)
{
// GLCD_CD_H(); // set C/D line high for command
GLCD_WR_L(); // set the WR line low
GLCD_DATAOUT(ucByte); // set the data value on the bus
GLCD_DELAY_WRITE(); // ensure tDS delay before removing the write line
GLCD_WR_H();
}
// This routine is used to write two parameter data bytes plus a command byte.
// The GLCD may be busy for some time after certain commands
//
static void fnCommandGlcd_2(unsigned char ucCommand, unsigned short usParameter)
{
while (GLCD_BUSY()) {} // wait until the GLCD can accept further writes
fnWriteGLCD_data((unsigned char)usParameter); // write low data byte
while (GLCD_BUSY()) {} // wait until the GLCD can accept further writes
fnWriteGLCD_data((unsigned char)(usParameter >> 8)); // write high data byte
while (GLCD_BUSY()) {} // wait until the GLCD can accept further writes
fnWriteGLCD_cmd(ucCommand); // write the command
}
// This routine is used to write one parameter data bytes plus a command byte.
// The GLCD may be busy for some time after certain commands.
//
static void fnCommandGlcd_1(unsigned char ucCommand, unsigned char ucParameter)
{
while (GLCD_BUSY()) {} // wait until the GLCD can accept further writes
fnWriteGLCD_data(ucParameter); // write parameter byte
while (GLCD_BUSY()) {} // wait until the GLCD can accept further writes
fnWriteGLCD_cmd(ucCommand); // write the command
}
static void LCD_Delay(unsigned short int nCount)
{
unsigned short int TimingDelay;
while(nCount--)
{
for(TimingDelay=0;TimingDelay<10000;TimingDelay++);
}
}
static void LCD_WriteData(unsigned short int data)
{
GLCD_CS_L();
GLCD_RS_H();
LCD_Send( data );
GLCD_WR_L();
wait_delay(1);
GLCD_WR_H();
GLCD_CS_H();
}
static void LCD_WriteReg(unsigned short int LCD_Reg,unsigned short int LCD_RegValue)
{
/* Write 16-bit Index, then Write Reg */
LCD_WriteIndex(LCD_Reg);
/* Write 16-bit Reg */
LCD_WriteData(LCD_RegValue);
}
void GLCD_Initialization()
{
//GLCD_Configuration();
LCD_Delay(5); /* delay 50 ms */
DeviceCode = LCD_ReadReg(0x0000); /* ¶ÁÈ¡ÆÁID */
if(DeviceCode==0x8989)
{
LCD_WriteReg(0x0000,0x0001); LCD_Delay(5); /* ´ò¿ª¾§Õñ */
LCD_WriteReg(0x0003,0xA8A4); LCD_Delay(5);
LCD_WriteReg(0x000C,0x0000); LCD_Delay(5);
LCD_WriteReg(0x000D,0x080C); LCD_Delay(5);
LCD_WriteReg(0x000E,0x2B00); LCD_Delay(5);
LCD_WriteReg(0x001E,0x00B0); LCD_Delay(5);
LCD_WriteReg(0x0001,0x2B3F); LCD_Delay(5); /* Çý¶¯Êä³ö¿ØÖÆ320*240 0x2B3F */
LCD_WriteReg(0x0002,0x0600); LCD_Delay(5);
LCD_WriteReg(0x0010,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0011,0x6070); LCD_Delay(5); /* ¶¨ÒåÊý¾Ý¸ñʽ 16λɫ ºáÆÁ 0x6070 */
LCD_WriteReg(0x0005,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0006,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0016,0xEF1C); LCD_Delay(5);
LCD_WriteReg(0x0017,0x0003); LCD_Delay(5);
LCD_WriteReg(0x0007,0x0133); LCD_Delay(5);
LCD_WriteReg(0x000B,0x0000); LCD_Delay(5);
LCD_WriteReg(0x000F,0x0000); LCD_Delay(5); /* ɨÃ迪ʼµØÖ· */
LCD_WriteReg(0x0041,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0042,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0048,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0049,0x013F); LCD_Delay(5);
LCD_WriteReg(0x004A,0x0000); LCD_Delay(5);
LCD_WriteReg(0x004B,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0044,0xEF00); LCD_Delay(5);
LCD_WriteReg(0x0045,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0046,0x013F); LCD_Delay(5);
LCD_WriteReg(0x0030,0x0707); LCD_Delay(5);
LCD_WriteReg(0x0031,0x0204); LCD_Delay(5);
LCD_WriteReg(0x0032,0x0204); LCD_Delay(5);
LCD_WriteReg(0x0033,0x0502); LCD_Delay(5);
LCD_WriteReg(0x0034,0x0507); LCD_Delay(5);
LCD_WriteReg(0x0035,0x0204); LCD_Delay(5);
LCD_WriteReg(0x0036,0x0204); LCD_Delay(5);
LCD_WriteReg(0x0037,0x0502); LCD_Delay(5);
LCD_WriteReg(0x003A,0x0302); LCD_Delay(5);
LCD_WriteReg(0x003B,0x0302); LCD_Delay(5);
LCD_WriteReg(0x0023,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0024,0x0000); LCD_Delay(5);
LCD_WriteReg(0x0025,0x8000); LCD_Delay(5);
LCD_WriteReg(0x004f,0); /* ÐÐÊ×Ö·0 */
LCD_WriteReg(0x004e,0); /* ÁÐÊ×Ö·0 */
}
LCD_Delay(5); /* delay 50 ms */
}
static void LCD_SetCursor(unsigned short int Xpos,unsigned short int Ypos)
{
LCD_WriteReg(0x004e,Ypos); /* Line */
LCD_WriteReg(0x004f,0x13f-Xpos); /* Row */
}
void LCD_Clear(void)//(unsigned short int Color)
{
unsigned long int index=0;
LCD_SetCursor(0,0);
LCD_WriteIndex(0x0022);
for(index=0;index<76800;index++)
{
LCD_WriteData(0x07E0);
}
}
void LCD_Background(void)
{
unsigned long int index=0;
LCD_SetCursor(0,0);
LCD_WriteIndex(0x0022);
for(index=0;index<76800;index++)
{
LCD_WriteData(Back[index]);
}
}
#endif
#endif
Also I modified this lines in app_hw_lpc17xx.h
//#define DATA_LINES (PORT3_BIT7 | PORT3_BIT6 | PORT3_BIT5 | PORT3_BIT4 | PORT3_BIT3 | PORT3_BIT2 | PORT3_BIT1 | PORT3_BIT0)
#define DATA_LINES (PORT2_BIT7 | PORT2_BIT6 | PORT2_BIT5 | PORT2_BIT4 | PORT2_BIT3 | PORT2_BIT2 | PORT2_BIT1 | PORT2_BIT0)
#if defined NOKIA_GLCD_MODE // backlight and reset
#define LCD_BL PORT3_BIT26
#define GLCD_RST PORT3_BIT25
#define CONFIGURE_GLCD() _CONFIG_DRIVE_PORT_OUTPUT_VALUE(3, (GLCD_RST | LCD_BL), 0);
#define GLCD_RST_H() _SETBITS(3, GLCD_RST)
#define GLCD_RST_L() _CLEARBITS(3, GLCD_RST)
#define ENABLE_BACKLIGHT() _SETBITS(3, LCD_BL)
#ifdef _WINDOWS
#define MAX_GLCD_WRITE_BURST 1000 // the maximum number of writes to the GLCD before the task yields
#else
#define MAX_GLCD_WRITE_BURST 70 // the maximum number of writes to the GLCD before the task yields
#endif
#elif defined _GLCD_SAMSUNG
#define GLCD_RST PORT1_BIT31 // reset
#define GLCD_RS PORT1_BIT30 // GLCD Register Select
#define GLCD_RW PORT1_BIT29 // GLCD Read/Write
#define GLCD_ENA PORT1_BIT28 // GLCD Enable
#define GLCD_CS0 PORT1_BIT27 // LCD Controller 0 Chip Select - 2 controller chips for 128 x 64
#define GLCD_CS1 PORT1_BIT26 // LCD Controller 1 Chip Select
#define CONFIGURE_GLCD() _CONFIG_DRIVE_PORT_OUTPUT_VALUE(1, (GLCD_RST | GLCD_RW | GLCD_ENA | GLCD_RS | GLCD_CS0 | GLCD_CS1), (GLCD_RW)); _CONFIG_PORT_INPUT(3, DATA_LINES);
#define GLCD_RS_H() _SETBITS(1, GLCD_RS)
#define GLCD_RS_L() _CLEARBITS(1, GLCD_RS)
#define GLCD_RW_H() _SETBITS(1, GLCD_RW)
#define GLCD_RW_L() _CLEARBITS(1, GLCD_RW)
#define GLCD_CS0_H() _SETBITS(1, GLCD_CS0)
#define GLCD_CS0_L() _CLEARBITS(1, GLCD_CS0)
#define GLCD_CS1_H() _SETBITS(1, GLCD_CS1)
#define GLCD_CS1_L() _CLEARBITS(1, GLCD_CS1)
#define GLCD_DELAY_WRITE() // no write delay since the data is stable for long enough at full speed
#define GLCD_DELAY_READ() GLCD_RW_H() // one extra operation to ensure set up time of read
#define GLCD_RST_H() _SETBITS(1, GLCD_RST)
#define GLCD_RST_L() _CLEARBITS(1, GLCD_RST)
#define GLCD_ENA_H() _SETBITS(1, GLCD_ENA)
#define GLCD_ENA_L() _CLEARBITS(1, GLCD_ENA)
#ifdef _WINDOWS
#define MAX_GLCD_WRITE_BURST 1000 // the maximum number of writes to the GLCD before the task yields
#else
#define MAX_GLCD_WRITE_BURST 80 // the maximum number of writes to the GLCD before the task yields
#endif
#else // Toshiba type GLCD
/*#define GLCD_RST PORT1_BIT31
#define GLCD_C_D PORT1_BIT30
#define GLCD_WR PORT1_BIT29
#define GLCD_RD PORT1_BIT28
#define CONFIGURE_GLCD() _CONFIG_DRIVE_PORT_OUTPUT_VALUE(1, (GLCD_RST | GLCD_WR | GLCD_RD | GLCD_C_D), (GLCD_WR | GLCD_RD | GLCD_C_D)); _CONFIG_PORT_INPUT(3, DATA_LINES);
#define GLCD_RST_H() _SETBITS(1, GLCD_RST)
#define GLCD_RST_L() _CLEARBITS(1, GLCD_RST)
#define GLCD_WR_H() _SETBITS(1, GLCD_WR)
#define GLCD_WR_L() _CLEARBITS(1, GLCD_WR)
#define GLCD_CD_H() _SETBITS(1, GLCD_C_D)
#define GLCD_CD_L() _CLEARBITS(1, GLCD_C_D)
#define GLCD_RD_H() _SETBITS(1, GLCD_RD)
#define GLCD_RD_L() _CLEARBITS(1, GLCD_RD)
#define GLCD_DELAY_WRITE() //GLCD_WR_L() // no write delay since the data is stable for long enough at full speed
#define GLCD_DELAY_READ() GLCD_RD_L() // one extra operation to ensure set up time of read
*/
#define GLCD_EN PORT0_BIT19
#define GLCD_LE PORT0_BIT20
#define GLCD_DIR PORT0_BIT21
#define GLCD_CS PORT0_BIT22
#define GLCD_RS PORT0_BIT23
#define GLCD_WR PORT0_BIT24
#define GLCD_RD PORT0_BIT25
#define CONFIGURE_GLCD() _CONFIG_DRIVE_PORT_OUTPUT_VALUE(0, (GLCD_EN | GLCD_LE | GLCD_DIR | GLCD_CS | GLCD_RS | GLCD_WR | GLCD_RD), (GLCD_EN | GLCD_LE | GLCD_DIR | GLCD_CS | GLCD_RS | GLCD_WR | GLCD_RD)); _CONFIG_PORT_INPUT(2, DATA_LINES);
#define GLCD_EN_H() _SETBITS(0, GLCD_EN)
#define GLCD_EN_L() _CLEARBITS(0, GLCD_EN)
#define GLCD_LE_H() _SETBITS(0, GLCD_LE)
#define GLCD_LE_L() _CLEARBITS(0, GLCD_LE)
#define GLCD_DIR_H() _SETBITS(0, GLCD_DIR)
#define GLCD_DIR_L() _CLEARBITS(0, GLCD_DIR)
#define GLCD_CS_H() _SETBITS(0, GLCD_CS)
#define GLCD_CS_L() _CLEARBITS(0, GLCD_CS)
#define GLCD_RS_H() _SETBITS(0, GLCD_RS)
#define GLCD_RS_L() _CLEARBITS(0, GLCD_RS)
#define GLCD_WR_H() _SETBITS(0, GLCD_WR)
#define GLCD_WR_L() _CLEARBITS(0, GLCD_WR)
#define GLCD_RD_H() _SETBITS(0, GLCD_RD)
#define GLCD_RD_L() _CLEARBITS(0, GLCD_RD)
#define GLCD_DELAY_WRITE() //GLCD_WR_L() // no write delay since the data is stable for long enough at full speed
#define GLCD_DELAY_READ() GLCD_RD_L() // one extra operation to ensure set up time of read
#ifdef _WINDOWS
#define MAX_GLCD_WRITE_BURST 1000 // the maximum number of writes to the GLCD before the task yields
#else
#define MAX_GLCD_WRITE_BURST 20 // the maximum number of writes to the GLCD before the task yields
#endif
#endif
#define GLCD_DATAASOUTPUT() _DRIVE_PORT_OUTPUT(2, DATA_LINES)
#define GLCD_DATAASINPUT() _FLOAT_PORT(2, DATA_LINES)
#define GLCD_DATAOUT(data) _WRITE_PORT_MASK(2, data, DATA_LINES)
#define GLCD_DATAIN() _READ_PORT(2)
If you wanted , I can upload all the uTasker modified. Sorry by delay to public my code, but i was working in another stuff.
Thanks