Author: Yang Shuo,Hua Qing vision embedded college lecturer.
1. Overview
RTC functions: Generally, RTC is used to provide reliable system time, including information such as year, month, day, hour, minute, and second.
RTC works properly when the system is shut down, because it is powered by a backup battery.
The peripheral of RTC does not require too many auxiliary circuits. Typically, you only need a high-precision 32.768khz crystal oscillator and capacitor, as shown in:
In the past, the RTC module was an independent chip. Now, with the maturity of SOC Technology, more RTC is integrated into the chip, and an RTC module is integrated into the S3C2410 module.
Many embedded products have RTC functions, such as mobile phones, electronic calendars, digital products, and set-top boxes.
The RTC of S3C2410 has the following features:
● Clock data is encoded with BCD (four binary digits are used to represent a decimal number)
● Clock data includes: year, month, day, hour, minute, second, and week
● Automatically process the year, month, and day of a leap year
● Alarm function (Interrupt: int_rtc)
● Independent Power Input
● Millisecond-level clock interruption (kernel clock for embedded real-time operating systems)
2. Structure
RTC 2410 consists of five parts:
● Clock generator
● Beat Generator
● Time and date counters
● Alarm Generator
● Control logic
As shown in:
3. Registers
Control Register: rtccon
Alarm Control Register: rtcalm
Real-time clock Counter: ticnt
Alarm time registers: almsec, almmin, almhour, almdate, almmon, almyear
4. Real-time clock programming steps
1) initialize the real-time clock
Void inittime ()
{
Rrtccon = 0x0;
}
2) write the current time to the real-time clock register
Void settime (struct time * t)
{
Rrtccon | = 0x01;
Rbcdyear = T-> year;
Rbcdmon = T-> mon;
Rbcdday = T-> weekday;
Rbcddate = T-> day;
Rbcdhour = T-> hour;
Rbcdmin = T-> min;
Rbcdsec = T-> sec;
Rrtccon & = 0xfe;
}
3) read time and display
Void gettime (struct time * t)
{
Rrtccon | = 0x01;
While (1)
{
T-> year = rbcdyear;
T-> MON = rbcdmon;
T-> weekday = rbcdday;
T-> day = rbcddate;
T-> hour = rbcdhour;
T-> min = rbcdmin;
T-> sec = rbcdsec;
If (t-> sec! = 0)
Break;
}
Rrtccon & = 0xfe;
}