Dejo Código básico, en C18, para utilizar un GLCD de 5.7" trabajando en 8 bits, con un controlador solomon SDD1963.
Saludos
#include "p18f4520.h"
#include <stdlib.h>
#include <stdio.h>
#include <delays.h>
#pragma config OSC = HSPLL, FCMEN = OFF, IESO = OFF // CONFIG1H
#pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 3 // CONFIG2L
#pragma config WDT = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC // CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF, DEBUG = ON // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // CONFIG5L
#pragma config CPB = OFF, CPD = OFF // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // CONFIG7L
#pragma config EBTRB = OFF // CONFIG7H
// control line pins
#define LCD_RS PORTBbits.RB7
#define LCD_WR PORTBbits.RB6
#define LCD_RD PORTBbits.RB5
#define LCD_CS PORTBbits.RB4
#define LCD_RES PORTBbits.RB3
/*************************************************/
void Write_Command(unsigned char command)
{
PORTC = command;
LCD_RS = 0;
LCD_WR = 0;
LCD_WR = 1;
}
/*************************************************/
void Write_Data(unsigned char data1)
{
PORTC = data1;
LCD_WR = 0;
LCD_WR = 1;
}
/*************************************************/
void Command_Write(unsigned char REG,unsigned char VALUE)
{
Write_Command(REG);
LCD_RS = 1;
Write_Data(VALUE);
}
/*************************************************/
void SendData(unsigned long color)
{
LCD_RS = 1;
Write_Data((color)>>16); //red
Write_Data((color)>>8); //green
Write_Data(color);
}
/*************************************************/
void Init_SSD1963(void)
{
LCD_CS = 0;
LCD_RD = 1;
LCD_WR = 0;
LCD_RES = 0;
Delay10KTCYx(2);
LCD_RES = 1;
Delay10KTCYx(10);
Write_Command(0x01); //Software Reset
Write_Command(0x01);
Write_Command(0x01);
Command_Write(0xe0,0x01); //START PLL
Command_Write(0xe0,0x03); //LOCK PLL
Write_Command(0xb0); //SET LCD MODE SET TFT 18Bits MODE
LCD_RS = 1;
Write_Data(0x0c); //SET TFT MODE & hsync+Vsync+DEN MODE
Write_Data(0x80); //SET TFT MODE & hsync+Vsync+DEN MODE
Write_Data(0x01); //SET horizontal size=320-1 HightByte
Write_Data(0x3f); //SET horizontal size=320-1 LowByte
Write_Data(0x00); //SET vertical size=240-1 HightByte
Write_Data(0xef); //SET vertical size=240-1 LowByte
Write_Data(0x00); //SET even/odd line RGB seq.=RGB
Command_Write(0xf0,0x00); //SET pixel data I/F format=8bit
Command_Write(0x3a,0x60); // SET R G B format = 6 6 6
Write_Command(0xe6); //SET PCLK freq=6.4MHz ; pixel clock frequency
LCD_RS = 1;
Write_Data(0x00);
Write_Data(0xe7);
Write_Data(0x4f);
Write_Command(0xb4); //SET HBP,
LCD_RS = 1;
Write_Data(0x01); //SET HSYNC Total 440
Write_Data(0xb8);
Write_Data(0x00); //SET HBP 68
Write_Data(0x44);
Write_Data(0x0f); //SET VBP 16=15+1
Write_Data(0x00); //SET Hsync pulse start position
Write_Data(0x00);
Write_Data(0x00); //SET Hsync pulse subpixel start position
Write_Command(0xb6); //SET VBP,
LCD_RS = 1;
Write_Data(0x01); //SET Vsync total 265=264+1
Write_Data(0x08);
Write_Data(0x00); //SET VBP=19
Write_Data(0x13);
Write_Data(0x07); //SET Vsync pulse 8=7+1
Write_Data(0x00); //SET Vsync pulse start position
Write_Data(0x00);
Write_Command(0x2a); //SET column address
LCD_RS = 1;
Write_Data(0x00); //SET start column address=0
Write_Data(0x00);
Write_Data(0x01); //SET end column address=319
Write_Data(0x3f);
Write_Command(0x2b); //SET page address
LCD_RS = 1;
Write_Data(0x00); //SET start page address=0
Write_Data(0x00);
Write_Data(0x00); //SET end page address=239
Write_Data(0xef);
Write_Command(0x13); //SET normal mode
Write_Command(0x29); //SET display on
}
/*************************************************/
void WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y)
{
Write_Command(0x2a); //SET page address
LCD_RS = 1;
Write_Data((s_x)>>8); //SET start page address=0
Write_Data(s_x);
Write_Data((e_x)>>8); //SET end page address=319
Write_Data(e_x);
Write_Command(0x2b); //SET column address
LCD_RS = 1;
Write_Data((s_y)>>8); //SET start column address=0
Write_Data(s_y);
Write_Data((e_y)>>8); //SET end column address=239
Write_Data(e_y);
}
/*************************************************/
void FULL_ON(unsigned long dat)
{
unsigned x,y;
WindowSet(0x0000,0x013f,0x0000,0x00ef);
Write_Command(0x2c);
for(x=0;x<240;x++)
{
for(y= 0;y<320;y++)
{
SendData(dat);
}
}
}
/*************************************************/
void QUADS(void)
{
unsigned i,j;
WindowSet(0x0000,0x013f,0x0000,0x00ef);
Write_Command(0x2c);
for(j= 0 ;j<120;j++)
{
for(i=0;i<160;i++)
{
SendData(0x0000FF); //blue
}
for(i=0;i<160;i++)
{
SendData(0xFF0000); //red
}
}
for(j= 0 ;j<120;j++)
{
for(i=0;i<160;i++)
{
SendData(0xFFFF00); //yellow
}
for(i=0;i<160;i++)
{
SendData(0x00FF00); //green
}
}
}
/*************************************************/
void main(void)
{
TRISA = 0b00000000;
PORTA = 0b00000000;
TRISB = 0b00000000;
PORTB = 0b00000000;
TRISC = 0b00000000;
PORTC = 0b00000000;
Delay10KTCYx(50);
Delay10KTCYx(50);
Init_SSD1963(); // Initialize the display
while(1)
{
Delay10KTCYx(50);
Delay10KTCYx(50);
QUADS();
Delay10KTCYx(50);
Delay10KTCYx(50);
Delay10KTCYx(50);
Delay10KTCYx(50);
FULL_ON(0xff0000); //red
Delay10KTCYx(50);
Delay10KTCYx(50);
Delay10KTCYx(50);
Delay10KTCYx(50);
FULL_ON(0x00ff00); //green
Delay10KTCYx(50);
Delay10KTCYx(50);
Delay10KTCYx(50);
Delay10KTCYx(50);
FULL_ON(0x0000ff); //blue
Delay10KTCYx(50);
Delay10KTCYx(50);
Delay10KTCYx(50);
Delay10KTCYx(50);
}