很想要個時鐘模塊,自己焊又太麻煩,干脆在TB上買下來了,省時。
模塊參數:
1.尺寸:38mm(長)*22mm(寬)*14mm(高)
2.重量:8g
3.工作電壓:3.3--5.5V
4.時鐘芯片:高精度時鐘芯片DS3231
5.時鐘精度:0-40℃范圍內,精度2ppm,年誤差約1分鐘
6.帶2個日歷鬧鐘
7.可編程方波輸出
8.實時時鐘產生秒、分、時、星期、日期、月和年計時,并提供有效期到2100年的閏年補償
9.芯片內部自帶溫度傳感器,精度為±3℃
10.存儲芯片:AT24C32(存儲容量32K)
11.IIC總線接口,最高傳輸速度400KHz(工作電壓為5V時)
12.可級聯其它IIC設備,24C32地址可通過短路A0/A1/A2修改,默認地址為0x57
13.帶可充電電池LIR2032,保證系統斷電后,時鐘任然正常走動
接線說明,以Arduino uno r3為例:
SCL→A5
SDA→A4
VCC→5V
GND→GND
代碼部分:
#include <DS3231.h>
#include <Wire.h>
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
byte year, month, date, DoW, hour, minute, second;
void setup() {
// 啟動I2C(IIC)接口
Wire.begin();
//以下部分是初始化時間,每次板子通電之后都會初始化成這個時間,只是測試用,以后可以刪除。
Clock.setSecond(50);//Set the second
Clock.setMinute(59);//Set the minute 設置分鐘
Clock.setHour(11); //Set the hour 設置小時
Clock.setDoW(5); //Set the day of the week 設置星期幾
Clock.setDate(31); //Set the date of the month 設置月份
Clock.setMonth(5); //Set the month of the year 設置一年中的月份
Clock.setYear(13); //Set the year (Last two digits of the year) 設置年份(在今年的最后兩位數——比如2013年最后的13)
// Start the serial interface
Serial.begin(115200);
}
void ReadDS3231()
{
int second,minute,hour,date,month,year,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12, PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();
temperature=Clock.getTemperature();
Serial.print("20");
Serial.print(year,DEC);
Serial.print('-');
Serial.print(month,DEC);
Serial.print('-');
Serial.print(date,DEC);
Serial.print(' ');
Serial.print(hour,DEC);
Serial.print(':');
Serial.print(minute,DEC);
Serial.print(':');
Serial.print(second,DEC);
Serial.print('\n');
Serial.print("Temperature="); //這里是顯示溫度
Serial.print(temperature);
Serial.print('\n');
}
void loop()
{
ReadDS3231();
delay(1000); //間隔1000ms(1000ms=1秒)循環一次。
}