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 //
} //
////////////////////////////////////////////////////////////////////////////////