本帖最后由 水镜 于 2015-10-21 13:03 编辑
5110屏直插arduino主板+3231简单时钟显示程序。
// 提示:程序要下载二次,如果3231时间调整好的,只需要下载一次。
#include <LCD5110_Graph.h>
#include <DS3231.h>
// ----------Init the DS3231 using the hardware interface------------3231
DS3231 rtc(SDA, SCL);//sda接A4口,scl接A5口
// ---------- 5110的RST从第8口开始,直接插入,最后一个为第12口。------------5110
LCD5110 myGLCD(12,11,10,8,9);//GND,BL,VCC,CLK,DIN,DC,CE,RST
extern uint8_t SmallFont[];
void setup()
{
myGLCD.InitLCD();
// Initialize the rtc object
rtc.begin();
// 程序要下载二次,第一次设置3231时间,看好电脑时间,提前9秒左右,下载进入主板。第二次取消时间设置后,再下载一次程序。否则重启永远设置一个固定时间。
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(11,55,30); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(21, 10, 2015); // Set the date to January 1st, 2014
// ----------Init the DS3231 using the hardware interface------------3231
}
void loop()
{
myGLCD.setFont(SmallFont);
myGLCD.clrScr();
//第一行显示日,月,年。
myGLCD.print(rtc.getDateStr() , CENTER, 0);
// 第二行显示周。
myGLCD.print(rtc.getDOWStr() , CENTER,12);
//第三行 时分秒
myGLCD.print(rtc.getTimeStr(), CENTER, 24);
//第四行画一线
myGLCD.print("--------------",CENTER, 34);
myGLCD.print("Temper:", LEFT, 40);//第五行 温度
myGLCD.printNumI( rtc.getTemp(), 55, 40);
myGLCD.print("C", 70, 40);
myGLCD.update();
//delay(1000);//1秒显示一次。
}
图片: http://user.qzone.qq.com/82399070/2
|