Minimalist Code for MikromediaPlus for PIC32MX7

General discussion on Visual TFT Software.
Post Reply
Author
Message
Bill Legge
Posts: 235
Joined: 28 Oct 2007 03:16
Location: West Australia

Minimalist Code for MikromediaPlus for PIC32MX7

#1 Post by Bill Legge » 26 Oct 2017 05:52

I am using a MikromediaPlus for PIC32MX7 with the PIC32 compiler and trying to get
a 'minimalist' display working - no touch screen or anything.
My code is:

Code: Select all

// TFT module connections
sbit TFT_BLED_Direction at TRISC2_bit;
sbit TFT_BLED at LATC2_bit;
sbit TFT_CS_Direction at TRISF12_bit;
sbit TFT_CS at LATF12_bit;
unsigned int TFT_DataPort_Direction at TRISE;
unsigned int TFT_DataPort at LATE;
sbit TFT_RD_Direction at TRISD5_bit;
sbit TFT_RD at LATD5_bit;
sbit TFT_RS_Direction at TRISB15_bit;
sbit TFT_RS at LATB15_bit;
sbit TFT_RST_Direction at TRISC1_bit;
sbit TFT_RST at LATC1_bit;
sbit TFT_WR_Direction at TRISD4_bit;
sbit TFT_WR at LATD4_bit;
// End TFT module connections

void main(){
    AD1PCFG = 0xFFFF;               // Configure AN pins as digital I/O
    JTAGEN_bit = 0;                 // Disable JTAG
    TFT_BLED_Direction = 0;         // Set TFT backlight pin as output
    TFT_Init_SSD1963(480,272);      // used on MikromediaPlus
    TFT_Set_DBC_SSD1963(255);       // what is this function ?????????  Edited on 27/10/2017: IT TURNS THE BACK LIGHT FULL ON i.e. 255/255
    TFT_BLED = 1;                   // Turn on TFT backlight
    TFT_Fill_Screen(CL_WHITE);
    TFT_Set_Pen(CL_BLACK, 3);
    TFT_Line(0, 200, 477, 200);
    TFT_Set_Font(&TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
    TFT_Write_Text("TEST MESSAGE 1", 50, 50);
    
   while(1){
        delay_ms(100);
   }
    
}
Some help please:
1. What is the function TFT_Set_DBC_SSD1963(255) I copied it from the driver built using the Visual TFT, without
it the screen is blank but I can not find any help on this function?
2. The line and text appears but in the wrong colours - why?

Anyone got some minimalist code I can try?

Regards Bill Legge
Last edited by Bill Legge on 26 Oct 2017 23:38, edited 1 time in total.

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: Minimalist Code for MikromediaPlus for PIC32MX7

#2 Post by lana.arsic » 26 Oct 2017 16:21

Hi Bill,

1. Function TFT_Set_DBC_SSD1963(255)
turns backlight ON and sets it to value "255".

I'm sorry for missing information in the Help file,
it is reported to our developers to add description.

2. Can you tell me which version of mikroC compiler are you using?

Kind regards,
Lana

Bill Legge
Posts: 235
Joined: 28 Oct 2007 03:16
Location: West Australia

Re: Minimalist Code for MikromediaPlus for PIC32MX7

#3 Post by Bill Legge » 26 Oct 2017 23:35

Thanks for your reply.

My compiler version is PIC32 4.0.0 with the integrated VTFT.
I can use it to get images on the MikromediaPlus display 480X272
but I wanted to 'do it myself' to better learn how to drive the SSD1963 display driver.

The code shown above works OK on the Mikromedia EasyTFT320X240 display - changing to TFT_Init(320, 240);
but not on the MikromediaPlus480X272.

I suspect it is to do with driving the Data/Command pin TFT_D/C# connected to RB15?

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: Minimalist Code for MikromediaPlus for PIC32MX7

#4 Post by lana.arsic » 27 Oct 2017 16:09

Hi Bill,

Since you are using the newest version of the compiler,
in order to get correct colors you can call function TFT_Set_MM_Plus();

I suggest you to take a look in Init_MCU function
in hello world example from the compiler, in file hello_world_driver.c,
and try to use the same function.

Example is located in the installation folder of the compiler,
for example in: c:\Users\Public\Documents\Mikroelektronika\mikroC PRO for PIC32\Examples\VTFT\mikromedia Plus for PIC32MX7\hello_world.

Kind regards,
Lana

Bill Legge
Posts: 235
Joined: 28 Oct 2007 03:16
Location: West Australia

Re: Minimalist Code for MikromediaPlus for PIC32MX7

#5 Post by Bill Legge » 28 Oct 2017 01:11

Lana - thanks for the suggestion - it worked.

Below is the minimum code needed to get the 480X272 TFT on the MikromediaPlus for PIC32MX7
working:
1. Copied from the examples folders for PIC32MC VTFT
2. Touch screen activation and use removed
3. Internal storage of resources
4. The function 'Initialize_TouchPanel' edited and re-named 'InitializeTFT.'

Code: Select all

// TFT module connections
sbit TFT_BLED_Direction at TRISC2_bit;
sbit TFT_BLED at LATC2_bit;
sbit TFT_CS_Direction at TRISF12_bit;
sbit TFT_CS at LATF12_bit;
unsigned int TFT_DataPort_Direction at TRISE;
unsigned int TFT_DataPort at LATE;
sbit TFT_RD_Direction at TRISD5_bit;
sbit TFT_RD at LATD5_bit;
sbit TFT_RS_Direction at TRISB15_bit;
sbit TFT_RS at LATB15_bit;
sbit TFT_RST_Direction at TRISC1_bit;
sbit TFT_RST at LATC1_bit;
sbit TFT_WR_Direction at TRISD4_bit;
sbit TFT_WR at LATD4_bit;
// Prototype functions
void Init_MCU();
void Initialize_TFT();
void Set_Index(unsigned short index);
void Write_Command( unsigned short cmd);
void Write_Data(unsigned int _data);

////////////////////////////////////////////////////////////////////////////////
void main(){
    AD1PCFG = 0xFFFF;               // configure AN pins as digital I/O
    JTAGEN_bit = 0;                 // disable JTAG
    TFT_BLED_Direction = 0;         // set TFT backlight pin as output
    Init_MCU();
    Initialize_TFT();
    TFT_BLED = 1;                   // turn on TFT backlight
    
    TFT_Fill_Screen(CL_YELLOW);     // some TFT commands to test
    TFT_Set_Pen(CL_RED, 3);
    TFT_Line(0, 200, 477, 200);
    TFT_Set_Font(&TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
    TFT_Write_Text("TEST MESSAGE 1", 50, 50);
    
   while(1){
        delay_ms(100);
   }
}

// Functions////////////////////////////////////////////////////////////////////
void Init_MCU() {
  // PMP setup
  PMMODE = 0;
  PMAEN  = 0;
  PMCON  = 0;               // WRSP: Write Strobe Polarity bit
  PMMODEbits.MODE = 2;      // master 2
  PMMODEbits.WAITB = 0;
  PMMODEbits.WAITM = 1;
  PMMODEbits.WAITE = 0;
  PMMODEbits.MODE16 = 1;    // 16 bit mode
  PMCONbits.CSF = 0;
  PMCONbits.PTRDEN = 1;
  PMCONbits.PTWREN = 1;
  PMCONbits.PMPEN = 1;
  
  TFT_Set_Default_Mode();
  STMPE610_SetDefaultMode();
  TFT_Set_MM_Plus();
}
void Initialize_TFT() {
  TFT_Set_Active(Set_Index, Write_Command, Write_Data);
  TFT_Init_SSD1963(480, 272);
  TFT_Set_DBC_SSD1963(255);
}
void Set_Index(unsigned short index) {
  TFT_RS = 0;
  PMDIN = index;
  while(PMMODEbits.BUSY);
  TFT_RS = 1;
}
void Write_Command( unsigned short cmd ) {
  TFT_RS = 1;
  PMDIN = cmd;
  while(PMMODEbits.BUSY);
}
void Write_Data(unsigned int _data) {
  PMDIN = _data;
  while(PMMODEbits.BUSY);
}
Main additions - adding code necessary to get the PMP working in 16bit mode.

Regards Bill Legge in Australia

Bill Legge
Posts: 235
Joined: 28 Oct 2007 03:16
Location: West Australia

Re: Minimalist Code for MikromediaPlus for PIC32MX7

#6 Post by Bill Legge » 28 Oct 2017 08:55

So far so good!
I now want to add an external image.
Created the appropriate "WVL_GPS_.RES" file and got the starting address by using the VTFT package
And added the code as follows:

Code: Select all

// TFT module connections
sbit TFT_BLED_Direction at TRISC2_bit;
sbit TFT_BLED at LATC2_bit;
sbit TFT_CS_Direction at TRISF12_bit;
sbit TFT_CS at LATF12_bit;
unsigned int TFT_DataPort_Direction at TRISE;
unsigned int TFT_DataPort at LATE;
sbit TFT_RD_Direction at TRISD5_bit;
sbit TFT_RD at LATD5_bit;
sbit TFT_RS_Direction at TRISB15_bit;
sbit TFT_RS at LATB15_bit;
sbit TFT_RST_Direction at TRISC1_bit;
sbit TFT_RST at LATC1_bit;
sbit TFT_WR_Direction at TRISD4_bit;
sbit TFT_WR at LATD4_bit;
// Extern memory interface
// MMC/SD Connections
sbit Mmc_Chip_Select at LATA6_bit;
sbit Mmc_Chip_Select_Direction at TRISA6_bit;
// end of MMC/SD
// Prototype functions
void Init_Ext_Mem();
void Init_MCU();
void Initialize_TFT();
void Set_Index(unsigned short index);
void Write_Command( unsigned short cmd);
void Write_Data(unsigned int _data);

// Globals
unsigned long res_file_size;

////////////////////////////////////////////////////////////////////////////////
void main(){
    AD1PCFG = 0xFFFF;               // configure AN pins as digital I/O
    JTAGEN_bit = 0;                 // disable JTAG

    TFT_BLED_Direction = 0;         // set TFT backlight pin as output
    Init_MCU();                     // set up PMP and
    Initialize_TFT();
    TFT_BLED = 1;                   // turn on TFT backlight
    Init_Ext_Mem();                 // set SPI and assign file ******* NEW CODE

    TFT_Ext_Image(0,0,0x0000002C, 1);                    // *******NEW CODE
    delay_ms(4000);

   while(1){
      delay_ms(500);
   }
}

// Functions////////////////////////////////////////////////////////////////////
void Init_Ext_Mem() {
    // Initialize SPI
    SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 80, _SPI_SS_DISABLE, \
    _SPI_DATA_SAMPLE_END, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
    Delay_ms(10);

    // Initialize MMC
    if (!Mmc_Fat_Init()) {
        // Reinitialize SPI at higher speed
        SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 4, _SPI_SS_DISABLE, \
        _SPI_DATA_SAMPLE_END, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);

        // Open resource file for read
        Mmc_Fat_Assign("WVL_GPS_.RES", 0);
        Mmc_Fat_Reset(&res_file_size);
    }
}
void Init_MCU() {
  // PMP setup
  PMMODE = 0;
  PMAEN  = 0;
  PMCON  = 0;               // WRSP: Write Strobe Polarity bit
  PMMODEbits.MODE = 2;      // master 2
  PMMODEbits.WAITB = 0;
  PMMODEbits.WAITM = 1;
  PMMODEbits.WAITE = 0;
  PMMODEbits.MODE16 = 1;    // 16 bit mode
  PMCONbits.CSF = 0;
  PMCONbits.PTRDEN = 1;
  PMCONbits.PTWREN = 1;
  PMCONbits.PMPEN = 1;

  TFT_Set_Default_Mode();
  STMPE610_SetDefaultMode();
  TFT_Set_MM_Plus();
}
void Initialize_TFT() {
  TFT_Set_Active(Set_Index, Write_Command, Write_Data);
  TFT_Init_SSD1963(480, 272);
  TFT_Set_DBC_SSD1963(255);
}
void Set_Index(unsigned short index) {
  TFT_RS = 0;
  PMDIN = index;
  while(PMMODEbits.BUSY);
  TFT_RS = 1;
}
void Write_Command( unsigned short cmd ) {
  TFT_RS = 1;
  PMDIN = cmd;
  while(PMMODEbits.BUSY);
}
void Write_Data(unsigned int _data) {
  PMDIN = _data;
  while(PMMODEbits.BUSY);
}
The file was copied onto the SD card.
All double/triple checked by doing the same thing using VTFT - where it all worked OK

Any advice on what I'm missing?

Regards Bill Legge
In Australia

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: Minimalist Code for MikromediaPlus for PIC32MX7

#7 Post by lana.arsic » 31 Oct 2017 18:30

Hi Bill,

Your function for initialization of SD card seems properly,
but in addition you can take a look in Resource_Collection_Demo example from the compiler,
particularly in functions TFT_Get_Data and TFT_Set_Ext_Buffer.

Kind regards,
Lana

Post Reply

Return to “Visual TFT General”