TFT displaying Images

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
Dakta
Posts: 53
Joined: 07 Sep 2013 16:08

TFT displaying Images

#1 Post by Dakta » 04 Jun 2023 11:27

I don't have VTFT at the moment but would like to display an image if possibe in my PIC32 project using the Easypic fusion v7 board

It's only a test project as Im learning the TFT library, I have got the screen working in every aspect except images.

Is the following concept look right?

Code: Select all

//tft variables
unsigned short TFT_DataPort at LATE;
sbit TFT_WR at LATD4_bit;
sbit TFT_RD at LATD5_bit;
sbit TFT_CS at LATD10_bit;
sbit TFT_RS at LATD9_bit;
sbit TFT_RST at LATD7_bit;
//TFT PORT DIRECTIONS
unsigned short TFT_DataPort_Direction at TRISE;
sbit TFT_WR_Direction at TRISD4_bit;
sbit TFT_RD_Direction at TRISD5_bit;
sbit TFT_CS_Direction at TRISD10_bit;
sbit TFT_RS_Direction at TRISD9_bit;
sbit TFT_RST_Direction at TRISD7_bit;

const unsigned int imagedata[] = {
0x0000, 0x3186, 0x3186, 0x3186....};

void main() {
//disable analog
ANSELA = 0x00;  ANSELB = 0x00;
ANSELC = 0x00; ANSELD = 0x00;
ANSELE = 0x00; ANSELF = 0x00;
ANSELG = 0x00;  ANSELH = 0x00;
TFT_Init_ILI9341_8bit(240, 320);

TFT_Fill_Screen(CL_GREEN);

TFT_Line(0,0,240,320);

delay_ms(2000);

TFT_Image(0, 0, imagedata, 1);

while(1){}
}


The image doesn't display but does display the line and screen fill so it's initialised and working. so I must be misunderstanding the purpose or how to use the tft_image function.

Any ideas where I am going wrong?

TIA

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

Re: TFT displaying Images

#2 Post by Bill Legge » 05 Jun 2023 22:23

I'm far from expert but I've attached some code that uses a TFT on the EasyPICFusionV7 board.
The MCU is PIC32Mx795F512L running at 80MHz.
A few thoughts:
1. You do not need VTFT to run simple projects but it's a great help with more complicated work. However it's not easy sailing.
2. The demo code should work OK - have you tried it?
4. Note the pins that drive the TFT and ensure you are not trying to use them for something else.
5. Take care of the 'Edit Project' settings, The PIC32 MCU's do need the config bits set properly (usually div2 followed by X20 to get 80HMz)

Regards Bill Legge in Australia

Code: Select all

////////////////////////////////////////////////////////////////////////////////
// Project:         WVL_Fusion_TFT_Basic                                      //
// File:            main.c                                                    //
// Function:        Standard template for PIC32 with TFT                      //
// MCU:             P32MX795F512L                                             //
// Board:           EasyPIC_Fusion_v7_for_PIC32                               //
// Power            3.3V                                                      //
// Compiler:        mikroC PRO for PIC32 V.3.5.0                              //
// Oscillator:      80,000,000 Hz                                             //
// Programmer:      On-board Mikro                                            //
// Author:          WVL                                                       //
// Date:            Mar 2016                                                  //
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
#include <built_in.h>                                                         //
#define  SCOPE      LATA1_bit                                                 //
#define  HEARTBEAT  LATG0_bit=~LATG0_bit                                      //
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// TFT module connections                                                     //
char TFT_DataPort at LATE;                                                    //
sbit TFT_RST at LATD7_bit;                                                    //
sbit TFT_BLED at LATD2_bit;                                                   //
sbit TFT_RS at LATD9_bit;                                                     //
sbit TFT_CS at LATD10_bit;                                                    //
sbit TFT_RD at LATD5_bit;                                                     //
sbit TFT_WR at LATD4_bit;                                                     //
char TFT_DataPort_Direction at TRISE;                                         //
sbit TFT_RST_Direction at TRISD7_bit;                                         //
sbit TFT_BLED_Direction at TRISD2_bit;                                        //
sbit TFT_RS_Direction at TRISD9_bit;                                          //
sbit TFT_CS_Direction at TRISD10_bit;                                         //
sbit TFT_RD_Direction at TRISD5_bit;                                          //
sbit TFT_WR_Direction at TRISD4_bit;                                          //
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
void WVL_ADC_Init();    //Function to init ADC, takes 4.3uS                   //                                      
////////////////////////////////////////////////////////////////////////////////

void main() {
    // Block variables
    unsigned int          loop = 0;
    unsigned int      old_loop = 0;
    unsigned int ADC_reading_1 = 0;
    unsigned int ADC_reading_2 = 0;
    unsigned char  txt1[6];            // for conversion unsigned int to string
    unsigned char  txt2[6];            // for conversion unsigned int to string
    unsigned char  txt3[6];            // for conversion unsigned int to string
    // Init MCU
    JTAGEN_bit = 0;                    // disable JTAG
    AD1PCFG = 0xFFFD;                  // Configure AN pins as digital I/O. RB0 and RB1 are analog
    UART2_Init(57600);                 // on RF4 and RF5
    // Init pins
    TRISA = 0;                         // scope output and leds
    TRISG = 0;                         // heartbeat
    LATA  = 0;
    TRISB0_bit = 1;                    // input for ADC
    TRISB1_bit = 1;                    // input for ADC
    // Init ADC
    WVL_ADC_Init();
    // Init TFT
    // TFT_Init(320, 240);             // old TFT controller
    TFT_Init_ILI9341_8bit(320, 240);   // new TFT controller Jan 2019
    Delay_ms(100);
    TFT_BLED = 1;
    // Draw
    TFT_Fill_Screen(CL_YELLOW);
    TFT_Set_Pen(CL_Black, 1);
    TFT_Line(0,2,320,2);
    TFT_Set_Font(&TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
    TFT_Write_Text("WVL_Fusion_TFT_Basic", 3, 10);
        
    while(1){
        // Get new readings
        SCOPE = 1;                               // pin must be an output
        ADC_reading_1 = ADC1_Get_Sample(0);      // requires pre-init of ADC module
        ADC_reading_2 = ADC1_Get_Sample(1);
        SCOPE = 0;
          
        TFT_Fill_Screen(CL_YELLOW);

        // Display new readings
        WordToStr(ADC_reading_1, txt1); // TFT only displays strings
        WordToStr(ADC_reading_2, txt2); // TFT only displays strings
        TFT_Write_Text(txt1,3,160);     // write in blue
        TFT_Write_Text(txt2,100,160);   // write in blue
        WordToStr(loop,txt3);
        TFT_Write_Text(txt3,3,200);
        
        // Update counters
        old_loop = loop;
        loop++;
        
        // Housekeeping
        delay_ms(200);
        HEARTBEAT;
    }
}

////////////////////////////////////////////////////////////////////////////////
// Function - WVL ADC                                                         //
// Time of ACD                                                                //
// ADC can use the internal RC clock or the PB(default), selected AD1CON3.ADRC//
// WVL uses PB for ADC                                                        //
// Tpb = Tosc = 1000,000,000/80MHz = 12.5nS                                   //
// Tad = Tpb*2*(ADCS<7:0>+1).   ADCS is in register AD1CON3                   //
// Default sets Tad = 2*Tpb = 25nS in AD1CON3.SAMC<4:0>                       //
// For correct operation Tad>83.33nS.  Section 17.4 in ref manual             //
// So Tad must be increased by a factor of 83.33/(2*12.5) = 3.33 so use 4     //
// Do this by making AD1CON3.ADCS = 3                                         //
// Now Tad = Tpb*2*(3+1) = 12.5 * 2 * 4 = 100nS                               //
// Total time of ADC = Acquisition time + Conversion time                     //
// Calculating Acquisition time - time to charge capacitor.                   //
// Max 'self-time' is 32*Tad = 32*100 = 3.2uS                                 //
// Function to init ADC, takes 4.3uS                                          //
void WVL_ADC_Init(){                                                          //
    AD1CON1          = 0x00E0;     // automatic conversion after sampling     //
    AD1CSSL          = 0;          // no scanning needed                      //
    AD1CON2          = 0;          // use MUXA, Vdd and Vss                   //
    AD1CON3          = 0x1F02;     // use PB, 32Tad, Tad=(2+1)*Tpb            //
    ON__AD1CON1_bit  = 1;          // ADC1 on, note double underline          //
}                                                                             //
////////////////////////////////////////////////////////////////////////////////
Last edited by Bill Legge on 07 Jun 2023 08:08, edited 1 time in total.

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

Re: TFT displaying Images

#3 Post by Bill Legge » 05 Jun 2023 22:28

Sorry - I've just read your post in detail and noted that you have a problem with IMAGES.
Download the free code from the Mikro Site: 'VTFT RES File Creator.
It will take your image (jpeg bitmap etc) and create the necessay code to insert in your program.
Although called VFTF it will 'stand alone.'

Good luck

Dakta
Posts: 53
Joined: 07 Sep 2013 16:08

Re: TFT displaying Images

#4 Post by Dakta » 06 Jun 2023 22:41

Not a problem, Bill - thank you very much - that resolved the issue!

Post Reply

Return to “mikroC PRO for PIC32 General”