Here is how I have done it:
Code:
/*
Get the time from the HMI and write it to the PLC tags
The Micrologix uses Fucntion Files RTC:0 which cannot be accessed
directly by the HMI. The PLC is programmed to update the N registers
with the RTC values unless the Set button is pressed.
The button which calls this program first sets the button. The PLC
reads that button and reverses its copy so that when this program runs, the data is updated
in reverse, then the last line turns the button back off.
*/
int i := GetNow();
PLC.MAIN.Clock.PLC_Year := GetYear(i);
PLC.MAIN.Clock.PLC_Month := GetMonth(i);
PLC.MAIN.Clock.PLC_Day := GetDate(i);
PLC.MAIN.Clock.PLC_Hour := GetHour(i);
PLC.MAIN.Clock.PLC_Min := GetMin(i);
PLC.MAIN.Clock.PLC_Sec := GetSec(i);
PLC.MAIN.Clock.Set := 0;
Which is quite similar to Troy's example. My tags are in folder hierarchy and I had two PLCs in this application (MAIN and Filters) so I had two programs like this, each with their own tags from each PLC.
My tags are set up as "N" registers in the Micrologix, and the last tag shown (PLC.MAIN.Clock.Set) is set when I want to tell the Micrologix to write those "N" registers to the RTC function file addresses.
In my case, N15:3/15 is the bit used to trigger the clock update, and N15:137 is the year value from the Red Lion and the next 5 values are Month, Day, Hour, Minute, and Second.
I use a button on a page to set the trigger bit when pressed and call the program when released.
In the PLC, when the trigger bit is set, the values are copied from the N registers to the RTC function files, and when the trigger bit is not set, the copy direction is reversed, so that the values shown on my "clocks" page will show the contents of the PLCs clocks.
The two rung mnemonics:
XIC N15:3/15 CPW #N15:137 #RTC:0.YR 6
XIO N15:3/15 CPW #RTC:0.YR #N15:137 6