dreaming 发表于 2013-8-15 02:26:03

用Arduino和LCD1602显示DS1302信息

本帖最后由 迷你强 于 2013-8-15 09:29 编辑

源程序

#include <LiquidCrystal.h>
#include <stdio.h>
#include <string.h>
#include <DS1302.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
uint8_t CE_PIN   = 2;
uint8_t IO_PIN   = 3;
uint8_t SCLK_PIN = 11;
char buf;
char day;
DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN);
Time t;
void setup()
{
    Serial.begin(9600);
    rtc.write_protect(false);
    rtc.halt(false);
    Time t(2013,8,15,1,9,20,5);
    rtc.time(t);
}

void loop()
{
Time t = rtc.time();
    memset(day, 0, sizeof(day));
    switch (t.day)
    {
    case 1: strcpy(day, "Sun"); break;
    case 2: strcpy(day, "Mon"); break;
    case 3: strcpy(day, "Tue"); break;
    case 4: strcpy(day, "Wed"); break;
    case 5: strcpy(day, "Thu"); break;
    case 6: strcpy(day, "Fri"); break;
    case 7: strcpy(day, "Sat"); break;
    }
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d ", day, t.yr, t.mon, t.date);
lcd.clear();
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print(buf);
lcd.setCursor(11, 1);
lcd.print("BISTU");
snprintf(buf, sizeof(buf), "%02d:%02d:%02d", t.hr, t.min, t.sec);
lcd.setCursor(1, 1);
lcd.print(buf);
delay(1000);                  
}

迷你强 发表于 2013-8-15 09:31:10

不错,应该将电路图,整体实物图啥的顺手拍个照片嘛。。。。

dreaming 发表于 2013-8-15 02:31:13

本帖最后由 迷你强 于 2013-8-15 09:30 编辑

用另外一个DS1302的库:
源代码:

#include <DS1302.h>
#include <LiquidCrystal.h>
// Init the DS1302
DS1302 rtc(2, 3, 11);
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

// Setup Serial connection
Serial.begin(9600);

// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW(THURSDAY);      // Set Day-of-Week to FRIDAY
rtc.setTime(1,58, 40);   // Set the time to 12:00:00 (24hr format)
rtc.setDate(15, 8, 2013);   // Set the date to August 6th, 2010
}

void loop()
{
lcd.clear();
lcd.begin(16, 2);
lcd.setCursor(1,0);
lcd.print("THU");
lcd.setCursor(5, 0);
lcd.print(rtc.getDateStr());
//lcd.print(" -- ");
   lcd.setCursor(1, 1);
lcd.print(rtc.getTimeStr());
   lcd.setCursor(10, 1);
lcd.print("BISTU");
delay (1000);
}

dreaming 发表于 2013-8-15 02:37:27

本人新手,高手勿喷...
感谢极客工坊,只是用以来添点人气

dreaming 发表于 2013-8-15 15:47:25

迷你强 发表于 2013-8-15 09:31 static/image/common/back.gif
不错,应该将电路图,整体实物图啥的顺手拍个照片嘛。。。。

我也想着这样!可是照片是910K的,网站提示文件类型限制无法上传,所以就截的图

迷你强 发表于 2013-8-15 17:50:41

dreaming 发表于 2013-8-15 15:47 static/image/common/back.gif
我也想着这样!可是照片是910K的,网站提示文件类型限制无法上传,所以就截的图

看教程咯
http://www.geek-workshop.com/thread-2887-1-1.html

熊猫 发表于 2013-11-22 16:16:00

bistu ?            

dreaming 发表于 2013-11-29 15:16:28

熊猫 发表于 2013-11-22 16:16 static/image/common/back.gif
bistu ?

BISTU的呃。。。

komoya 发表于 2013-11-29 15:20:40

家里有,改天调试调试让DS1307也可以用,不错。

philhoo 发表于 2013-12-9 21:53:35

不错,用1302模块还是单独的芯片?

a_zhi 发表于 2013-12-15 00:03:15

dreaming 发表于 2013-8-15 02:31 static/image/common/back.gif
用另外一个DS1302的库:
源代码:



有空试试这个库。谢谢了!

huangshan78 发表于 2014-5-1 00:12:12

能不能用ds3231试一试

huangshan78 发表于 2014-5-1 00:13:43

ds1302的晶体实在不准啊,才几分钟就快了5秒

suoma 发表于 2017-3-8 12:05:57

dreaming 发表于 2013-8-15 02:31
用另外一个DS1302的库:
源代码:



第二个程序里面 lcd.print("THU");
rtc.get函数不能获得星期几吗?

lyy1208 发表于 2020-10-13 16:11:10

dreaming 发表于 2013-8-15 02:31
用另外一个DS1302的库:
源代码:

你好,请问LCD7个引脚具体接法是什么?
页: [1] 2
查看完整版本: 用Arduino和LCD1602显示DS1302信息