Модуль DS1302 Как показать отдельно секунды, минуты, часы?
- Войдите на сайт для отправки комментариев
Втр, 31/12/2013 - 00:42
Доброго времени суток.
Я полный чайник в микрокуонтроллерах, только начал разбираться. У меня есть модуль DS1302. Немного полазив по форумам, разобрался как его подключить. Также подключил LCD модуль. Прописал вот такой код:
#include <LiquidCrystal.h>
#include <DS1302.h>
// Init the DS1302
DS1302 rtc(2, 3, 4);
// Init the LCD
LiquidCrystal lcd(11, 10, 9, 8, 7, 6);
void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
// Setup LCD to 16x2 characters
lcd.begin(16, 2);
// The following lines can be commented out to use the values already stored in the DS1302
rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010
}
void loop()
{
// Display time centered on the upper line
lcd.setCursor(4, 0);
lcd.print(rtc.getTimeStr());
// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));
// Display date in the lower right corner
lcd.setCursor(6, 1);
lcd.print(rtc.getDateStr());
// Wait one second before repeating :)
delay (1000);
}
Но меня не устраивает то, что команда lcd.print(rtc.getTimeStr()); показывает время слитно, часы, минуты и секунды вместе. Как отобразить отдельно минуты, часы и секунды?
Также требуется сделать некий "будильник", проще говоря зажигать светодиод в определенное время. Как правильно это сделать? Нужны ли еще какие библиотеки?
ну так и печатайте отдельно часы минуты и секунды..как вариант выржеть из бамажки точечки и наклейте между цифрами на дисплей.. и будильник там же.. вы какжется перепутали форум.. вам нужен для тех кто учится програмировать что нибуть.
#include <DS1302.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> // Init the DS1302 DS1302 rtc(2, 3, 4); // (RST, DAT, CLK) LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display Time t; void setup() { // Set the clock to run-mode, and disable the write protection //Установка часов для запуска- // rtc.halt(false); //rtc.writeProtect(false); // The following lines can be commented out to use the values already stored in the DS1302 //rtc.setDOW(MONDAY); // Set Day-of-Week to FRIDAY Monday //rtc.setTime(20, 37, 0); // Set the time to 12:00:00 (24hr format) //rtc.setDate(23, 12, 2013); // Set the date to August 6th, 2010 } void loop() { t = rtc.getTime(); lcd.init(); // initialize the lcd lcd.backlight(); // включение подсветки lcd.setCursor(0, 0); // отступ первой строки слева 0 . // lcd.print(rtc.getDateStr()); // дата в формате день.месяц.год lcd.print(t.date, DEC); // день lcd.print(" "); lcd.print(rtc.getMonthStr()); // месяц lcd.print(" "); lcd.print(t.year, DEC); // год lcd.print("."); lcd.setCursor(0, 1); // отступ второй строки слева 1 . //lcd.print(rtc.getTimeStr()); // Время в формате час:минуты:секунды // или по отдельности lcd.print(rtc.getDOWStr()); // день недели lcd.print(" "); lcd.print(t.hour, DEC); //часы lcd.print(":"); // разделитель lcd.print(t.min, DEC); // минуты lcd.print(":"); // разделитель lcd.print(t.sec, DEC); // секунды }