PIC32MX795F512H with SSD1289

Status
Not open for further replies.

micro9000

New Member
Hey guys, I could use a bit of help here. I am trying to get this graphics LCD (YX32B 3.2" 320x240) to display the color red. I found some sample code and looked at the timing on pg.63 of the SSD1289 datasheet:

https://www.electro-tech-online.com/custompdfs/2013/01/SSD1289.pdf

It says that a complete write cycle takes 100ns and WR need to be low for 50ns and high for 50ns under 8080 16 bit parallel timing characteristics.

The problem is that it appears that I cannot get the LCD to initialize properly. After commenting out the call to "SSD1289_clearWith(0xF800);" and leaving just "SSD1289_on();" leaves me with a glitched screen that flickers. The line "SSD1289_clearWith(0xF800);" has no effect. Here is a picture of what I am talking about.

**broken link removed**

I am using the following code:

Code:
// DEVCFG3
// USERID = No Setting
#pragma config FSRSSEL = PRIORITY_7     // SRS Select (SRS Priority 7)
#pragma config FMIIEN = OFF             // Ethernet RMII/MII Enable (RMII Enabled)
#pragma config FETHIO = OFF             // Ethernet I/O Pin Select (Alternate Ethernet I/O)
#pragma config FCANIO = OFF             // CAN I/O Pin Select (Alternate CAN I/O)
#pragma config FUSBIDIO = OFF           // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)

// DEVCFG2
// External Oscillator uses base 20MHz oscillator
#pragma config FPLLIDIV = DIV_5         // PLL Input Divider (4x Divider) Using 20MHz/5 = 4MHz
#pragma config FPLLMUL = MUL_20         // PLL Multiplier (20x Multiplier) 4MHz * 20 = 80Mhz
#pragma config UPLLIDIV = DIV_5         // USB PLL Input Divider (5x Divider) (USB module must have an input of 4MHz to multiply by 24 (96) and divide by 2 to get 48MHz for FS)
#pragma config UPLLEN = ON              // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1         // System PLL Output Clock Divider (PLL Divide by 1) => 80Mhz/1 => 80MHz

// DEVCFG1
#pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF                // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = HS             // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1              // Watchdog Timer Postscaler (1:1)
#pragma config FWDTEN = OFF              // Watchdog Timer Enable (WDT Enabled)

// DEVCFG0
#pragma config DEBUG = OFF              // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (ICE EMUC1/EMUD1 pins shared with PGC1/PGD1)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)

#include <p32xxxx.h>
#include <plib.h>
#include "delays.h" // must create own delays


// Graphics LCD (SSD1289 controller)
#define HighByteGLCD LATD           // Used for D15 to D8 (RD7-RD0)
#define LowByteGLCD LATE            // Used for D7 to D0 (RE7-RE0)
#define RS_GLCD LATBbits.LATB5      // Register Select (AKA Data and Control D/C in datasheet of SSD1289)
#define CS_GLCD LATBbits.LATB4      // Chip select - used if using SPI communication
#define WR_GLCD LATBbits.LATB3      // Write enable


int main(void) {

    SYSTEMConfigPerformance(80000000); // predefined function from plib.h that optimizes access time to flash memory, enables the instruction
                                       // and data caches, and enables the PIC32 cache module to jump ahead and read functions that aren?t being
                                       // executed yet so there is often zero wait time for accessing those instructions

    DDPCONbits.JTAGEN = 0;  // disable the JTAG port

    //TRISBbits.TRISB12=0; // 0= ouput 1= input
    LATD=0;
    LATE=0;
    LATB=0;
    TRISB=0;
    TRISE=0;
    TRISD=0;
    AD1PCFG=0xFFFF; // pg. 144 of PIC32MX250F128B datasheet


    int i=0;
    int colours[] = {
                        0xFFFF, //white
                        0x0000, //black
                        0xF7DE, //grey
                        0x001F, //blue
                        0x051F, //blue2
                        0xF800, //red
                        0xF81F, //magenta
                        0x07E0, //green
                        0x7FFF, //cyan
                        0xFFE0  //yellow
                        };


    SSD1289_on();
    SSD1289_clearWith(0xF800); //turn LCD red

    while (1)
    {
         // do nothing
    }
    return 1;
}

void SSD1289_sendCommand( UINT16 command )
{
    CS_GLCD=0;
    RS_GLCD=0;
    

    HighByteGLCD=(unsigned char)command>>8;
    LowByteGLCD=(unsigned char)command;

    WR_GLCD=0;
    delay_50ns(1);

    WR_GLCD=1;

    delay_50ns(1);
    CS_GLCD=1;

    
}

void SSD1289_sendData( UINT16 data )
{
    CS_GLCD=0;
    RS_GLCD=1;

   
    HighByteGLCD=(unsigned char)data>>8;
    LowByteGLCD=(unsigned char)data;

    WR_GLCD=0;
    delay_50ns(1);

    WR_GLCD=1;

    delay_50ns(1);
    CS_GLCD=1;

    
}





void SSD1289_writeResgiter( UINT16 reg, UINT16 data ){

    SSD1289_sendCommand( reg );
    SSD1289_sendData( data );
}




void SSD1289_on(void)
{

          CS_GLCD =0;


    // set R07h at 0021h
    SSD1289_writeResgiter( 0x0007, 0x0021 );

    // set R00h at 0001h
    SSD1289_writeResgiter( 0x0000, 0x0001 );

    // set R07h at 0023h
    SSD1289_writeResgiter( 0x0007, 0x0023 );

    // set R10h at 0000h = exit sleep mode
    SSD1289_writeResgiter( 0x0010, 0x0000 );

    // wait 30ms
    delay_ms(30);

    // set R07h at 0033h
    SSD1289_writeResgiter( 0x0007, 0x0033 );

    // entry mode setting
    // set R11h at
    SSD1289_writeResgiter( 0x0011, 0x6830 );

    // LCD drive AC setting
    // set R02h at
    SSD1289_writeResgiter( 0x0002, 0x1000 );

    //Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh)
    SSD1289_writeResgiter( 0x0001,0x2B3F  );

    //Frame Cycle Control (R0Bh) (POR = 5308h)
    SSD1289_writeResgiter( 0x000B, 0x5308 );

    //Setting R28h as 0x0006 is required before
    //setting R25h and R29h registers.
    SSD1289_writeResgiter( 0x0028, 0x0006 );

    //Frame Frequency Control (R25h) (POR = 8000h)
    SSD1289_writeResgiter( 0x0025, 0xE000 );

    //set the RAM register for writing
    SSD1289_sendCommand(0x0022);

    // display ON, start to write RAM


    CS_GLCD =1;

}


void SSD1289_clearWith( UINT16 colour ){
    int i,j;
    for(i=0;i<320;i++){
        for (j=0;j<240;j++)
            SSD1289_sendData(colour);

    }

}

Again I am using the PIC32MX795F512H at 80MHz with MPLAB X and C32. The display module I am using is the YX32B 3.2" 320x240 display module with an SSD1289 controller.

The connections I am using are as follows:
D15-D8 => RD7-RD0
D7-D0 => RE7-RE0
RS => RB5
CS => RB4
WR => RB3
RD => 3.3V
Reset => 3.3V

If anyone has any idea as to why this isn't working please let me know. As always any help or suggestions are greatly appreciated. Thank you.
 
Last edited:
SOLVED

I found some sample code that didn't use the PMP module and modified it slightly for the PIC32MX uC I am using. There are now no delays required. Here is the working code:

Code:
/*
 * File:   main.c
 *
 */

// DEVCFG3
// USERID = No Setting
#pragma config FSRSSEL = PRIORITY_7     // SRS Select (SRS Priority 7)
#pragma config FMIIEN = OFF             // Ethernet RMII/MII Enable (RMII Enabled)
#pragma config FETHIO = OFF             // Ethernet I/O Pin Select (Alternate Ethernet I/O)
#pragma config FCANIO = OFF             // CAN I/O Pin Select (Alternate CAN I/O)
#pragma config FUSBIDIO = OFF           // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO = OFF          // USB VBUS ON Selection (Controlled by Port Function)

// DEVCFG2
// External Oscillator uses base 20MHz oscillator
#pragma config FPLLIDIV = DIV_5         // PLL Input Divider (4x Divider) Using 20MHz/5 = 4MHz
#pragma config FPLLMUL = MUL_20         // PLL Multiplier (20x Multiplier) 4MHz * 20 = 80Mhz
#pragma config UPLLIDIV = DIV_5         // USB PLL Input Divider (5x Divider) (USB module must have an input of 4MHz to multiply by 24 (96) and divide by 2 to get 48MHz for FS)
#pragma config UPLLEN = ON              // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_1         // System PLL Output Clock Divider (PLL Divide by 1) => 80Mhz/1 => 80MHz

// DEVCFG1
#pragma config FNOSC = PRIPLL           // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF            // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF                // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = HS             // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_1           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1)
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1              // Watchdog Timer Postscaler (1:1)
#pragma config FWDTEN = OFF              // Watchdog Timer Enable (WDT Enabled)

// DEVCFG0
#pragma config DEBUG = OFF              // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (ICE EMUC1/EMUD1 pins shared with PGC1/PGD1)
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)

#include <p32xxxx.h>
#include <plib.h>
#include "delays.h" // must create own delays


#define    RS    LATBbits.LATB5
#define    CS    LATBbits.LATB4
#define    RW    LATBbits.LATB3


#define    DATA_H    LATD
#define    DATA_L    LATE


void SSD1289_sendCommand( UINT16 command )
{
CS=0;
RS=0;

DATA_H=(unsigned char)command>>8;
DATA_L=(unsigned char)command;


RW=0;
RW=1;
CS=1;
}

void SSD1289_sendData( UINT16 data )
{
CS=0;
RS=1;


DATA_H=(unsigned char)(data>>8);
DATA_L=(unsigned char)data;


RW=0;
RW=1;
CS=1;

}


void SSD1289_writeResgiter( UINT16 reg, UINT16 data ){

    SSD1289_sendCommand( reg );
    SSD1289_sendData( data );
}


void SSD1289_on(void)
{

          CS =0;


    // set R07h at 0021h
    SSD1289_writeResgiter( 0x0007, 0x0021 );

    // set R00h at 0001h
    SSD1289_writeResgiter( 0x0000, 0x0001 );

    // set R07h at 0023h
    SSD1289_writeResgiter( 0x0007, 0x0023 );

    // set R10h at 0000h = exit sleep mode
    SSD1289_writeResgiter( 0x0010, 0x0000 );

    // wait 30ms
    delay_ms(30);

    // set R07h at 0033h
    SSD1289_writeResgiter( 0x0007, 0x0033 );

    // entry mode setting
    // set R11h at
    SSD1289_writeResgiter( 0x0011, 0x6830 );

    // LCD drive AC setting
    // set R02h at
    SSD1289_writeResgiter( 0x0002, 0x1000 );

    //Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh)
    SSD1289_writeResgiter( 0x0001,0x2B3F  );

    //Frame Cycle Control (R0Bh) (POR = 5308h)
    SSD1289_writeResgiter( 0x000B, 0x5308 );

    //Setting R28h as 0x0006 is required before
    //setting R25h and R29h registers.
    SSD1289_writeResgiter( 0x0028, 0x0006 );

    //Frame Frequency Control (R25h) (POR = 8000h)
    SSD1289_writeResgiter( 0x0025, 0xE000 );

    //set the RAM register for writing
    SSD1289_sendCommand(0x0022);

    // display ON, start to write RAM


        CS =1;

}


void SSD1289_clearWith( UINT16 colour ){
    int i,j;
    for(i=0;i<320;i++){
        for (j=0;j<240;j++)
            SSD1289_sendData(colour);

    }

}

void main()
{
int i=0;
int colours[] = {
                        0xFFFF, //white
                        0x0000, //black
                        0xF7DE, //grey
                        0x001F, //blue
                        0x051F, //blue2
                        0xF800, //red
                        0xF81F, //magenta
                        0x07E0, //green
                        0x7FFF, //cyan
                        0xFFE0  //yellow
                        };


TRISB=0;
TRISE=0;
TRISD=0;

LATB=0;
LATD=0;
LATE=0;

SSD1289_on();

SSD1289_clearWith(0xF800);

while(1)
{

    delay_ms(500);

    if(i==10){i=0;}
    SSD1289_clearWith(colours[i++]);

}

}
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…