| 88 | } |
| 89 | |
| 90 | void cplus_RTC::GetTime(RTC_TimeTypeDef *RTC_TimeStruct) { |
| 91 | // if() |
| 92 | uint8_t buf[3] = {0}; |
| 93 | |
| 94 | wr->beginTransmission(0x51); |
| 95 | wr->write(0x02); |
| 96 | wr->endTransmission(); |
| 97 | wr->requestFrom(0x51, 3); |
| 98 | |
| 99 | while (wr->available()) { |
| 100 | buf[0] = wr->read(); |
| 101 | buf[1] = wr->read(); |
| 102 | buf[2] = wr->read(); |
| 103 | } |
| 104 | |
| 105 | RTC_TimeStruct->Seconds = Bcd2ToByte(buf[0] & 0x7f); // 秒 |
| 106 | RTC_TimeStruct->Minutes = Bcd2ToByte(buf[1] & 0x7f); // 分 |
| 107 | RTC_TimeStruct->Hours = Bcd2ToByte(buf[2] & 0x3f); // 时 |
| 108 | } |
| 109 | |
| 110 | void cplus_RTC::SetTime(RTC_TimeTypeDef *RTC_TimeStruct) { |
| 111 | if (RTC_TimeStruct == NULL) return; |
no test coverage detected