Estoy usando una pantalla LCD que tiene ILI9163C como controlador LCD con pic18f66k22 con interfaz de datos paralela de 8 bits. El problema que estoy obteniendo es que, después de inicializar la pantalla LCD, muestra la basura en lugar de imprimir toda la pantalla con el color tal como se hace en el código. Entonces, ¿qué podría estar causando este problema? Aquí está el código que he usado. Aquí primero reinicio la pantalla, luego inicializo la pantalla y luego utilizo la función de escritura de datos para pintar la pantalla con color ROJO. Cualquier ayuda sería muy apreciada.
La hoja de datos del controlador LCD se puede encontrar en
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_command(0x2A); //Set Column Address
write_data(0x00);
write_data(0x00);
write_data(0x00);
write_data(0x7F);
write_command(0x2B); //Set Page Address
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_command(0x2A); //Set Column Address
write_data(0x00);
write_data(0x00);
write_data(0x00);
write_data(0x7F);
write_command(0x2B); //Set Page Address
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++);
}