Application Design of 51 Single Chip Microcomputer Controlling Real-time Clock X1226

Publisher:SparkleMagicLatest update time:2011-12-31 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Introduction
X1226 has the functions of clock and calendar. The clock relies on hour, minute and second registers to track, and the calendar relies on date, week, month and year registers to track. The calendar can correctly pass 2099 and has automatic leap year correction.
It has a powerful dual alarm function that can be set to any clock/calendar value with an accuracy of 1s. The output frequency can be set to any one of 1 Hz, 4096 Hz or 32768Hz by software.
The device provides a backup power input pin VBACK1 to allow the device to be backed up by a battery or a large-capacity capacitor. Many battery types can be used as backup batteries for Xicor's real-time clock device X1226. 3.0V or 3.6V lithium-ion batteries are more suitable and have a service life of 10 years. Another usage can be to choose a large-capacity capacitor. The backup time can last from a few days to two weeks, depending on the size of the capacitor. Use a simple silicon or Schottky diode connected to Vcc and the charging capacitor. The charging capacitor is connected to the Vback pin. Note that the diode cannot be used to charge the battery (especially lithium-ion batteries). The condition for switching to battery power supply is Vcc=Vback-0.1V. During normal operation, the supply voltage Vcc must be higher than the battery voltage, otherwise the battery power will gradually be exhausted.

The crystal required for the oscillator uses an external 32.768kHz crystal. The resulting oscillation error can be corrected by adjusting the values ​​of the digital trimming register and the analog trimming register through software, avoiding the influence of the discreteness of the external resistor and capacitor on the accuracy.
The device can provide 4Kb EEPROM and 8 blocks of lock control. It can be used as a memory for storing a large amount of user data, which is safe and confidential. The data in this memory will not be affected when both the main power supply and the backup power supply fail.


1 Circuit composition and working principle
The real-time clock device X1226 can be interfaced with various types of microcontrollers or microprocessors, and the interface method is a serial I2C interface. The data bus SDA is a bidirectional pin used to input or output data. It is an open-drain output, and a pull-up resistor needs to be added during use, with a resistance value of approximately 4.7Ω to 10kΩ. This article introduces the interface method between the 89C51 microcontroller and X1226. Since the 89C51 microcontroller does not have a standard I2C interface, it can only be simulated by software.
In order to see the time change more intuitively, an eight-bit LED digital tube is used to display the change of year, month, day or hour, minute, and second. The LED digital tube is driven by our company's own product PS7219A, and the digital tube selects a 1.27cm common cathode red or green LED digital tube. Since the PS7219A device contains an IMP810 microcontroller monitoring device, the reset output is valid at a high level, so when using the 51 system, there is no need to add a monitoring device. The reset output of the PS7219A can be used to reset the 51 microcontroller. The monitoring voltage is 4.63V. The hardware design schematic is shown in Figure 1.

During the hardware power-on debugging process, please do not touch the crystal of the real-time clock X1226 with your hands, as this may cause the oscillator to stop oscillating. The way to restore the oscillator is to turn off the power supply (including the backup power supply) and then turn it on again. In addition, it should be noted that when measuring the oscillator, please do not use the oscilloscope probe to measure the oscillation output of X2. The correct method is to use the probe to measure the oscillation output of PHz/IRQ to determine whether it is oscillating and whether the oscillation frequency is accurate. It is recommended to add a 5.1 kΩ pull-up resistor to this pin when measuring.
Note: When designing printed circuits, please refer to the manufacturer's recommended method in the X1226 data sheet for the wiring of xl226.


2 Software Design
X1226 consists of real-time clock register (RTC), status register (SR), control register (CONTROL), alarm register (Alarm0, Alarm1) and customer data storage. Since the real-time clock register (RTC) and status register (SR) need to be written frequently, its storage structure is a volatile SRAM structure, which has no limit on the number of write operations. The other register structures are all non-volatile EEPROM structures, which have a limit on the number of write operations, usually more than 100,000 times. The X1226 initialization program flow is shown in Figure 2.

Start condition subroutine:
SETB SDA
LCALL YS4
SETB SCL
LCALL YS4
CLR SDA
LCALL YS4
CLR SCL
LCALL YS4
RET
Stop condition subroutine:
CLR SDA
LCALL YS4
SETB SCL
LCALL YS4
SETB SDA
RET
Note: The function of subroutine YS4 is to delay 4μs.
2.1 Write operation
After X1226 is initialized, the microcontroller sets the start condition for X1226. Before writing CCR or EEPROM, the host must first write 02H to the status register, confirm the response signal, write 06H after confirmation, and then confirm the response signal. After confirmation, the write operation is started. First send the high address, then send the low address. Xl226 will generate a response signal after receiving each address byte. After both address bytes are received, X1226 waits for 8 bits of data. After receiving 8 bits of data, X1226 generates another response. The microcontroller then terminates the transfer by generating a stop condition.
X1226 has a continuous write function. After receiving each byte, X1226 responds with an acknowledgement and internally increases the address by one. When the counter reaches the end of the page, it automatically "returns" to the first address of the page. This means that the microcontroller can write 64 bytes to the memory array or 8 bytes to the CCR continuously from any position on a page.
Subroutine for writing X1226 data:

MOV R5, #8

SENDI: MOV A, DATASE
RLC A
MOV DATASE, A
MOV SDA, C
SEB SCL
LCALL YS4
CLR SCL
LCALL YS4
DJNZ R5, SENDl
RET
2.2 Read operation
At power-on, the default value of the 16-bit address is 0000H. After the X1226 initialization operation, the microcontroller sets the start condition for X1226. Before writing CCR or EEPROM, the host must first write 02H to the status register, confirm the response signal, write 06H after confirmation, and then confirm the response signal. After confirmation, the write operation is started. First send the high address, then send the low address. Xl226 will generate an acknowledge signal after each address byte received. The microcontroller sends another start condition, sets the R/W bit to 1, and then receives 8 bits of data. When the microcontroller terminates the read operation, it does not need to wait for the response signal of X1226, and the microcontroller can set the stop condition.
Read out X1226 data subroutine:

MOV       R5,#8
MOV       DATARE,#0
SETR      SDA
CLR       C
READl:SETB      SCL
LCALL     YS4

MOV C,SDA
CLR SCL
MOV A,DATARE
RLC A
MOV DATARE,A
LCALL YS4
DJNZ R5,READl
RET
2.2 X1226 unique oscillator frequency online compensation adjustment function
Xicor has integrated an oscillator compensation circuit on the X1226 chip, which allows users to fine-tune the oscillator frequency online through software. This fine-tuning of the oscillator frequency is usually for two situations. One situation is to compensate for the frequency deviation of the oscillator due to the initial accuracy of the device at a normal temperature of 25℃; the second situation is to compensate for the frequency drift caused by temperature. X1226 has a digital trim register (DTR) and an analog trim register (ATR), both of which are non-volatile registers. The digital trim register (DTR) has three digital trim bits with an adjustment range of -30ppm~+30ppm. The analog trim register (ATR) has six analog trim bits with an adjustment range of +116ppm~-37ppm.

In order to compensate for the temperature drift caused by the change of external ambient temperature, a temperature sensor is required to be designed in the system and placed as close as possible to the real-time clock device X1226, so that the temperature of the oscillator can be truly reflected. The schematic diagram is shown in Figure 3. The microcontroller first obtains the ambient temperature through the system temperature sensor, obtains the corresponding compensation value in the compensation parameter table, and then fills the compensation data into the corresponding fine-tuning register to achieve the purpose of temperature drift compensation.

Reference address:Application Design of 51 Single Chip Microcomputer Controlling Real-time Clock X1226

Previous article:VHDL Design of Interface between 8-bit 51 Single-chip Microcomputer and Ethernet Controller RTL8029
Next article:13×14 dot matrix reduced code Chinese card for 51 single chip microcomputer

Recommended ReadingLatest update time:2024-11-17 02:56

Software simulation I2C read and write X1226 program
Written in C51, the program has passed the test and has been successfully used in the project. It is suitable for all 51 core microcontrollers and can be transplanted to other microcontrollers with very few modifications. I have transplanted it to the 430 microcontroller.     Disclaimer: This code is origina
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号