Hi guys,
Just wondering if anyone could offer any advice, I'm using an arduuino Uno and the TFT shield by adafruit using their library: Overview | 2.8" TFT Touch Shield | Adafruit Learning System here. I'm also using a ds1307 module using the Arduino wire library. I am trying to get the LCD t display the time from the ds1307, the only problem is that when I call the getDateDs1307 function (currently commented out in the code) it stops the LCD from working and it just shows a white screen, however it correctly shows the time if I reset the screen after calling the function to get the time from the ds1307. Only problem is I only want to reset the screen once upon start, I don't want to initialise it every time!
Any help much appreciated!
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define DS1307_I2C_ADDRESS 0x68
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define PURPLE 0xF81F
#include "TFTLCD.h"
#include "Wire.h"
TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void setup(void) {
Wire.begin();
tft.initDisplay();
tft.setRotation(3);
tft.fillScreen(BLACK);
}
void loop(void) {
//getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
tft.setCursor(0, 0);
tft.setTextColor(GREEN);
tft.setTextSize(6);
tft.print(hour);
tft.print(":");
tft.print(minute);
tft.print(":");
tft.print(second);
delay(1000);
}