|
楼主 |
发表于 2020-12-24 10:40
|
显示全部楼层
#include <Wire.h>
#include <DS3231.h>
#include <LiquidCrystal.h>
DS3231 Clock;
bool h12,PM,Century=false;
byte year,month,date,DoW,hour,minute,second;
LiquidCrystal lcd(12,3,7,8,9,10);
void setup() {
Wire.begin();
Clock.setSecond(50);
Clock.setMinute(59);
Clock.setHour(11);
Clock.setDoW(5);
Clock.setDate(31);
Clock.setMonth(5);
Clock.setYear(13);
}
void Pritime()
{
int second,minute,hour,date,month,year,dow,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12,PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();
dow=Clock.getDoW();
temperature=Clock.getTemperature();
lcd.setCursor(0,0);
lcd.print("20");
if(year>=10)
{
lcd.print(year,DEC);
}
else
{
lcd.print("0");
lcd.print(year,DEC);
}
lcd.print('-');
lcd.setCursor(5,0);
if (month>=10)
{
lcd.print(month,DEC);
}
else
{
lcd.print("0");
lcd.print(month,DEC);
}
lcd.print('-');
lcd.setCursor(8,0);
if(date>=10)
{
lcd.print(date,DEC);
}
else
{
lcd.print("0");
lcd.print(date,DEC);
}
lcd.setCursor(11,0);
switch (dow)
{
case 1:
lcd.print("Mon");
break;
case2:
lcd.print("Tue");
break;
case 3:
lcd.print("Wed");
break;
case 4:
lcd.print("Thu");
break;
case 5:
lcd.print("Fri");
break;
case 6:
lcd.print("Sat");
break;
case 7:
lcd.print("Sun");
break;
}
lcd.setCursor(0,1);
if (hour>=10)
{
lcd.print(hour,DEC);
}
else
{
lcd.print("0");
lcd.print(hour,DEC);
}
lcd.print(':');
lcd.setCursor(3,1);
if(minute>=10)
{
lcd.print(minute,DEC);
}
else
{
lcd.print("0");
lcd.print(minute,DEC);
}
lcd.print(':');
lcd.setCursor(6,1);
if(second>=10)
{
lcd.print(second,DEC);
}
else
{
lcd.print("0");
lcd.print(second,DEC);
}
lcd.setCursor(12,1);
lcd.print(temperature);
lcd.write(0xdf);
lcd.print("C");
}
void Tictime() {
lcd.setCursor(2,1);
lcd.print(' ');
lcd.setCursor(5,1);
lcd.print(' ');
}
void loop()
{
unsigned long Rt=millis()%1000;
if(Rt<500)
{
Pritime();
}
else
{
Tictime();
}
}
]改了这样后为什么上传总是出错 |
|