1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| #include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DS1302.h>
// Set the LCD address to 0x3F for a 16 chars and 2 line display // note: it may be different for your LCD please find it.
LiquidCrystal_I2C lcd(0X27, 16, 2);
#include <DS1302.h>
// Init the DS1302
DS1302 rtc(2, 3, 4);
// Init a Time-data structure
Time t;
void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
// The following lines can be commented out to use the values already stored in the DS1302
rtc.setDOW(TUESDAY); // Set Day-of-Week to TUESDAY
rtc.setTime(9, 14, 50); // Set the time to 24hr format it will automatically take time according to AM/PM
rtc.setDate(04, 4, 2020); // Set the date to Febrauray 6th, 2018
// initialize the LCD
lcd.begin();
}
void loop()
{
// Get data from the DS1302
t = rtc.getTime();
lcd.setCursor(0, 0);
if (t.date<=9){
lcd.setCursor(0,0);
lcd.print("0");
lcd.setCursor(1,0);
lcd.print(t.date, DEC);
}
else {
lcd.print(t.date, DEC);}
lcd.setCursor(3, 0);
lcd.print(rtc.getMonthStr());
lcd.setCursor(12,0);
lcd.print(t.year, DEC);
lcd.setCursor(4,1);
{if (t.hour>=12){
lcd.setCursor(13,1);
lcd.print("PM");
lcd.setCursor(4,1);
t.hour = t.hour-12;
if (t.hour== 0) {
t.hour = 12; // Day 12 PM
}
if (t.hour<=9){
lcd.setCursor(4,1);
lcd.print("0");
lcd.setCursor(5,1);
lcd.print(t.hour, DEC);
}
else {
lcd.print(t.hour, DEC);}}
else { if(t.hour==0){
t.hour=12; // Night 12 AM
}
lcd.setCursor(13,1);
lcd.print("AM");
lcd.setCursor(4,1);
if (t.hour<=9){
lcd.setCursor(4,1);
lcd.print("0");
lcd.setCursor(5,1);
lcd.print(t.hour, DEC);
}
else {
lcd.print(t.hour, DEC);}} }
lcd.setCursor(6,1);
lcd.print(":");
lcd.setCursor(7,1);
if (t.min<=9){
lcd.setCursor(7,1);
lcd.print("0");
lcd.setCursor(8,1);
lcd.print(t.min, DEC);
}
else {
lcd.print(t.min, DEC);}
lcd.setCursor(9,1);
lcd.print(":");
lcd.setCursor(10,1);
if (t.sec<=9){
lcd.setCursor(10,1);
lcd.print("0");
lcd.setCursor(11,1);
lcd.print(t.sec, DEC);
}
else {
lcd.print(t.sec, DEC);}
delay (1000);
lcd.clear();
} |
Partager