CrazyEngineers
  • Problem With Coding a TFT Display

    Lankythekid

    Lankythekid

    @lankythekid-DEYi2A
    Updated: Jan 13, 2010
    Views: 1.1K
    I am an Electronic Engineering, working on my FYP; using a TFT display 320x240 in pixels, and RGB format of 666. it is using the SSD1963 controller for graphics and i am having trouble getting the programing code to work. If you can take a look at the following code and make some suggestions or adjustments that maybe the problem as to why its not working it will be greatly appreciated. Right now i am trying to display a specific colour on the screen for example just blue, or red or green. Eventually i would like to display some images.

    Karthick.

    //---------------------------------------------------------
    /*
    SSD1963_8-bit
    Program for writing to Newhaven Display 5.7" TFT
    */
    //---------------------------------------------------------

    #define CD PORTA.B0 //REGISTER SELECT - 1: Command, 0: Data
    #define nWR PORTA.B1 //ACTIVE LOW WRITE
    #define nRD PORTA.B2 //ACTIVE LOW READ
    #define CS PORTA.B3 //CHIP SELECT
    #define RESET PORTA.B4 //RESET

    //=======================================

    void Write_Command(unsigned char command)
    {
    nRD = 1;
    PORTB = command;
    CD = 0;
    nWR = 0;
    CS = 0;

    CS = 1;
    nWR = 1;

    }
    //;******************************************************************************
    void Write_Data(unsigned char data1)
    {
    nRD = 1;
    PORTB = data1;
    CD = 1;
    nWR = 0;
    CS = 0;

    CS = 1;
    nWR = 1;
    }
    //====================================================
    void Command_Write(unsigned char REG,unsigned char VALUE)
    {
    Write_Command(REG);
    Write_Data(VALUE);
    }
    //======================================================
    void SendData(unsigned long color)
    {
    Write_Data((color)>>16); //red
    Write_Data((color)>>8); //green
    Write_Data(color); //blue
    }
    //======================================================
    // initialize controller
    //======================================================
    void Init_SSD1963()
    {
    RESET = 0;
    Delay_ms(5);
    RESET = 1;
    Delay_ms(100);
    Write_Command(0x01); //Software Reset
    Write_Command(0x01);
    Write_Command(0x01);
    Delay_ms(10);
    Command_Write(0xe0,0x01); //START PLL
    Command_Write(0xe0,0x03); //LOCK PLL
    Write_Command(0xb0); //SET LCD MODE SET TFT 18Bits MODE
    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=4.94MHz ; pixel clock frequency
    Write_Data(0x02);
    Write_Data(0xff);
    Write_Data(0xff);
    Write_Command(0xb4); //SET HBP,
    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,
    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
    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
    Write_Data(0x00); //SET start page address=0
    Write_Data(0x00);
    Write_Data(0x00); //SET end page address=239
    Write_Data(0xef);
    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
    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
    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 char 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()
    {
    unsigned int 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()
    {
    int count = 3;

    TRISA=0;
    TRISB=0;

    //while(1){

    Init_SSD1963();
    Delay_ms(5);
    QUADS();

    //Delay_ms(200);
    //delayms(2000);
    //FULL_ON(0xff0000); //red
    //delayms(2000);
    //FULL_ON(0x00ff00); //green
    //delayms(2000);
    //FULL_ON(0x0000ff); //blue
    //FULL_ON(0xFFFF00); //yelow
    //delayms(2000);
    //}

    }
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • fvparg

    MemberMay 2, 2010

    hello. I use the following code sample:

    WINSTAR_TFT Application Note. 8bit-80 interface mode , 262K color , 5.7_Panel:320xRGBx240
    {
    Initial_SSD1963();
    FULL_ON(0xff0000); // red
    FULL_ON(0x00ff00); // green
    FULL_ON(0x0000ff); // blue
    }

    void Write_Command (unsigned char command)
    {
    IC_RD = 1; // /RD=1

    IC_A0 = 0; // D/C=0

    IC_WR= 0; // /WR=0

    IC_CS = 0; // /CS=0

    Data_BUS = command; // Data Bus OUT

    IC_CS = 1; // /CS=1

    IC_WR= 1; // /WR=1

    }

    void Write_Data (unsigned char data1)
    {
    IC_RD = 1;
    IC_A0 = 1;
    IC_WR = 0;
    IC_CS = 0;
    Data_BUS = data1;
    IC_CS = 1;
    IC_WR= 1;
    }

    void Command_Write(unsigned char command,unsigned char data1)
    {
    Write_Command(command);
    Write_Data(data1);
    }

    void SendData(unsigned long color)
    {
    Write_Data((color)>>16); // color is red
    Write_Data((color)>>8); // color is green
    Write_Data(color); // color is blue
    }

    void main(void)
    void Initial_SSD1963 (void) //for 5.7 QVGA

    {

    IC_RST = 0;
    _nop_();
    _nop_();
    _nop_();
    IC_RST = 1;
    _nop_();
    _nop_();
    _nop_();


    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
    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
    Write_Data(0x00);
    Write_Data(0xe7);
    Write_Data(0x4f);

    Write_Command(0xb4); //SET HBP
    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
    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
    Write_Data(0x00); //SET start column address=0
    Write_Data(0x00);
    Write_Data(0x01); //SET end column address=320
    Write_Data(0x3f);

    Write_Command(0x2b); //SET page address
    Write_Data(0x00); //SET start page address=0
    Write_Data(0x00);
    Write_Data(0x00); //SET end page address=240
    Write_Data(0xef);

    Write_Command(0x29); //SET display on
    Write_Command(0x2c);

    }
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register