This repository provides a lightweight and easy-to-use driver for the DS1302 Real-Time Clock (RTC) module, specifically adapted for Nuvoton M031 series microcontrollers.
The library implements bit-banging communication via GPIOs without relying on heavy peripheral libraries, making it highly portable and efficient.
2025-04-27.20-42-59.mp4
- Read and write time (year, month, date, hour, minute, second, day)
- Microsecond-level timing using
CLK_SysTickDelay - Minimal dependencies
| DS1302 Pin | M031 Pin |
|---|---|
| CLK | PA0 |
| IO | PA1 |
| RST | PA2 |
| VCC | 3.3V |
| GND | GND |
![]() |
- Connect your DS1302 module to the specified pins.
- Include
DS1302.candDS1302.hin your project. - Initialize the RTC:
DS1302_Init(); - Set Time Example:
uint8_t time_set[8] = {0x00, 24, 4, 27, 15, 30, 0, 7}; // Control, Year, Month, Date, Hour, Minute, Second, Day DS1302_WriteTime(time_set);
- Read Time Example:
uint8_t time_read[8]; DS1302_ReadTime(time_read);
- Make sure
SYS_Init()configures the core clock before usingCLK_SysTickDelay. - The IO (data) pin is dynamically configured as INPUT or OUTPUT as needed.
Distributed under the MIT License. See LICENSE for more information.
Developed and maintained by ibrahim ışıklı - https://www.ibrahimisikli.com/
⭐ Feel free to star this repository if you find it useful!
🤝 Contributions and pull requests are welcome!
