Hello everyone ,
I am trying to display RTC data on TFT display with Arduino uno..
I use the mcufriend library to show data on TFT display. All I need is correct only problem with RTC
data overlap on each other when ,I set rtc data and even it is continuing after whole procedure .
my full sketch is like these.....
[code]
#include <MCUFRIEND_kbv.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#define tft_CS A3
#define tft_CD A2
#define tft_WR A1
#define tft_RD A0
#define tft_RESET A4
#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 button1 10
#define button2 11
Adafruit_TFTLCD tft(tft_CS, tft_CD, tft_WR, tft_RD, tft_RESET);
void setup(void) {
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
delay(1000);
Wire.begin();
tft.reset();
tft.begin(0x9341);
tft.setRotation(3);
tft.fillScreen(BLACK);
}
char Time[] = " : : ";
char Calendar[] = " / /20 ";
byte i, second, minute, hour, day, date, month, year;
void display_day(){
switch(day){
case 1: draw_text(40, 0, " SUNDAY ", 1); break;
case 2: draw_text(40, 0, " MONDAY ", 1); break;
case 3: draw_text(40, 0, " TUESDAY ", 1); break;
case 4: draw_text(40, 0, "WEDNESDAY", 1); break;
case 5: draw_text(40, 0, "THURSDAY ", 1); break;
case 6: draw_text(40, 0, " FRIDAY ", 1); break;
default: draw_text(40, 0, "SATURDAY ", 1);
}
}
void DS1307_display(){
second = (second >> 4) * 10 + (second & 0x0F);
minute = (minute >> 4) * 10 + (minute & 0x0F);
hour = (hour >> 4) * 10 + (hour & 0x0F);
date = (date >> 4) * 10 + (date & 0x0F);
month = (month >> 4) * 10 + (month & 0x0F);
year = (year >> 4) * 10 + (year & 0x0F);
Time[7] = second % 10 + 48;
Time[6] = second / 10 + 48;
Time[4] = minute % 10 + 48;
Time[3] = minute / 10 + 48;
Time[1] = hour % 10 + 48;
Time[0] = hour / 10 + 48;
Calendar[9] = year % 10 + 48;
Calendar[8] = year / 10 + 48;
Calendar[4] = month % 10 + 48;
Calendar[3] = month / 10 + 48;
Calendar[1] = date % 10 + 48;
Calendar[0] = date / 10 + 48;
draw_text(4, 18, Calendar, 2);
draw_text(16, 42, Time, 2);
//draw_text(15, 180, Calendar, 2);
//draw_text(160, 420, Time, 2);
}
void blink_parameter(){
byte j = 0;
while(j < 10 && digitalRead(button1) && digitalRead(button2)){
j++;
delay(250);
}
}
byte edit(byte x_pos, byte y_pos, byte parameter){
char text[3];
sprintf(text,"%02u", parameter);
while(!digitalRead(button1));
while(true){
while(!digitalRead(button2)){
parameter++;
if(i == 0 && parameter > 31)
parameter = 1;
if(i == 1 && parameter > 12)
parameter = 1;
if(i == 2 && parameter > 99)
parameter = 0;
if(i == 3 && parameter > 23)
parameter = 0;
if(i == 4 && parameter > 59)
parameter = 0;
tft.fillScreen(BLACK);
sprintf(text,"%02u", parameter);
draw_text(x_pos, y_pos, text, 2);
delay(200);
}
draw_text(x_pos, y_pos, " ",2 );
blink_parameter();
draw_text(x_pos, y_pos, text, 2);
blink_parameter();
if(!digitalRead(button1)){
i++;
return parameter;
}
}
}
void draw_text(byte x_pos, byte y_pos, char *text, byte text_size) {
tft.setCursor(x_pos, y_pos);
tft.setTextSize(text_size);
tft.println(text);
}
void loop() {
if(!digitalRead(button1)){
i = 0;
while(!digitalRead(button1));
while(true){
while(!digitalRead(button2)){
day++;
if(day > 7) day = 1;
display_day();
delay(200);
}
draw_text(40, 0, " ", 2);
blink_parameter();
display_day();
blink_parameter();
if(!digitalRead(button1))
break;
}
date = edit(4, 18, date);
month = edit(40, 18, month);
year = edit(100, 18, year);
hour = edit(16, 42, hour);
minute = edit(52, 42, minute);
minute = ((minute / 10) << 4) + (minute % 10);
hour = ((hour / 10) << 4) + (hour % 10);
date = ((date / 10) << 4) + (date % 10);
month = ((month / 10) << 4) + (month % 10);
year = ((year / 10) << 4) + (year % 10);
Wire.beginTransmission(0x68);
Wire.write(0);
Wire.write(0);
Wire.write(minute);
Wire.write(hour);
Wire.write(day);
Wire.write(date);
Wire.write(month);
Wire.write(year);
Wire.endTransmission();
delay(200);
}
Wire.beginTransmission(0x68);
Wire.write(0);
Wire.endTransmission(false);
Wire.requestFrom(0x68, 7);
second = Wire.read();
minute = Wire.read();
hour = Wire.read();
day = Wire.read();
date = Wire.read();
month = Wire.read();
year = Wire.read();
// tft.fillScreen(BLACK);
display_day();
DS1307_display();
delay(50);
}
[/code]
I dont know where i am Wrong ...