Всем привет. МОжет есть у кого-нибудь кусок кода для arduino - установка часов и минут кнопками на RTC 3231. Спасибо
Код (C++): #include <Wire.h> struct _I2CRealRimeClockTime { byte seconds = 0; byte minutes = 0; byte Hours = 0; byte weekday = 0; byte day = 0; byte month = 0; byte year = 0; unsigned long startTime = 0; }; _I2CRealRimeClockTime _RTC1; bool _RTCST_Ost1 = 0; void setup() { Wire.begin(); delay(10); Wire.beginTransmission(68); Wire.write(0x0E); Wire.write(B00000000); Wire.write(B10001000); Wire.endTransmission(); _RTC1.startTime = millis() - 1000; } void loop() { if (0) { if (!(_RTCST_Ost1)) {set3231Date(0x68, &_RTC1, -1, (0), (0), -1, -1, -1, -1); get3231Date(0x68, &_RTC1); _RTCST_Ost1 = 1; }} else { _RTCST_Ost1 = 0;} } bool _isTimer(unsigned long startTime, unsigned long period ) { unsigned long currentTime; currentTime = millis(); if (currentTime>= startTime) {return (currentTime>=(startTime + period));} else {return (currentTime >=(4294967295-startTime+period));} } byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); } void set3231Date(int addres, struct _I2CRealRimeClockTime *timeStruct, int sec, int minut, int hou, int dat, int mo, int ye, int daW) { byte temp; Wire.beginTransmission(addres); Wire.write(0x00); if (sec < 0) { temp = timeStruct -> seconds; } else { temp = sec; } Wire.write(decToBcd(temp)); if (minut < 0) { temp = timeStruct -> minutes; } else { temp = minut; } Wire.write(decToBcd(temp)); if (hou < 0) { temp = timeStruct -> Hours; } else { temp = hou; } Wire.write(decToBcd(temp)); if (daW < 0) { temp = timeStruct -> weekday; } else { temp = daW; } Wire.write(decToBcd(temp)); if (dat < 0) { temp = timeStruct -> day; } else { temp = dat; } Wire.write(decToBcd(temp)); if (mo < 0) { temp = timeStruct -> month; } else { temp = mo; } Wire.write(decToBcd(temp)); if (ye < 0) { temp = timeStruct -> year; } else { temp = ye; } Wire.write(decToBcd(temp)); Wire.endTransmission(); timeStruct ->startTime = millis() - 1000; } void get3231Date(int addres, struct _I2CRealRimeClockTime *timeStruct) { if (!(_isTimer ((timeStruct ->startTime), 250))) { return; } Wire.beginTransmission( addres); Wire.write(0x00); Wire.endTransmission(); Wire.requestFrom(addres, 7); if (Wire.available()) { byte seconds = Wire.read(); byte minutes = Wire.read(); byte hours = Wire.read(); byte day = Wire.read(); byte date = Wire.read(); byte month = Wire.read(); byte year = Wire.read(); timeStruct -> seconds = (((seconds & B11110000) >> 4) * 10 + (seconds & B00001111)); timeStruct -> minutes = (((minutes & B11110000) >> 4) * 10 + (minutes & B00001111)); timeStruct -> Hours = (((hours & B00110000) >> 4) * 10 + (hours & B00001111)); timeStruct -> weekday = (day & B00000111); timeStruct -> day = (((date & B00110000) >> 4) * 10 + (date & B00001111)); timeStruct -> month = (((month & B00010000) >> 4) * 10 + (month & B00001111)); timeStruct -> year = (((year & B11110000) >> 4) * 10 + (year & B00001111)); } timeStruct ->startTime = millis(); }