I have a sketch that I worked out almost a year ago that worked on my Uno-and still does. I had bought a cheap 2.8" TFT display that I eventually got going with the Adafruit_GFX and Adafruit_TFTLCD libraries, before pin_magic.h and registers.h were part of the deal…
Now, I’ve finished my first “arduino compatable” board, using a Atmega2561 running Megacore. The pin assignments are quite different from the Uno, and I need to redefine them for the LCD-as the LCD is the only thing that will be plugged into the shield pinout on the board, eveything else is just brought out as seperate headers.
Now, in my old sketch, the control lines are defined-but the data lines aren’t defined, and I think in the TFTLCD library, they are not done using digitalWrite() methods but instead using direct AVR port calls. In effect…the libraries are hardwired for this LCD to be used on an Uno or Uno-compatable…which mine is not.
The below is my currently running Uno code:
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
//Define the LCD control lines
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
//Define some colors:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//configuring the data lines for tft library
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup(void) {
// setting up the serial console monitor
Serial.begin(9600);
Serial.println("serial console works");
tft.reset(); //reset the display
tft.begin(0x9341); //start up the display
Serial.println("started the display, boss");
}
void loop(void) {
tft.setRotation(3); //landscape mode with data pins on the top and address lines on the bottom
tft.fillScreen(BLACK); //this cleared the screen, but it did it every loop through-so display flickered for redraw
//Filter Indicator
tft.setCursor(6,6);
tft.setTextColor(CYAN, BLACK);
tft.setTextSize(2);
tft.println("6Khz Filter");
//tft.println("3Khz Filter");
//Band Indicator, display indicated band
tft.setCursor(6,25);
tft.setTextColor(CYAN, BLACK);
tft.setTextSize(2);
tft.println("40M Band");
//tft.println("20M band");
//tft.println("10M Band");
//tft.println("6M Band");
//Memory Indicator
tft.setCursor(220,6);
tft.setTextColor(CYAN, BLACK);
tft.setTextSize(2);
tft.println("Memory A"); //replace A with A/B/C for whichever stored frequency is in position A/B/C
//Setup Main TX Tuning Display
tft.setCursor(6, 80); //Don't get closer than "6" from the edge, it's too close.
tft.setTextColor(RED, BLACK);
tft.setTextSize(2); //text size 2 is about 3/16" tall
tft.println("TX");
tft.setCursor(60, 80);
tft.setTextColor(GREEN, BLACK);
tft.setTextSize(3); //text size 4 is about 1/4" tall
tft.println("Mhz"); //Make the "123" the Transmit Mhz tuning, "456" the Transmit khz tuning, and "789" the Transmit hz tuning later
tft.setCursor(110, 80);
tft.println("."); //seperator
tft.setCursor(128, 80);
tft.println("Khz"); //Khz tuning
tft.setCursor(180, 80);
tft.println("."); //seperator
tft.setCursor(198, 80);
tft.println("hz_"); //hz tuning
tft.setCursor(280, 80);
tft.setTextColor(YELLOW, BLACK);
tft.setTextSize(2);
tft.println("MHz");
//Setup Main RX Tuning Display
tft.setCursor(6, 136); //Don't get closer than "6" from the edge, it's too close.
tft.setTextColor(RED, BLACK);
tft.setTextSize(2); //text size 2 is about 3/16" tall
tft.println("RX");
tft.setCursor(60, 130);
tft.setTextColor(GREEN, BLACK);
tft.setTextSize(3); //text size 4 is about 1/4" tall
tft.println("123"); //Make the "123" the Recive Mhz tuning, "456" the Recieve khz tuning, and "789" the Recieve hz tuning later
tft.setCursor(110, 130);
tft.println("."); //seperator
tft.setCursor(128, 130);
tft.println("456"); //Khz tuning
tft.setCursor(180, 130);
tft.println("."); //seperator
tft.setCursor(198, 130);
tft.println("789"); //hz tuning
tft.setCursor(280, 136);
tft.setTextColor(YELLOW, BLACK);
tft.setTextSize(2);
tft.println("MHz");
//Setup to display Mode Indication, select only one at a time
tft.setCursor(40, 180);
tft.setTextColor(CYAN,BLACK);
tft.setTextSize(3);
tft.println("LSB");
//tft.setCursor(40, 180);
//tft.setTextColor(CYAN,BLACK);
//tft.setTextSize(3);
//tft.println("AM");
//tft.setCursor(40, 180);
//tft.setTextColor(CYAN,BLACK);
//tft.setTextSize(3);
//tft.println("USB");
delay(5000); //slow the redraw flicker down for testing
}
and all it does is draw on the screen-no actual work yet. I’d like to at least get back to this point with the new board, but I’m at a loss as to how I’d have to do it.
Here’s how the display is connected to my current board; I hope it can be made to work! If not, well…I’ll trash the first 10 boards and start over.
Port-Uno shield-Pin defined in Megacore
PG1 A0 27
PC0 A1 28
PC1 A2 29
PC2 A3 30
PC3 A4 31
PC4 A5 32
PC5 D2 33
PC6 D3 34
PC7 D4 35
PG2 D5 36
PA7 D6 37
PA6 D7 38
PA5 D8 39
PA4 D9 40
PA3 D10 41
PA2 D11 42
PA1 D12 43
PA0 D13 44
Is there any hope? Have I just royally screwed up?