The main function of real-time clock (RTC) is to keep the clock running when the system powers down, so as not to lose time information.
S3C2440 is integrated with the RTC module, which is easy to use. Its internal registers bcdsec, bcdmin, bcdhour, bcdday, bcddate, bcdmon, and bcdyear are stored
The second, minute, hour, week, day, month, and year indicate that the time value is BCD code. The content of these registers can be read and written only when the 0th-bit rtccon register is 1. To prevent
Misoperations: when no read/write operations are performed, this bit must be cleared. When reading these registers, the current time can be known; when writing these registers, the current time can be changed. In addition, it should be noted that the so-called "one second
Therefore, when the number of seconds read is 0, you need to read the content of these registers again to ensure that the time is correct (for this, see the S3C2440 document ).
The following is a simple program. When the power-on is started, the current time value is read and displayed through the serial port. The current time is set to January 1, August 25, 2014, and 33 seconds:
After the setting is complete, comment out the code for setting the time and re-compile it. Use openjtag to go down. It can be seen that the clock is also timing during a period of time when the power is off. This is a simple and small feature.
Clone.
In addition to simple timing, RTC also provides two types of clock interruption functions: Alarm interruption, time cycle interruption, and time cycle interruption. As the name suggests, it is like a timer, which can be used to control the cycle synchronously. So it class
It is similar to the timer interruption. However, the time-to-cycle interruption is millisecond-level, while the timer interruption can reach microseconds or even smaller levels. The cycle formula for time cycle interruption is: (n + 1) interval 128, in seconds, that is, every
Long time, will interrupt once. Where the value of N is 1 ~ 127, which is stored in the Lower 6 bits of the register ticnt. When the 7th bits of the register ticnt are set to 1, it indicates that the start time is interrupted. At this time, n is decreased, and when
When the value is 0, the start time is interrupted. Generally, the beat level in UCOS is Ms level, which is suitable for UCOS.
Alarm interruption can cause an alarm when the real-time reaches the preset time. The preset time is stored in the alarm time data register (RTC has two sets of time-related registers, all of which are stored in BCD format. Current Time
Set), including almyear (year), almmon (month), almdate (day), almhour (hour), almmin (minute), and almsec (second ). The alarm is controlled by the alarm control register rtcalm. Its
6th position 1 indicates Global Alarm, while 5th to 0th position 1 indicates year, month, day, hour, minute, and second alarm respectively.
For example, if we want to trigger an alarm at, January 1, April 5, 2010, we store the time in the corresponding alarm time data register, and set rtcalm to 0x7f, in this way, when the real-time clock reaches this time point
Alarm interruption;
For example, if we want the system to have the alarm function to remind us to get up at every morning, we can set almhour to 6 and rtcalm to 0x44.
What should we do if we only want the system to remind us to get up at in March? This problem is a piece of cake for S3C2440, as long as we write 4 in almmon, and then change rtcalm to 0x54.
In short, the system compares the value in the current time and alarm time data register according to the corresponding bit set by rtcalm. If the value is equal, the system enters the interrupt, no matter what form of the alarm is set, the global enable of the alarm must be set.
Some functions can be implemented based on this: the time cycle interrupt is set to 1 s, each cycle interrupt writes a string of characters "Beat int" to the serial port ". When an alarm is set to interrupt after power-on, a character is written to the serial port one minute after power-on.
String "alarm int ".
Perform the TRC operation of S3C2440