{ program in TurboPASCAL to set real-time-clock loacted at ports 30h through 33h in Morrow MD 2/3 rev.2 main board Mike Allen 8/9/86 } program time; const CLS = ^Z; {Clear Screen} PA = $30; {8255 A register} PB = $31; {8255 B register} PC = $32; {8255 C register} CNTRL = $33; {8255 control register} var rtc: array[0..12] of byte; {MSM8532 registers} i,civil_time: byte; {i=general loop variable, civil_time=24hr, AM or PM indicator} new_in: integer; {new values} begin write(CLS); {clear the screen} port[CNTRL]:=$90; {set up the 8522} port[PC]:=$20; {put MSM5832 in 'read' mode} for i:=2 to 12 do {read top 11 MSM5832 registers} begin port[PB]:=i; {output the register address} rtc[i]:=port[PA] and $0f {read the register and strip the top 4 bits} end; port[PC]:=$00; {take the MSM5832 out of read mode} if rtc[5]>7 then {check for 24hr time} civil_time:=0 else if rtc[5]>3 then {not 24 hr, check for PM} civil_time:=2 else civil_time:=1; {not 24 hr or PM, must be AM} repeat new_in := 10*rtc[12]+rtc[11]; {set input var equ to year} write('Year? <',new_in,'> '); {show what it is} readln(new_in); {get new value. NOTE: turbo Pascal maintains the variable value if nothing is entered for the variable} until new_in in [0 .. 99]; {make sure the year is valid} rtc[12] := new_in div 10; {set up 10s of years} rtc[11] := new_in mod 10; {and 1s of years} repeat new_in := rtc[8] div 4; {get leap year flag} write('Leap Year? [1=yes] <',new_in,'> '); {show what it is} readln(new_in); {get new value} until new_in in [0 .. 1]; {make sure it is valid} rtc[8] := (rtc[8] and $03) or (4 * new_in); {reset/set the flag} repeat new_in := 10*rtc[10]+rtc[9]; {set input equ month} write('Month? <',new_in,'> '); {show what it is} readln(new_in); {get new value} until new_in in [1 .. 12]; {make sure it is valid} rtc[10] := new_in div 10; {set up 10s of months} rtc[9] := new_in mod 10; {and 1s of months} repeat new_in := 10*(rtc[8] and $3)+rtc[7]; {set input equ day} write('Day? <',new_in,'> '); readln(new_in); until new_in in [1 .. 31]; {make sure it is valid (well, mostly)} rtc[8] := (rtc[8] and $4) or (new_in div 10); {set up 10s of days and keep leap year flag} rtc[7] := new_in mod 10; {set up 1s of days} repeat new_in := rtc[6]; {set input equ day of week} write('Day of the week? [0=Sunday, 6=Saturday] <',new_in,'> '); {show it} readln(new_in); {get new value} until new_in in [0 .. 6]; {make sure it is valid} rtc[6] := new_in; {set up day-of-week} repeat write('24 hr[0], AM[1] or PM[2]? <',civil_time,'> '); {show 24hr, AM, PM flag} readln(civil_time); {get new flag} until civil_time in [0 .. 2]; {make sure it is valid} new_in := 10*(rtc[5] and $03) + rtc[4]; {get hours} case civil_time of 0: rtc[5] := (rtc[5] and $03) or $8; {clear pm, set 24 hr flags} 1: rtc[5] := rtc[5] and $03; {clear pm and 24 hr flags} 2: rtc[5] := (rtc[5] and $03) or $4 {set pm, clear 24 hr flags} end; if civil_time > 0 then {make sure 12 hr time values are valid} begin if new_in > 12 then new_in := new_in - 12 else if new_in = 0 then new_in := 12; rtc[5] := (rtc[5] and $4) or (new_in div 10); {set 10s of hrs} rtc[4] := new_in mod 10; {set 1s of hours} repeat new_in := 10*(rtc[5] and $03) + rtc[4]; {set input equ hours} write('Hours? <',new_in,'> '); {show them} readln(new_in); {get new value} until new_in in [1 .. 12]; {make sure it is valid} end else repeat new_in := 10*(rtc[5] and $03) + rtc[4]; {set input equ hours} write('Hours? <',new_in,'> '); {show them} readln(new_in); {get new value} until new_in in [0 .. 23]; {make sure it is valid} rtc[5] := (rtc[5] and $0C) or (new_in div 10); {set 10s of hours} rtc[4] := new_in mod 10; {set 1s of hours} repeat new_in := 10*rtc[3]+rtc[2]; {set input equ minutes} write('Minutes? <',new_in,'> '); {show it} readln(new_in); {get new value} until new_in in [0 .. 59]; {make sure it is valid} rtc[3] := new_in div 10; {set 10s of minutes} rtc[2] := new_in mod 10; {set 1s of minutes} write('Press RETURN to start clock on the minute'); {prompt user} readln; {this allows the clock to be loaded} port[CNTRL] := $80; port[PC] := $10; {turn on the hold} delay(1); {wait a LONG time} for i:=0 to 12 do {write ALL 13 MSM5832 registers to reset seconds} begin port[PB]:=i; {output the register address} port[PA]:=rtc[i] and $0f; {output the bottom 4 bits of the register} port[PC] := $50; {strobe the write line} port[PC] := $10 end; port[PC] := $00; {turn off the hold} port[CNTRL] := $90 {restore the 8255} end. { and retire!}