In this article, we will use the font-free 12864 LCD module to make a small calendar clock. The final effect is shown in Figure 1.
What are the features of this small calendar clock?
1. The circuit is simple, uses few components, and is easy to make. The core is the microcontroller ATMega8L and the calendar clock 1302.
2. All low-voltage components are used and can work with a voltage of 3V.
3. The use of self-edited small fonts and graphic interface makes the display unique: the current date and time can be clearly read on the text interface, and a small animation is added to make the display more vivid. The analog scale and pointer are used in the graphic interface to dynamically indicate the current time, and the two interfaces can be switched by buttons.
Figure 2 Circuit Principle
4. The power supply is made on an independent small circuit board. When debugging the program, insert a 3.3V regulated power supply powered by USB. After completion, you can remove it, plug in the switch, and use battery power.
5. When the backlight is not in use, the power consumption is very small (about 3mA for the whole machine), and it can be powered by a CR2O32 wafer lithium battery.
The calendar clock is installed on a small 50mm x 50mm multi-purpose board. See Figure 1 for the appearance.
Circuit Principle
The electrical schematic is shown in Figure 2. The LCD model is as mentioned above. The microcontroller is AVR's ATMega8L-8PU (hereinafter referred to as M8), which can work at low voltage. The PD port of M8 controls the LCD, mainly controlling the serial writing of display data. DS13O2 (hereinafter referred to as 1302) is a commonly used calendar clock chip, and the 32768Hz crystal B is its oscillation source. There are 10 command registers inside it to store the values of date and time and control the chip operation. M8 controls 1302's RST, SCLK, and I/O through PB0PB1 and PB2: 1302 can only be read and written when RST is high. Both reading and writing allow data to be transmitted serially on I/O. When SCLK rises, 1 bit of address or data is written, and 1 bit of address or data is written. After writing the address, the data is read out every time SCLK falls. Reading and writing start from the lowest bit and are synchronized by the SCLK clock. After the power is turned on, it must start the timing through the MCU program. As long as there is power or power supply, it can keep working, regardless of whether the MCU is working. The 4 touch buttons connected to the PC port of M8, S1, S2, S3 are used to adjust the time: confirm the modification, move the cursor, and modify the value; S4 is used for interface switching. The power pack is inserted into two parts: the disc battery CR2O32 is connected to the VCC1 of 1302 through the diode VD1 as the back power supply, so that 1302 can continue to work when it is turned off. The other way can be used to power the LCD, MB, and VCC2 of 1302 through the switch S5. In order to avoid consuming the battery during debugging, another 5V to 3.3V small voltage regulator board is connected, and the 5V power supply is obtained from the outside using the micro SB interface. After debugging, remove the voltage regulator board, plug the small toggle switch S5 into the jack, and you can use the lithium battery. Note that diode VD1 cannot be omitted, because according to the 1302 manual, when VCC2 is higher than VCC1, it is powered by VCC2, and when VCC2 is lower than VCC1, it is powered by VCC1. When using batteries, due to the two straws, VCC2 is higher than VCC1, and the battery is powered normally. When the battery is turned off, VCC2 is 0, and the battery is used as the subsequent power supply through the diode, which meets the requirements and ensures the normal operation of the circuit.
Hardware Production
This calendar clock circuit is simple and requires few components. The integrated circuit uses a dual in-line socket, and the 90-degree pin row soldered on the LCD is connected to the 90-degree pin header socket soldered on the multi-purpose board. The 6-wire programming port and the power supply part socket use a round hole 2.54mm spacing socket strip. The battery uses a round lithium battery CR2O32. A 5cm square multi-purpose board is used to install all components. First, a section of 90° pin header is cut and soldered to the center of the upper back of the circuit board as an LCD socket. The M8 IC socket should also be installed on the back of the circuit board. For this purpose, its pins are bent outwards and the IC socket is positioned according to the corresponding position of the LCD socket pins. First, the RC reset component and some related wires are soldered, and then the MB socket is positioned and soldered to the circuit board pad. The 1302 socket is positioned according to the M8 socket and is also soldered on the back of the circuit board together with the 32768HZ crystal. Although this unconventional installation is not entirely reasonable, it effectively utilizes the installation area of the multi-purpose board (otherwise the area occupied by the LCD is inconvenient to use), and it can make the connection between the LCD and the MB and 1302 very simple, and can be directly connected with solder. On the front of the circuit board, it is also necessary to install a touch button, a battery nest, a programming jack row, and a power block jack. The layout of components on both sides is shown in Figures 3 and 4. Another small multi-purpose board is used to solder the micro USB socket, filter capacitor, low-voltage regulator LM1117-3.3, and the IC pins corresponding to the power jack of the clock board.
When soldering the 90° pin header of the LCD, you can first insert it into the pin header that has been soldered on the circuit board, and then solder the gold-plated pads on the LCD. Be careful to keep the LCD and the circuit board parallel, so the pins cannot be inserted to the bottom of the LCD.
Because the LCD backlight consumes too much power for a small lithium battery with a capacity of only 2OOmAh, a current of 50mA is not installed. If you need to install it, it is best to connect it to an external power source instead of using a small battery.
programming
Although the circuit is simple, in order to make the LCD and 1302 without fonts work in an orderly manner under the unified leadership of M8, the specific programming must solve the following problems.
Figure 7 Program flow
1. Make the clock move, and you can set or modify the current data by pressing buttons.
2. Let the LCD display the information currently provided by the clock chip: year, month, day, hour, minute, and second, and refresh the two display interfaces on time.
3. Make fonts and graphical interface programming.
The first point above is to use M8 to control 1302. We can compile some functions according to its timing requirements. In addition, we can create an array DateTime[7] in the program to store the year, month, day, hour, minute, and second read from 1302 as the basis for data refresh. The second point is mainly to display the current data of this array on the LED (note that the format of 1302 to store date and time is BCD code, so the number system must be converted before access). Data refresh is actually to query whether the current "second" of 1302 is equal to the last query result. If not, 1 second has passed, record the new second in the array, and refresh the displayed "second" - of course, it is refreshed once every 1 second; and when the second is updated to 0, the "minute" must be updated... and so on. The third point has been described last time, using the Panpan font method, which has compiled 8 x 8 small numbers, 12×16 numbers, and 16×16 Chinese characters for different display positions. In addition, there is an animation of a chicken pecking at rice. You can click with the mouse in the 16-dot font tool to draw two patterns of a chicken lowering its head and a chicken raising its head, and display them alternately when the second refreshes. After using the font software to make the required fonts, put all the constant font array definitions in the header file miniClock, and all these arrays are placed in the FLASH area.
It is not difficult to make analog indicator needles and scales in the graphical interface. You just need to plan the length of the horizontal scale in advance, draw horizontal lines with the starting and ending coordinates, and draw short vertical lines for the vertical scale according to the scale position. The indicator ground is a vertical straight line above or below the scale. Its position must be calculated and changed according to the refresh of time data.
The title "Little Calendar Clock" is a Chinese character string, and a Chinese character string display function is used, Vold show-string1616(ucharx,uchary,uchar * string,uchar string_length); the parameters are the display starting column, page, string pointer, and string length. At the same time, one or more string arrays pointed to by pointers must be defined in advance. The elements of this array are the positions of the fonts to be displayed in the font array.
The entire program flow is shown in Figure 7. The left is the main process, and the right is the year, day, month, hour, minute, and second update process.
debug
After the hardware is soldered, check repeatedly without inserting M8, 1302 and LCD lithium battery, plug in the voltage regulator board, connect USB power supply, test M8 socket, 1302 socket, programming port and LCD VCC power supply should be normal 3.3V, remove the voltage regulator and turn off the power, plug in the lithium battery, 1302 socket 8 pin should be 2.4V, plug in S5 and turn it on, VCC should be 3∨, so the battery is fine. Unplug S5, plug in M8, LCD and 1302, plug in the voltage regulator board and USB power supply. If you have never used this kind of LCD, you might as well compile some small programs yourself (for example, after starting and initializing M8 and LCD, run the clear screen function with different parameters) to observe whether the LCD display is as expected. If there is no response, check again whether the definition of M8 pin in the program is consistent with your actual hardware wiring. This small LCD is different from some other LCDs. It does not require hardware to adjust the contrast summer, and will not not display due to improper contrast adjustment (unless you modify the default value). This level must be passed before going down. Download the program to M8. If everything is normal, the screen will appear immediately. However, the current date and time are wrong. Press S2 and a vertical cursor will appear on the separator of the date and time in the bottom row. Press S2 continuously and the cursor will move right in a loop. Press S1 at the position where the cursor stops, and the set value will appear on it. Press repeatedly to increase the value in a loop. In this way, the date and time are adjusted one by one, as shown in Figure 5. Finally, press S3, and the new time will be stored in 1302 and can be refreshed by seconds. Now plug in the battery and everything will be fine. As shown in Figure 6, it can be seen that the hours and minutes have been changed to the new set values. The voltage regulator can be removed. Although the LCD is off, 1302 is still running silently. If you plug in the switch S5 and turn it on again, the LCD will light up again. In order to save battery consumption, don't always turn it on. Just like an old pocket watch, open the cover before looking at the watch.
Previous article:Power saving methods for NUC1xx microcontrollers (MCUs)
Next article:Brushless ESC solution for model aircraft based on Sinowin SH79F168 MCU
Recommended ReadingLatest update time:2024-11-17 15:43
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- LIS2DE12MEMS digital output motion sensor ultra-low power high performance 3-axis "femto" accelerometer datasheet
- Chapter7 Analog-to-digital converter ADC12_A
- Open source hardware small project: Anxinke ESP-C3-12F controls WS2812
- Hiring embedded software engineer
- Principle and design of flyback switching power supply
- EEWORLD University Hall----Live Replay: MPS Inductor Solutions Help Better Switching Power Supply Design
- High-precision humidity and temperature sensor
- 【NUCLEO-L552ZE Review】+ Planning & Preparation
- After cc2530 successfully creates a network, p1_0 immediately becomes low level
- SMSC Launches MOST50 Technology to Double Bandwidth for Automotive Multimedia Networks