In case anyone is following this post I solved the problem. I don't remember where I got the library that I'm using and I don't remember if the class I named or the author named. In any case here is the header file, note that some functions I added.#ifndef __TFTSCREEN_H__
#define __TFTSCREEN_H__
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <limits.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdbool.h>
#include "colors_fonts.h"
#define CTR_PORT PORTF // Register where the control ports are located
#define CTR_DDR DDRF // To set up direction of the control ports
#define DATA_BUS PORTK // Register where bus data located
#define BUS_DDR DDRK // To set up direction of the bus pins
#define RST_PORT PORTF // Register where the reset pin is located
#define RST_DDR DDRF // To set up direction of the reset pin
#define READ_PORTK PINK // To read values of the register D
// Below are described the pins used for the data bus on the LCD
#define LCD_D2 PK2
#define LCD_D3 PK3
#define LCD_D4 PK4
#define LCD_D5 PK5
#define LCD_D6 PK6
#define LCD_D7 PK7
#define LCD_D0 PK0
#define LCD_D1 PK1
#define LCD_RST PF3 //Screen hardware reset
#define LCD_CS PF4 // Chip select, making this H will cause the chip not to respond to commands or data
#define LCD_RS PF5 // This is the C/D (command or data) selection
#define LCD_WR PF6 // Write pin
#define LCD_RD PF7 // Read pin
#define TFTHEIGHT 240
#define TFTWIDTH 320
#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
#define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
class TFTScreen
{
//variables
public:
protected:
GFXfont *gfxFont;
bool wrap; // If set, 'wrap' text at right edge of display
bool _cp437; // If set, use correct CP437 charset (default is off)
private:
volatile uint16_t cursor_x;
volatile uint16_t cursor_y;
volatile uint16_t textcolour;
volatile uint16_t textbgcolour;
volatile uint8_t textsize;
uint16_t vsetx,vsety,vactualx,vactualy,isetx,isety,iactualx,iactualy;
uint16_t LCD_W;
uint16_t LCD_H;
/* Parameters to be displayed at the screens */
bool celsFar; // True display in Celsius, false display in Fahrenheit.
float tempHeatSink; // This maintains the last measured temperature of the heat sink
float tempCase; // This maintains the last measured temperature of the enclosure
//Basic functions
public:
TFTScreen();
~TFTScreen();
void setCursor(uint16_t x,uint16_t y);
void setTextColour(uint16_t x,uint16_t y);
void setTextSize(uint8_t s);
void write(uint8_t c);
void writeString(const char *strLine);
void screenInit(void);
void clear(uint16_t colour);
void setRotation(uint8_t x);
void pushColour(uint16_t colour);
void drawChar(int16_t x, int16_t y, unsigned char c,uint16_t color, uint16_t bg, uint8_t size);
void drawPixel(uint16_t x3,uint16_t y3,uint16_t colour1);
void drawLine(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1, uint16_t color);
void fillRect(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint16_t colour);
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void cp437(bool x=true);
void setFont(const GFXfont *f = NULL);
protected:
private:
TFTScreen( const TFTScreen &c );
TFTScreen& operator=( const TFTScreen &c );
void hard_init(void);
void writeCommand8(uint8_t com);
void writeData8(uint8_t data);
void setAddress(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
void hard_reset(void);
void backupLocationVset(void);
void backupLocationVactual(void);
void backupLocationIset(void);
void backupLocationIactual(void);
int celsToFar(float temp);
// Display functions
public:
void screen1(void); // This is the main working display
void showHeatTemp(uint16_t temp);
void showCaseTemp(uint16_t temp);
void showHeatFan(bool onOff);
void showCaseFan(bool onOff);
}; //TFTScreen
#endif //__TFTSCREEN_H__
The problem was with the initial setup of the font, the function setFont() was not called any where. For the basic font variable GFXfont need to be setup to NULL. I'm guessing that when the program was put in memory by the programmer the memory space pointed by the variable was an empty space, but after power down the chip that piece of memory had garbage and the program go lost trying to print characters.
The solution was to call setFont(NULL) when the constructor of the class was called.