Message Boards
Threads [ Previous | Next ]
GLCD with PIC32
GLCD with PIC32
Tags: glcd, ssd963
7/12/10 1:58 PM
Hi, I am using an LCD from New Haven Display with an SSD1963, actually I can show in the display colors, i.e. red, blue, etc. But i can“t show any image on it.
I am not using the graphic libraries, i wrote my own code. Somebody can help me with this.

This is my code:

  1#include <plib.h> // Adds support for PIC32 Peripheral Library functions and macros
  2//#include "NumericTypedefs.h"
  3//#include "Images.c"
  4
  5//#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
  6//#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
  7
  8#define SYS_FREQ (80000000)
  9#define DESIRED_BAUDRATE (19200) //The desired BaudRate
 10#define LCD_RS PORTBbits.RB5   
 11#define LCD_WR PORTBbits.RB4
 12#define LCD_RD PORTBbits.RB3
 13#define LCD_CS PORTBbits.RB2
 14#define LCD_RES PORTBbits.RB1
 15
 16void DelayMs(unsigned int msec)
 17{
 18    unsigned int tWait, tStart;
 19    tWait=(SYS_FREQ/2000)*msec;
 20    tStart=ReadCoreTimer();
 21    while((ReadCoreTimer()-tStart)<tWait); // wait for the time to pass
 22}
 23
 24void DelayUs(unsigned int usec)
 25{
 26    unsigned int tWait, tStart;
 27    tWait=(SYS_FREQ/80000000)*usec;
 28    tStart=ReadCoreTimer();
 29    while((ReadCoreTimer()-tStart)<tWait); // wait for the time to pass
 30}
 31
 32void Write_Command(unsigned char command)
 33{
 34    PORTE = command;
 35    DelayUs(1);//Nop();//
 36    LCD_RS = 0;
 37    DelayUs(1);
 38    LCD_WR = 0;
 39    DelayUs(1);
 40    LCD_WR = 1;
 41    DelayUs(1);
 42}
 43
 44void Write_Data(unsigned char data1)
 45{
 46    PORTE = data1;
 47    DelayUs(1);//Nop();//
 48    LCD_WR = 0;
 49    DelayUs(1);
 50    LCD_WR = 1;
 51    DelayUs(1);
 52}
 53
 54void Command_Write(unsigned char REG,unsigned char VALUE)
 55{
 56       Write_Command(REG);
 57    LCD_RS = 1;
 58    Write_Data(VALUE);
 59}
 60
 61void SendData(unsigned long color)
 62{
 63      LCD_RS = 1;
 64    Write_Data((color)>>16);   //red
 65    Write_Data((color)>>8);      //green
 66    Write_Data(color);
 67}
 68
 69void Init_SSD1963(void)
 70{
 71       LCD_CS = 0;
 72    LCD_RD = 1;
 73    LCD_WR = 0;
 74    LCD_RES = 0;
 75    DelayMs(20);   
 76    LCD_RES = 1;
 77    DelayMs(100);
 78    Write_Command(0x01);        //Software Reset
 79    DelayMs(100);   
 80    Write_Command(0x01);
 81    DelayMs(100);
 82    Write_Command(0x01);
 83
 84    Command_Write(0xe0,0x01);   //START PLL
 85    Command_Write(0xe0,0x03);   //LOCK PLL
 86    Write_Command(0xb0);        //SET LCD MODE  SET TFT 18Bits MODE
 87    LCD_RS = 1;
 88    Write_Data(0x0c);           //SET TFT MODE & hsync+Vsync+DEN MODE
 89    Write_Data(0x80);           //SET TFT MODE & hsync+Vsync+DEN MODE
 90    Write_Data(0x01);           //SET horizontal size=320-1 HightByte
 91    Write_Data(0x3f);           //SET horizontal size=320-1 LowByte
 92    Write_Data(0x00);           //SET vertical size=240-1 HightByte
 93    Write_Data(0xef);           //SET vertical size=240-1 LowByte
 94    Write_Data(0x00);           //SET even/odd line RGB seq.=RGB
 95    Command_Write(0xf0,0x00);   //SET pixel data I/F format=8bit
 96    Command_Write(0x3a,0x60);   // SET R G B format = 6 6 6
 97    Write_Command(0xe6);        //SET PCLK freq=6.4MHz  ; pixel clock frequency
 98    LCD_RS = 1;
 99    Write_Data(0x00);
100    Write_Data(0xe7);
101    Write_Data(0x4f);
102    Write_Command(0xb4);        //SET HBP,
103    LCD_RS = 1;
104    Write_Data(0x01);             //SET HSYNC Total 440
105    Write_Data(0xb8);
106    Write_Data(0x00);             //SET HBP 68
107    Write_Data(0x44);
108    Write_Data(0x0f);             //SET VBP 16=15+1
109    Write_Data(0x00);             //SET Hsync pulse start position
110    Write_Data(0x00);
111    Write_Data(0x00);             //SET Hsync pulse subpixel start position
112    Write_Command(0xb6);        //SET VBP,
113    LCD_RS = 1;
114    Write_Data(0x01);             //SET Vsync total 265=264+1
115    Write_Data(0x08);
116    Write_Data(0x00);             //SET VBP=19
117    Write_Data(0x13);
118    Write_Data(0x07);             //SET Vsync pulse 8=7+1
119    Write_Data(0x00);             //SET Vsync pulse start position
120    Write_Data(0x00);
121    Write_Command(0x2a);        //SET column address
122    LCD_RS = 1;
123    Write_Data(0x00);           //SET start column address=0
124    Write_Data(0x00);
125    Write_Data(0x01);             //SET end column address=319
126    Write_Data(0x3f);
127    Write_Command(0x2b);          //SET page address
128    LCD_RS = 1;
129    Write_Data(0x00);             //SET start page address=0
130    Write_Data(0x00);
131    Write_Data(0x00);             //SET end page address=239
132    Write_Data(0xef);
133    Write_Command(0x13);          //SET normal mode
134    Write_Command(0x29);          //SET display on
135}
136
137void WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y)
138{
139       Write_Command(0x2a);      //SET page address
140    LCD_RS = 1;
141    Write_Data((s_x)>>8);         //SET start page address=0
142    Write_Data(s_x);
143    Write_Data((e_x)>>8);         //SET end page address=319
144    Write_Data(e_x);
145
146    Write_Command(0x2b);      //SET column address
147    LCD_RS = 1;
148    Write_Data((s_y)>>8);         //SET start column address=0
149    Write_Data(s_y);
150    Write_Data((e_y)>>8);         //SET end column address=239
151    Write_Data(e_y);
152}
153
154void FULL_ON(unsigned long dat)
155{
156       unsigned x,y;
157    WindowSet(0x0000,0x013f,0x0000,0x00ef);
158    Write_Command(0x2c);
159    for(x=0;x<240;x++)
160    {
161        for(y= 0;y20;y++)
162        {
163            SendData(dat);
164        }
165       }
166}
167
168void QUADS(void)
169{
170     unsigned i,j;
171    WindowSet(0x0000,0x013f,0x0000,0x00ef);
172    Write_Command(0x2c);
173    for(j= 0 ;j<120;j++)
174    {
175        for(i=0;i<160;i++)
176        {
177            SendData(0x0000FF);             //blue
178        }
179        for(i=0;i<160;i++)
180        {
181             SendData(0xFF0000);             //red
182        }
183       }
184    for(j= 0 ;j<120;j++)
185    {   
186         for(i=0;i<160;i++)
187        {
188             SendData(0xFFFF00);             //yellow
189        }
190        for(i=0;i<160;i++)
191        {
192               SendData(0x00FF00);             //green
193        }
194       }
195}
196
197int main(void)
198{
199    int pbClk;
200     int Contador;
201       // Configure the device for maximum performance but do not change the PBDIV
202       // Given the options, this function will change the flash wait states, RAM
203       // wait state and enable prefetch cache but will not change the PBDIV.
204       // The PBDIV value is already set via the pragma FPBDIV option above..
205   
206    pbClk=SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
207    /* LED setup - Turn off leds before configuring the IO pin as output */
208    mPORTDClearBits(BIT_0 | BIT_1 | BIT_2); // same as LATDCLR = 0x0007
209    /* Set RD0, RD1 and RD2 as outputs */
210    mPORTDSetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2 ); // same as TRISDCLR = 0x0007
211    /* endless loop */
212    mPORTEClearBits(BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
213    mPORTESetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); // same as TRISCCLR = 0x0007
214    mPORTBClearBits(BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5);
215    mPORTBSetPinsDigitalOut(BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5); // same as TRISCCLR = 0x0007
216
217    while(1)
218    {
219        Contador = Contador + 1;
220        DelayMs(100);
221        mPORTDToggleBits(BIT_0); // toggle LED0 (same as LATDINV = 0x0001)
222        DelayMs(100);
223        mPORTDToggleBits(BIT_1); // toggle LED1 (same as LATDINV = 0x0002)
224        DelayMs(100);
225        mPORTDToggleBits(BIT_2); // toggle LED2 (same as LATDINV = 0x0004)
226
227        OpenUART2(UART_EN | UART_NO_PAR_8BIT | UART_1STOPBIT ,  // Module is ON
228                  UART_RX_ENABLE | UART_TX_ENABLE,              // Enable TX & RX
229                  pbClk/16/DESIRED_BAUDRATE-1);                  // 19200 bps, 8-N-1
230
231           // Configure UART2 RX Interrupt
232           ConfigIntUART2(UART_INT_PR2 | UART_RX_INT_DIS);
233
234           putsUART2("*** MIRA EL DISPLAY ***\r\n");
235           putsUART2("*** Hola ***\r\n");
236
237        DelayMs(2000);
238          Init_SSD1963();         // Initialize the display
239    
240        DelayMs(1000);
241        QUADS();
242        DelayMs(2000);
243        FULL_ON(0xff0000);      //red
244        DelayMs(2000);
245        //VER_IMAGEN();
246    //FULL_ON(0x00ff00);      //green
247        //DelayMs(2000);
248        //FULL_ON(0x0000ff);      //blue
249        DelayMs(2000);
250    };
251    return 0;
252}
RE: GLCD with PIC32
7/24/10 11:32 PM as a reply to diegopuntin .
dear diegopuntin

do you have some news about your work. It intrested also for me the reply.
Is possible to contact you also privat ? We can arrange about your work and
time you spended

thanks