AnsweredAssumed Answered

Help with STM32VL_Discovery and a TFT display

Question asked by urbina.jonathan on Aug 23, 2012
Latest reply on Feb 1, 2013 by lopes.paulo

Hi, i have a STM32VL_Discovery and i need help with the initialization code of the display with SSD1963 Controller... i have this code but i don't know what i'm doing... please i need it because is the thesis for college and i am VERY worried.

/* Includes */
#include <stddef.h>
#include "stm32f10x.h"
#include "STM32vldiscovery.h"
#include "Main.h"

 

int main(void)
{
 int i = 0;

  STM32vldiscovery_LEDInit(LED3);
  STM32vldiscovery_LEDInit(LED4);
  STM32vldiscovery_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
  STM32vldiscovery_LEDOff(LED3);
  STM32vldiscovery_LEDOff(LED4);

while(1){
 /* if(STM32vldiscovery_PBGetState(BUTTON_USER))
  {

   STM32vldiscovery_LEDOff(LED4);
   STM32vldiscovery_LEDToggle(LED3);

  }
  else
  {
   STM32vldiscovery_LEDOff(LED3);
   STM32vldiscovery_LEDToggle(LED4);

  }*/

 

       /*LCD_ResetDevice();
     LCD_WriteCommand(0xBE);
     LCD_Clear(0x000000);
     big_button();
     LCD_WriteCommand(0x29);*/

    //SSD1963_Init();
}

  /*GPIOSetup();
  GPIOLed(0);*/

return i;
}

//=============================================================================
// Write command to SSD1963
//=============================================================================
void SSD1963_WriteCommand(unsigned int commandToWrite)
{
SSD1963_DATAPORT->ODR  = commandToWrite;
SSD1963_CTRLPORT->BSRR = LCD_RD_PIN;
//SSD1963_CTRLPORT->BRR  = SSD1963_PIN_A0 | SSD1963_PIN_CS | SSD1963_PIN_WR;
SSD1963_DATAPORT->BRR  = LCD_CS_PIN;
SSD1963_CTRLPORT->BRR  = LCD_WR_PIN;
asm("nop");
//SSD1963_CTRLPORT->BSRR = SSD1963_PIN_A0 | SSD1963_PIN_CS | SSD1963_PIN_WR;
SSD1963_DATAPORT->BSRR  = LCD_CS_PIN;
SSD1963_CTRLPORT->BSRR  = LCD_WR_PIN;
}
//=============================================================================
// Write data to SSD1963
//=============================================================================
void SSD1963_WriteData(unsigned int dataToWrite)
{
SSD1963_DATAPORT->ODR  = dataToWrite;
//SSD1963_CTRLPORT->BSRR = SSD1963_PIN_RD | SSD1963_PIN_A0;
SSD1963_CTRLPORT->BSRR = LCD_RD_PIN;
SSD1963_DATAPORT->BRR  = LCD_CS_PIN;
SSD1963_CTRLPORT->BRR  = LCD_WR_PIN;
asm("nop");
SSD1963_DATAPORT->BSRR  = LCD_CS_PIN;
SSD1963_CTRLPORT->BSRR  = LCD_WR_PIN;
}
//=============================================================================
//
//=============================================================================
void SSD1963_Init (void)
{

 STM32vldiscovery_LEDInit(LED3);
 STM32vldiscovery_LEDInit(LED4);
 STM32vldiscovery_LEDOn(LED4);

volatile unsigned int dly;
SSD1963_DATAPORT->BRR = LCD_RST_PIN;
for(dly = 0; dly < 1000; dly++);
SSD1963_DATAPORT->BSRR = LCD_RST_PIN;
for(dly = 0; dly < 1000; dly++);

SSD1963_WriteCommand(SSD1963_SOFT_RESET);STM32vldiscovery_LEDOff(LED4);STM32vldiscovery_LEDOn(LED3);

SSD1963_WriteCommand(SSD1963_SET_PLL_MN);
SSD1963_WriteData(49); // PLLclk = REFclk * 50 (500MHz)
SSD1963_WriteData(4); // SYSclk = PLLclk / 5  (100MHz)
SSD1963_WriteData(4);  // dummy

SSD1963_WriteCommand(SSD1963_SET_PLL);
SSD1963_WriteData(0x01);

for(dly = 0; dly < 100000; dly++);

SSD1963_WriteCommand(SSD1963_SET_PLL);
SSD1963_WriteData(0x03);

SSD1963_WriteCommand(SSD1963_SET_LCD_MODE);
SSD1963_WriteData(0x0C);
SSD1963_WriteData(0x00);
SSD1963_WriteData(mHIGH((TFT_WIDTH-1)));
SSD1963_WriteData(mLOW((TFT_WIDTH-1)));
SSD1963_WriteData(mHIGH((TFT_HEIGHT-1)));
SSD1963_WriteData(mLOW((TFT_HEIGHT-1)));
SSD1963_WriteData(0b000000);

SSD1963_WriteCommand(SSD1963_SET_PIXEL_DATA_INTERFACE);
SSD1963_WriteData(SSD1963_PDI_16BIT565);

SSD1963_WriteCommand(SSD1963_SET_LSHIFT_FREQ);
SSD1963_WriteData((LCD_FPR >> 16) & 0xFF);
SSD1963_WriteData((LCD_FPR >> 8) & 0xFF);
SSD1963_WriteData(LCD_FPR & 0xFF);

SSD1963_WriteCommand(SSD1963_SET_HORI_PERIOD);
SSD1963_WriteData(mHIGH(TFT_HSYNC_PERIOD));
SSD1963_WriteData(mLOW(TFT_HSYNC_PERIOD));
SSD1963_WriteData(mHIGH((TFT_HSYNC_PULSE + TFT_HSYNC_BACK_PORCH)));
SSD1963_WriteData(mLOW((TFT_HSYNC_PULSE + TFT_HSYNC_BACK_PORCH)));
SSD1963_WriteData(TFT_HSYNC_PULSE);
SSD1963_WriteData(0x00);
SSD1963_WriteData(0x00);
SSD1963_WriteData(0x00);

SSD1963_WriteCommand(SSD1963_SET_VERT_PERIOD);
SSD1963_WriteData(mHIGH(TFT_VSYNC_PERIOD));
SSD1963_WriteData(mLOW(TFT_VSYNC_PERIOD));
SSD1963_WriteData(mHIGH((TFT_VSYNC_PULSE + TFT_VSYNC_BACK_PORCH)));
SSD1963_WriteData(mLOW((TFT_VSYNC_PULSE + TFT_VSYNC_BACK_PORCH)));
SSD1963_WriteData(TFT_VSYNC_PULSE);
SSD1963_WriteData(0x00);
SSD1963_WriteData(0x00);

SSD1963_WriteCommand(SSD1963_SET_DISPLAY_ON);STM32vldiscovery_LEDOff(LED3);STM32vldiscovery_LEDOn(LED4);  //SET display on
}
//=============================================================================
//
//=============================================================================
void SSD1963_SetArea(unsigned int sx, unsigned int ex, unsigned int sy, unsigned int ey)
{
SSD1963_WriteCommand(SSD1963_SET_COLUMN_ADDRESS);
SSD1963_WriteData((sx >> 8) & 0xFF);
SSD1963_WriteData((sx >> 0) & 0xFF);
SSD1963_WriteData((ex >> 8) & 0xFF);
SSD1963_WriteData((ex >> 0) & 0xFF);

SSD1963_WriteCommand(SSD1963_SET_PAGE_ADDRESS);
SSD1963_WriteData((sy >> 8) & 0xFF);
SSD1963_WriteData((sy >> 0) & 0xFF);
SSD1963_WriteData((ey >> 8) & 0xFF);
SSD1963_WriteData((ey >> 0) & 0xFF);
}
//=============================================================================
// Fill area of specified color
//=============================================================================
void SSD1963_FillArea(unsigned int sx, unsigned int ex, unsigned int sy, unsigned int ey, int color)
{
int i;
SSD1963_SetArea(sx, ex, sy, ey);
SSD1963_WriteCommand(SSD1963_WRITE_MEMORY_START);
for(i = 0; i < ((ex-sx+1)*(ey-sy+1)); i++)
 {
 SendData(color);
 }
}
//=============================================================================
// Fills whole screen specified color
//=============================================================================
void SSD1963_ClearScreen(unsigned long color)
{
unsigned int x,y;
SSD1963_SetArea(0, TFT_WIDTH-1 , 0, TFT_HEIGHT-1);
SSD1963_WriteCommand(0x2c);
for(x=0;x<TFT_WIDTH;x++)
 {
        for(y= 0;y<TFT_HEIGHT;y++)
                {
                SSD1963_WriteData(color);
                }
 }
}
//=============================================================================
//
//=============================================================================
void GLCD_SetPixel(int x, int y, int color)
{
SSD1963_SetArea(x, x, y, y);
SSD1963_WriteCommand(0x2c);
SSD1963_WriteData(color);
SSD1963_WriteCommand(0x0);
}
//=============================================================================
//
//=============================================================================

 

Outcomes