# ILI9163C : LCD showing garbage after initialization

I am using a LCD having ILI9163C as LCD controller with pic18f66k22 with 8-bit parallel data interface. The problem that I am getting is that after initializing the LCD it shows the garbage instead of printing the whole screen with the colour as done in the code. So what might be causing this issue ? Here's the code that I have used. Here I am first resetting the display then initializing the display and then using the write data function to paint the screen with RED colour. Any help would be much appreciated.

The datasheet for the LCD controller can be found at https://www.displaytech-us.com/sites/default/files/driver-ic-data-sheet/ILI9163C_DS_V010_2011_0118.pdf

void lcd_reset(void)
{

PORTCbits.RC0=1;    //lcd reset
delay_ms(1);
PORTCbits.RC0=0;    //lcd reset
delay_ms(1);
PORTCbits.RC0=1;
delay_ms(120);
PORTAbits.RA5=1;
}

void Config_IO(void)       //Configures the I/O for the operation
{
int q = 0;
TRISA = 0x00;
TRISB = 0X00;  //output
TRISC = 0X00;  //output
TRISD = 0X00;  //output
TRISE = 0X00;  //output
TRISF = 0X00;  //input
}

void main()
{
unsigned char x=1,y=1,z;
OSCCONbits.IRCF0 = 1;                                                   //HFINTOSC 16MHz with PLLEN
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
OSCTUNEbits.PLLEN = 1;
delay_ms(5);
while(!OSCCONbits.IRCF2);                               //wait for HF-INTOSC oscillator frequency is stable
delay_ms(5);
Config_IO();

lcd_reset();
LCD_init();

LCD_paint_block(x,y,x+50,y+50,RED);
LCD_paint_block(x,y,x+50,y+50,RED);
while(1);
}

void write_command(unsigned char cmd)
{
rs=0;      // set the command line low,
cs=0;        // set the chip select low,
wr=0;

PORTE=cmd;  //PORTB=j&0xFFEF;

wr=1;
cs=1;     // Set the chip select high
}

void write_data(unsigned char dat)
{
rs=1;        // set the command line high,
cs=0;        // set the chip select low,
wr=0;     // set the write line low,

PORTE=dat;  //PORTB=j&0xffef;//(i|(PORTB&0x807F))

wr=1;
cs=1;
}

void LCD_init()
{
write_command(0x11); //Exit Sleep
delay_ms(120);

write_command(0xec); //
write_data(0x0c);

write_command(0x26); //Set Default Gamma
write_data(0x04);

write_command(0xB1);//Set Frame Rate  Ö¡Æµ¿ØÖÆ
write_data(0x08);
write_data(0x09);

write_command(0xB4);
write_data(0x07);

write_command(0xC0); //Set VRH1[4:0] & VC[2:0] for VCI1 & GVDD
write_data(0x0C);//0c
write_data(0x05);//05

write_command(0xC1); //Set BT[2:0] for AVDD & VCL & VGH & VGL
write_data(0x02);//02

write_command(0xC5); //Set VMH[6:0] & VML[6:0] for VOMH & VCOML  //Æ«Ñ¹¿ØÖÆ
write_data(0x41);//43
write_data(0x41);//43

write_command(0xC7);// Set VMF  //Æ«Ñ¹¿ØÖÆ
write_data(0xc1);//c1

write_data(0x00);
write_data(0x00);
write_data(0x00);
write_data(0x7F);

write_data(0x00);
write_data(0x00);
write_data(0x00);
write_data(0x9F);

write_command(0x3A); //Set Color Format
write_data(0x55);

write_command(0x36);
write_data(0x08);

write_command(0x20);

write_command(0xF2); //Enable Gamma bit
write_data(0x01);

write_command(0xE0);
write_data(0x3F);//p1
write_data(0x25);//p2
write_data(0x21);//p3
write_data(0x24);//p4
write_data(0x1D);//p5
write_data(0x0D);//p6
write_data(0x4C);//p7
write_data(0xB8);//p8
write_data(0x38);//p9
write_data(0x17);//p10
write_data(0x0F);//p11
write_data(0x08);//p12
write_data(0x04);//p13
write_data(0x02);//p14
write_data(0x00);//p15

write_command(0xE1);
write_data(0x00);//p1
write_data(0x1A);//p2
write_data(0x1E);//p3
write_data(0x0B);//p4
write_data(0x12);//p5
write_data(0x12);//p6
write_data(0x33);//p7
write_data(0x47);//p8
write_data(0x47);//p9
write_data(0x08);//p10
write_data(0x20);//p11
write_data(0x27);//p12
write_data(0x3C);//p13
write_data(0x3D);//p14
write_data(0x3F);//p15

write_command(0x3A); //Set Color Format
write_data(0x55);

write_command(0x29); // Display On

write_command(0x2C);//Memory Write

}

void LCD_paint_block (int Hstart,int Vstart, int Hend, int Vend, int color)
{

unsigned int i,count=((Hend-Hstart)+1)*((Vend-Vstart)+1)*2;

write_data(0x00);
write_data(0x00);
write_data(0x00);
write_data(0x7F);

write_data(0x00);
write_data(0x00);
write_data(0x00);
write_data(0x9F);

//start to write memory
write_command(0x2C);

for (i = 0; i <40960; i+=2)
{
write_data(color >> 8);
write_data(color);

}
}

void delay_ms(unsigned int ms)
{
unsigned int x;

for(x = 0; x < 8*ms; x++)
{
TMR1L = 0x00;
TMR1H = 0x00;
T1CON = 0x31;     //turn on timer1 1:8 prescale
while(TMR1L<0xFA);    //125us
T1CON = 0x30;     // turn off timer
}
}

void delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<250;j++);
}

• Can you reduce the code to the absolute minimum to reproduce the problem and add a link to the datasheet for the display/ – jippie Jun 12 '13 at 6:10
• added the datasheet and reduced the code as requested. @jippie – Jimit Jun 12 '13 at 6:17
• Some code is missing! – Leon Heller Jun 12 '13 at 9:09
• I have reduced the code to the absolute minimum here for convenience. – Jimit Jun 12 '13 at 9:16
• @LeonHeller OP reduced the code per an up-voted comment. – kolosy Jan 14 '15 at 20:21

I have solved this problem. I have used following two steps to get the LCD working at 64 MHz.

1. In the beginning I was straightaway using the 64 Mhz to get the LCD working. But then I switched to lower frequencies and started the LCD at 8,16,32 MHz. and then I moved to 64 MHz.

2. Delay is the thing which will cause the main problem at this high frequencies. So if LCD is working at lower frequencies and Not at higher frequencies then the only problem that you have is the delay. Try increasing the delay & it will surely work.

Download the library for ILI9163C displays for Teensy3, Arduino's and Energia IDE from GitHub.

Then, in file TFT_ILI9163C.h, change line 132 from:

#define __OFFSET        32//*see note 2


to

#define __OFFSET        0//*see note 2