欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

專(zhuān)注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> Arduino >> 瀏覽文章

Arduino驅(qū)動(dòng)DS3231高精度時(shí)鐘模塊

作者:huqin   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2014年04月03日   【字體:

很想要個(gè)時(shí)鐘模塊,自己焊又太麻煩,干脆在TB上買(mǎi)下來(lái)了,省時(shí)。

  模塊參數(shù):
  1.尺寸:38mm(長(zhǎng))*22mm(寬)*14mm(高)
  2.重量:8g
  3.工作電壓:3.3--5.5V
  4.時(shí)鐘芯片:高精度時(shí)鐘芯片DS3231
  5.時(shí)鐘精度:0-40℃范圍內(nèi),精度2ppm,年誤差約1分鐘
  6.帶2個(gè)日歷鬧鐘
  7.可編程方波輸出
  8.實(shí)時(shí)時(shí)鐘產(chǎn)生秒、分、時(shí)、星期、日期、月和年計(jì)時(shí),并提供有效期到2100年的閏年補(bǔ)償
  9.芯片內(nèi)部自帶溫度傳感器,精度為±3℃
  10.存儲(chǔ)芯片:AT24C32(存儲(chǔ)容量32K)
  11.IIC總線接口,最高傳輸速度400KHz(工作電壓為5V時(shí))
  12.可級(jí)聯(lián)其它IIC設(shè)備,24C32地址可通過(guò)短路A0/A1/A2修改,默認(rèn)地址為0x57
  13.帶可充電電池LIR2032,保證系統(tǒng)斷電后,時(shí)鐘任然正常走動(dòng)

 

接線說(shuō)明,以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() {
 // 啟動(dòng)I2C(IIC)接口
 Wire.begin();
        //以下部分是初始化時(shí)間,每次板子通電之后都會(huì)初始化成這個(gè)時(shí)間,只是測(cè)試用,以后可以刪除。
        Clock.setSecond(50);//Set the second
        Clock.setMinute(59);//Set the minute 設(shè)置分鐘
        Clock.setHour(11);  //Set the hour 設(shè)置小時(shí)
        Clock.setDoW(5);    //Set the day of the week 設(shè)置星期幾
        Clock.setDate(31);  //Set the date of the month 設(shè)置月份
        Clock.setMonth(5);  //Set the month of the year 設(shè)置一年中的月份
        Clock.setYear(13);  //Set the year (Last two digits of the year) 設(shè)置年份(在今年的最后兩位數(shù)——比如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秒)循環(huán)一次。
}

關(guān)閉窗口

相關(guān)文章