rx8025t.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "rx8025t.h"
  15. __XDATA uint8_t buff[7];
  16. uint8_t RX8025T_Write(uint8_t reg, uint8_t dat)
  17. {
  18. return I2C_Write(RX8025T_I2C_ADDR, reg, &dat, 1);
  19. }
  20. uint8_t RX8025T_Init(void)
  21. {
  22. // Reset all flags
  23. RX8025T_Write(RX8025T_REG_FLAG, 0x00);
  24. // Default , turn off all interrupts
  25. RX8025T_Write(RX8025T_REG_CONTROL, 0x40);
  26. return HAL_OK;
  27. }
  28. uint8_t RX8025T_GetTime(uint8_t *t)
  29. {
  30. I2C_Read(RX8025T_I2C_ADDR, RX8025T_REG_SECOND, t, 16);
  31. return HAL_OK;
  32. }
  33. uint8_t RX8025T_SetTime(uint8_t *t)
  34. {
  35. RX8025T_Write(RX8025T_REG_SECOND, t[0]);
  36. RX8025T_Write(RX8025T_REG_MINUTE, t[1]);
  37. RX8025T_Write(RX8025T_REG_HOUR, t[2]);
  38. RX8025T_Write(RX8025T_REG_WEEKDAY, t[3]);
  39. RX8025T_Write(RX8025T_REG_DAY, t[4]);
  40. RX8025T_Write(RX8025T_REG_MONTH, t[5]);
  41. RX8025T_Write(RX8025T_REG_YEAR, t[6]);
  42. return HAL_OK;
  43. }