2.4 Hardware Schematic Diagram
2.4.1 MCU Minimum System
The MCU minimum system includes an external crystal oscillator circuit, a reset circuit and a power supply circuit. Figure 2-4-1 shows the minimum system of the MCU. Using STC89C52RC, it requires a 5V power supply system. The above figure uses the 5V DC output from the USB port for direct power supply. As can be seen from the figure, the power supply circuit is at pin 38, also commonly known as VCC or VDD, representing the positive pole of the power supply, and pin 16 is connected to GND, representing the negative pole of the power supply.

Figure 2-4-1 Single-chip minimum system
2.4.2 DS1302 typical circuit
DS1302 is a high-performance, low-power, real-time clock circuit with RAM. It can time the year, month, day, weekday, hour, minute, and second, and has leap year compensation function. The operating voltage is 2.5V~5.5V. It uses a three-wire interface to communicate synchronously with the CPU, and can use burst mode to transmit multiple bytes of clock signals or RAM (RAM (random access memory) RAM - random access memory. The contents of the storage unit can be taken out or stored as needed, and the access speed is independent of the location of the storage unit. This memory will lose its storage content when the power is off, so it is mainly used to store programs used for short periods of time. According to the different storage information, random memory is divided into static random memory (SRAM) and dynamic random memory (DRAM).) data. The DS1302 has a 31×8 RAM register for temporary storage of data. DS1302 is an upgraded product of DS1202. It is compatible with DS1202, but adds dual power pins of main power supply/back power supply, and provides the ability to charge the back power supply with trickle current. Figure 2-4-2 is its typical

circuit 2-4-2 DS1302 typical circuit
2.4.3 Typical LDO circuit
AMS1117 is a low dropout voltage regulator. Its voltage regulator is composed of a PNP-driven NPN tube. The dropout voltage is defined as: VDROP=VBE+VSAT. AMS1117 is available in fixed and adjustable versions. The output voltage can be: 1.2V, 1.5V, 1.8V, 2.5V, 2.85V, 3.0V, 3.3V, and 5.0V. The on-chip overheat cutoff circuit provides overload and overheat protection to prevent the ambient temperature from causing excessive junction temperature. In order to ensure the stability of AMS1117, for the adjustable voltage version, the output needs to be connected to a tantalum capacitor of at least 22μF. For the fixed voltage version, a smaller capacitor can be used, which can be determined according to the actual application. Generally, the stability of the linear regulator decreases as the output current increases.

Figure 2-4-3 LDO typical circuit
2.4.4TP4057 lithium battery charging circuit
TP4057 is a linear charger designed specifically for lithium-ion batteries. It uses the power MOSFET inside the chip to charge the battery with constant current/constant voltage. The charging current can be determined by external resistor programming, and the maximum charging current can reach 500mA. TP4057 has two open-drain output status indication output terminals, the charging status indication terminal CHRG and the battery charging completion indication output terminal STDBY. The power tube circuit inside the chip automatically reduces the charging current when the junction temperature of the chip exceeds 135℃. This function allows users to maximize the use of chip charging without worrying about chip overheating and damaging the chip or external components.
Figure 2-4-4 tp4057 typical circuit
III. Functional design
3.1 System design
Buttons are used for control and user interaction mode. When the microcontroller detects that the level of a pin is low, it triggers the execution of the corresponding processing function. The boot animation, main page, secondary menu page and exit page are designed. The secondary menu page includes changing the time and date, setting the alarm to trigger the buzzer, and displaying the boot animation.
3.2 Software
Flowchart 3-2-1 Main Function Execution Process
The hardware initialization is completed in the main function, including IIC, font library, OLED, key function and WHILE () loop. When while executes key scanning, it will detect the level of the key. When it is low, it can trigger the case matching condition and enter the P_K program lock. At this time, the value of P_K is true, while () is an infinite loop, and the key scan is executed in the current while (). When a certain interface enters the function P_K-while () loop, this function is executed. Figure 3-2-2 is the execution flow of the P_K-while () loop.

Figure 3-2-2 P_K execution flow
3.2.1 Boot animation display
Write OLED operation interface function, then take the picture module The module taking tools include lmage2Lcd2.9 and PCtoLCD2002 software. First convert the picture into a pixel matrix, and then take the module; the module taking format is C51 type, and the picture array is obtained. Then write the OLED picture interface function.
3.2.2 DS1302 settings
The main working principle is shift register, control logic, crystal oscillator, clock and RAM. When any data is transmitted, it must be set to a high level (note that although it is set to a high level, the internal clock is still running under the action of the crystal oscillator. At this time, external reading and writing of data is allowed). Data is input at each SCLK rising edge and output at the falling edge. Only one bit can be read and written at a time. Moderation or writing needs to be realized through serial input control instructions (also a byte). One byte can be read through 8 pulses to realize serial input and output. Initially, the control byte is loaded into the shift register through 8 clock cycles. If the control instruction selects the single-byte mode, 8 consecutive clock pulses can write and read 8-bit data. The data is written to DS1302 at the rising edge of the SCLK clock, and the data of DS1302 is read at the falling edge of the SCLK pulse. 8 pulses can read and write one byte; after understanding the underlying logic, write the driver function and operation function of DS1302 according to the manual.