Page 1 of 1
How to change date and time RTC
Posted: Mon May 14, 2012 11:46 am
by AlexanderSilvaB
Hello, I'm trying to create a C function to change the time and date of the RTC, already have a function that reads data from the RTC. Please help me if you can.
Thank you.
Re: How to change date and time RTC
Posted: Mon May 14, 2012 10:48 pm
by LindusSystem
It is same as reading, use this code
Code: Select all
void write_cmos(unsigned char address, unsigned int value)
{
outportb(ADDRESSREGISTER, address);
outportb(DATAREGISTER,NMI_disable_bit << 7 | data);
}
And write to respective bits, but did u try
this
Re: How to change date and time RTC
Posted: Mon May 14, 2012 10:56 pm
by Brendan
Hi,
AlexanderSilvaB wrote:Hello, I'm trying to create a C function to change the time and date of the RTC, already have a function that reads data from the RTC. Please help me if you can.
The general idea is:
- Split your time into "century, year, month, week, hour, minute, second" stored in temporary variables
- Determine if the RTC is using binary format or BCD and change everything except "hour" to suit
- Determine if the RTC is using 24 hour format or 12 hour format and change "hour" to suit (note: there's 4 cases here - 24 hour binary, 24 hour BCD, 12 hour binary, 12 hour BCD)
- Determine where the "century" goes using ACPI (the "RTC century register" field at offset 108 in the Fixed ACPI Description Table), or discard it if there's no ACPI
- Wait until the RTC's "update in progress" flag goes from "set" to "clear". There's 2 ways of doing this:
- Polling: Loop until the flag becomes set, then loop until the flag becomes clear. This can waste up to 1 second of CPU time.
- Use the RTC's "update IRQ" to avoid wasting CPU time. In this case the next step will be done in the IRQ handler.
- Write the values you've already prepared into the corresponding RTC/CMOS registers, in order (seconds, then minutes, then hour, then ..., then century).
Cheers,
Brendan
Re: How to change date and time RTC
Posted: Thu May 17, 2012 1:18 pm
by AlexanderSilvaB
Thank you...