//Modified Sketch by KB1UIF (A.Tedds.) (c) 2015. //Written for the RTC and 2.4" TFT LCD Display //Using the ILI9341 8bit Display from Banggood.com //Using DS3231 Real Time Clock Module from Banggood.com //Thanks to the modified Adafruit Libraries. //Thanks also to the Original Author of the RTC Sketch for 2 Line Liquid Crystal Display. #include //Used for RTC device communications SDA SCL Pins 20,21 on the Mega. #include // Library for thr DS3231 RTC Chip. #include // Core graphics library. #include // Hardware-specific library. #define LCD_CS A3 // Chip Select goes to Analog 3 #define LCD_CD A2 // Command/Data goes to Analog 2, Labled LCD_RS #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 BUFF_MAX 128 #define BLACK 0xFFFF #define BLUE 0xFFE0 #define GREEN 0xF81F #define CYAN 0xF800 #define GRAY1 0x8410 #define RED 0x07FF #define GRAY2 0x4208 #define MAGENTA 0x07E0 #define YELLOW 0x001F #define WHITE 0x0000 Adafruit_ILI9341_8bit_AS tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); uint8_t time[8]; char recv[BUFF_MAX]; unsigned int recv_size = 0; unsigned long prev, interval =1000; void setup() { Serial.begin(9600); Wire.begin(); DS3231_init(DS3231_INTCN); memset(recv, 0, BUFF_MAX); Serial.println("GET time"); //tft.fillScreen(BLACK); //tft.reset(); //delay(10); tft.begin(0x9341); tft.fillScreen(BLACK); tft.setRotation(3); tft.setTextColor(BLUE); tft.setTextSize(3); //Only use these next 2 lines once to set the RTC module. //Serial.println("Setting time"); //parse_cmd("T005804712072015",16); //TssmmhhDddmmyyyy For D Sat=6 } void loop() { // char in; // char tempF[6]; // float temperature; // char buff[BUFF_MAX]; // unsigned long now = millis(); // struct ts t; // // // show time once in a while // if ((now - prev > interval) && (Serial.available() <= 0)) { // DS3231_get(&t); //Get time // parse_cmd("C",1); // temperature = DS3231_get_treg(); //Get temperature // dtostrf(temperature, 5, 1, tempF); // // tft.fillScreen(BLACK); // tft.setCursor(30, 35); // tft.setTextSize(3); // tft.print(t.mday); // Serial.print(t.mday); // Serial.print("/"); // // printMonth(t.mon); // Serial.print(t.mon); // Serial.print("/"); // tft.print(t.year); // Serial.print(t.year); // Serial.print(" "); // tft.println(" "); // tft.setTextSize(4); // tft.println(" "); // tft.print(" "); // tft.print(t.hour); // Serial.print(t.hour); // tft.print(":"); // Serial.print(":"); // if(t.min<10) // { // tft.print("0"); // } // tft.print(t.min); // Serial.print(t.min); // tft.print(":"); // Serial.print(":"); // if(t.sec<10) // { // tft.print("0"); // } // tft.println(t.sec); // tft.println(" "); // Serial.print(t.sec); // Serial.print(" "); // // tft.print(" "); // tft.print(tempF); // tft.print(" "); for (int a=0; a<255; a++) { //tft.autoscroll(); tft.setCursor(0,0); tft.print(a); tft.print(" "); tft.print((char)(a)); delay(1000); tft.fillScreen(BLACK); } // tft.print("C "); // prev = now; // } // // // if (Serial.available() > 0) { // in = Serial.read(); // // if ((in == 10 || in == 13) && (recv_size > 0)) { // parse_cmd(recv, recv_size); // recv_size = 0; // recv[0] = 0; // } else if (in < 48 || in > 122) {; // ignore ~[0-9A-Za-z] // } else if (recv_size > BUFF_MAX - 2) { // drop lines that are too long // // drop // recv_size = 0; // recv[0] = 0; // } else if (recv_size < BUFF_MAX - 2) { // recv[recv_size] = in; // recv[recv_size + 1] = 0; // recv_size += 1; // } // // } //} // //void parse_cmd(char *cmd, int cmdsize) //{ // uint8_t i; // uint8_t reg_val; // char buff[BUFF_MAX]; // struct ts t; // // //snprintf(buff, BUFF_MAX, "cmd was '%s' %d\n", cmd, cmdsize); // //Serial.print(buff); // // // TssmmhhWDDMMYYYY aka set time // if (cmd[0] == 84 && cmdsize == 16) { // //T004218611072015 // t.sec = inp2toi(cmd, 1); // t.min = inp2toi(cmd, 3); // t.hour = inp2toi(cmd, 5); // t.wday = inp2toi(cmd, 7); // t.mday = inp2toi(cmd, 8); // t.mon = inp2toi(cmd, 10); // t.year = inp2toi(cmd, 12) * 100 + inp2toi(cmd, 14); // DS3231_set(t); // Serial.println("OK"); // } else if (cmd[0] == 49 && cmdsize == 1) { // "1" get alarm 1 // DS3231_get_a1(&buff[0], 59); // Serial.println(buff); // } else if (cmd[0] == 50 && cmdsize == 1) { // "2" get alarm 1 // DS3231_get_a2(&buff[0], 59); // Serial.println(buff); // } else if (cmd[0] == 51 && cmdsize == 1) { // "3" get aging register // Serial.print("aging reg is "); // Serial.println(DS3231_get_aging(), DEC); // } else if (cmd[0] == 65 && cmdsize == 9) { // "A" set alarm 1 // DS3231_set_creg(DS3231_INTCN | DS3231_A1IE); // //ASSMMHHDD // for (i = 0; i < 4; i++) { // time[i] = (cmd[2 * i + 1] - 48) * 10 + cmd[2 * i + 2] - 48; // ss, mm, hh, dd // } // byte flags[5] = { 0, 0, 0, 0, 0 }; // DS3231_set_a1(time[0], time[1], time[2], time[3], flags); // DS3231_get_a1(&buff[0], 59); // Serial.println(buff); // } else if (cmd[0] == 66 && cmdsize == 7) { // "B" Set Alarm 2 // DS3231_set_creg(DS3231_INTCN | DS3231_A2IE); // //BMMHHDD // for (i = 0; i < 4; i++) { // time[i] = (cmd[2 * i + 1] - 48) * 10 + cmd[2 * i + 2] - 48; // mm, hh, dd // } // byte flags[5] = { 0, 0, 0, 0 }; // DS3231_set_a2(time[0], time[1], time[2], flags); // DS3231_get_a2(&buff[0], 59); // Serial.println(buff); // } else if (cmd[0] == 67 && cmdsize == 1) { // "C" - get temperature register // Serial.print("temperature reg is "); // Serial.println(DS3231_get_treg(), DEC); // } else if (cmd[0] == 68 && cmdsize == 1) { // "D" - reset status register alarm flags // reg_val = DS3231_get_sreg(); // reg_val &= B11111100; // DS3231_set_sreg(reg_val); // } else if (cmd[0] == 70 && cmdsize == 1) { // "F" - custom fct // reg_val = DS3231_get_addr(0x5); // Serial.print("orig "); // Serial.print(reg_val,DEC); // Serial.print("month is "); // Serial.println(bcdtodec(reg_val & 0x1F),DEC); // } else if (cmd[0] == 71 && cmdsize == 1) { // "G" - set aging status register // DS3231_set_aging(0); // } else if (cmd[0] == 83 && cmdsize == 1) { // "S" - get status register // Serial.print("status reg is "); // Serial.println(DS3231_get_sreg(), DEC); // } else { // Serial.print("unknown command prefix "); // Serial.println(cmd[0]); // Serial.println(cmd[0], DEC); // } //} // //void printMonth(int month) //{ // switch(month) // { // case 1: tft.print(" January ");break; // case 2: tft.print(" February ");break; // case 3: tft.print(" March ");break; // case 4: tft.print(" April ");break; // case 5: tft.print(" May ");break; // case 6: tft.print(" June ");break; // case 7: tft.print(" July ");break; // case 8: tft.print(" August ");break; // case 9: tft.print(" September ");break; // case 10: tft.print(" October ");break; // case 11: tft.print(" November ");break; // case 12: tft.print(" December ");break; // default: tft.print(" Error ");break; // } }