查看: 3387|回复: 0

Arduino UNO、LCD1602、DS1307制作带日历星期的数字时钟

[复制链接]
  • TA的每日心情
    奋斗
    2019-10-1 12:54
  • 签到天数: 313 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2018-4-17 08:52:51 | 显示全部楼层 |阅读模式
    分享到:
    下面介绍使用Arduino UNO、LCD1602、DS1307制作带日历星期的数字时钟
    硬件连接:
    DS1307模块的SDA SCL连接Arduino UNO数字输入输出上面一排的SDA SCL,DS1307的VCC GND连接Arduino UNO的ICSP的VCC GND
    ICSP排针排列如下

    LCD1602的VCC GND SDA SCL连接到Arduino UNO的5V GND A4 A5
    连接好之后上电,打开Arduino IDE,打开项目--加载库--管理库,搜索安装rtllib库

    如果之前没有安装过LiquidCrystal_I2C库还需要安装这个,安装完成后新建sketch,输入下面代码
    #include <Wire.h>#include <RTClib.h>#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x3F,16,2);RTC_DS1307 RTC;char daysOfTheWeek[7][12] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};void setup () {    Serial.begin(9600);    lcd.init();    lcd.backlight();    Wire.begin();    RTC.begin();    RTC.adjust(DateTime(__DATE__, __TIME__));  }void loop () {      DateTime now = RTC.now();        Serial.print(now.year(), DEC);    Serial.print('-');    Serial.print(now.month(), DEC);    Serial.print('-');    Serial.print(now.day(), DEC);    Serial.print(' ');    Serial.print(now.hour(), DEC);    Serial.print(':');    Serial.print(now.minute(), DEC);    Serial.print(':');    Serial.print(now.second(), DEC);    Serial.print(' ');    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);    Serial.println();        lcd.setCursor(0,0);    lcd.print(now.year(), DEC);    lcd.print('-');    lcd.print(now.month(), DEC);    lcd.print('-');    lcd.print(now.day(), DEC);    lcd.print(' ');    lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);    lcd.setCursor(0,1);    lcd.print(now.hour(), DEC);    lcd.print(':');    lcd.print(now.minute(), DEC);    lcd.print(':');    lcd.print(now.second(), DEC);    lcd.print(' ');    delay(1000);}
    上传后效果如下
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-11-19 12:42 , Processed in 0.121724 second(s), 18 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.