用ds1302时钟数码管原理图和程序
时间: 2023-04-21 15:05:58 浏览: 187
DS1302时钟模块是一种常用的时钟模块,可以通过它来实现时间的显示和计时等功能。下面是DS1302时钟数码管的原理图和程序:
原理图:
程序:
#include <DS1302.h>
#include <LiquidCrystal.h>
//定义DS1302引脚
const int DS1302_CLK = 2;
const int DS1302_DAT = 3;
const int DS1302_RST = 4;
//定义LCD引脚
const int LCD_RS = 12;
const int LCD_EN = 11;
const int LCD_D4 = 5;
const int LCD_D5 = 6;
const int LCD_D6 = 7;
const int LCD_D7 = 8;
//定义LCD对象
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
//定义DS1302对象
DS1302 rtc(DS1302_CLK, DS1302_DAT, DS1302_RST);
void setup() {
//初始化LCD
lcd.begin(16, 2);
lcd.print("DS1302 Clock");
//初始化DS1302
rtc.halt(false);
rtc.writeProtect(false);
rtc.setDateTime("2022/01/01 00:00:00");
}
void loop() {
//获取当前时间
rtc.update();
int year = rtc.getYear();
int month = rtc.getMonth();
int day = rtc.getDay();
int hour = rtc.getHour();
int minute = rtc.getMinute();
int second = rtc.getSecond();
//显示时间
lcd.setCursor(, 1);
lcd.print(year);
lcd.print("/");
lcd.print(month);
lcd.print("/");
lcd.print(day);
lcd.print(" ");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
//延时1秒
delay(100);
}
阅读全文