Luc Pauwels

Clock program

Eric J. Zmyslowski
March 9, 1989

Date: Thu, 9 Mar 89 14:03:53 EST
Reply-To: HP-28 - HP-28C and HP-28S Calculators <HP-28@NDSUVM1>
Sender: HP-28 - HP-28C and HP-28S Calculators <HP-28@NDSUVM1>
From: GRIK@MTUS5
Subject: Clock program

Well, here's a program I'd like to share with you all... It is a clock program that not only displays (and updates) time, but also day of week, month, and year.

Sample output:

                 12:25:30 am
           Tuesday
           March 10, 1989
This ``clock'' program consists of 16 sub-programs, so it is suggested that these subprograms are put in a directory (for 28S owners).

e.g.

         'D.Time' <ENTER> CRDIR

And access the clock program from the main (home) directory like so:

         << D.Time CLOCK HOME >>  <ENTER>
         'CLOCK' STO
Please note that certain ``subprograms'' are just data, and numbers. Certain of these subprograms require installation, these will be noted and explained when needed. Also most of the subprograms will have a brief description.

PROGRAM CLOCK:

Please note certain notations:
   << STD IF 24 FS? THEN CLLCD END DO TIME 3600 / ->HMS CORRECT HMS- 24
   MOD MINUTES 1 DISP IF 25 FS? THEN DAY 2 DISP DDATE 3 DISP END
   UNTIL KEY END CLMF DROP >>  <ENTER>
   'CLOCK' STO
This program is the main program, which does the displaying and calling of other programs. Notice the two flag checks (24 and 25), if these don't suit you, change them; flag 24 checks to see if the LCD (screen) should be cleared or not, flag 25 checks to see if just the time should be displayed or if the time and the date should be displayed.
   [3 10 1989] <ENTER>
   'DATE' STO
This is just a variable (vector) that contains the current date.
   3 <ENTER>
   'DNUM' STO
This is just a variable that contains the number of the current day of the week. (1=sunday, 2=monday, ..., 7=saturday)
   << DUP IF 12 >= THEN 12 - " pm" IF SWAP DUP ROT ROT 1 < THEN SWAP 12
   + SWAP END ELSE " am" END SWAP IF DUP NOT THEN 12 + END IF TIME 3600
   / ->HMS CORRECT HMS- 24 / IP YSTRDAY - 0 <> THEN CLND1 END DUP IP
   ->STR ":" + SWAP FP ->STR DUP 2 3 SUB ":" + SWAP 4 5 SUB + + SWAP
   + "        " SWAP + >>  <ENTER>
   'MINUTES' STO
   
This program called by CLOCK checks to see if the current date is correct, and if not it calls CLND1 to correct it. This program also builds up the string that contains the time. You may notice the colon characters in the body of the program, and there is no key on the HP-28 that has that character. If you do not know how to get that colon character in the body of the program, then replace:

":" with 58 CHR

Although the ":" is more efficient the 58 CHR will produce the same effect.

   << YSTRDAY TIME 3600 / ->HMS CORRECT HMS- 24 / IP DUP 'TODAY' STO
   SWAP - 7 MOD DNUM + 7 MOD DUP IF 0 == THEN 7 + DUP ELSE DUP END
   'DNUM' STO WEEK SWAP GET 'DAY' STO CLND2 >>  <ENTER>
   'CLND1' STO
This program updates the day of the week (DNUM and DAY).
   << DATE DUP 2 GET TODAY YSTRDAY - + 2 SWAP PUT DUP 'DATE' STO IF DATE
   2 GET YMONTHS DATE 1 GET GET > THEN DATE 1 GET 1 + DUP IF 12 > THEN
   12 - END 1 SWAP PUT 2 DATE 2 GET YMONTHS DATE 1 GET GET - PUT END IF
   DATE 1 GET 12 == DATE 2 GET 31 > AND THEN DATE 3 GET 1 + 3 SWAP PUT
   1 1 PUT 2 1 PUT END 'DATE' STO CLND3 >>  <ENTER>
   'CLND2' STO
This program updates the day, month, and year (does not take into account for leap years, and if run on 12-31 it will update to 1-1 the following year. This program then calls CLND3
   << DATE 2 GET ->STR YEAR DATE 1 GET GET SWAP DATE 3 GET ->STR ", "
   SWAP + + " " SWAP + + 'DDATE' STO TODAY 'YSTRDAY' STO >>  <ENTER>
   'CLND3' STO
This program builds the current date string (DDATE) and update YSTRDAY.
   { "January" "February" "March" "April" "May" "June" "July" "August"
   "September" "October" "November" "December" }  <ENTER>
   'YEAR' STO
This is just a list containing the months of the year.
   [[ 31
      28
      31
      30
      31
      30
      31
      31
      30
      31
      30
      31 ]]  <ENTER>
   'YMONTHS' STO
This is an array that contains the number of days in the months.
   "Tuesday"  <ENTER>
   'DAY' STO
A string that contains the current day of the week.
   { "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday"
   "Saturday" }  <ENTER>
   'WEEK' STO
A list containing the days of the week.
   "March 10, 1989"  <ENTER>
   'DDATE' STO
A string contaning the current date.
   << #11CAh SYSEVAL RCWS 40 STWS SWAP B->R 8192 / SWAP STWS >>  <ENTER>
   'TIME' STO
This piece of code compliments of Hewlett Packard.

*WARNING*
Check which version you have, before using SYSEVAL! Here are the appropriate numbers to use for the different versions: (if you don't know how to check which version you have, consult your owners manual)

Version:        1BB                 1CC                2BB
               -----               -----              ------
               #123E               #1266              #11CAh
On versions 1BB and 1CC make sure it is in HEX mode.
   417  <ENTER>
   'TODAY' STO

   417 <ENTER>
   'YSTRDAY' STO
These two programs contain numbers which are used in counting the number of days that have passed by since last run. These two numbers are arbitrary and will be different for every HP-28. Here is how to install these two numbers to your machine:
  1. Run the program TIME.
  2. Take the value returned by TIME and do the following:
                3600 / ->HMS 24 / IP
  3. Store this value in both TODAY and YSTRDAY.
   -1.0708  <ENTER>
   'CORRECT' STO
This variable contains a number that is used in correcting the calculator time to correspond with actual time. Here is how to install it to your machine:
  1. Store 0 in CORRECT
  2. Run the program CLOCK (note difference between actual time)
  3. Calculate the offset value to be stored in CORRECT as follows:
    1. Key in the number displayed by clock, press <ENTER>
    2. Key in the actual time (in 12 or 24 hour H.MS format)
    3. Press HMS- to calculate the offset value
  4. Store the offset value in CORRECT
Well, there you go... everything should run correctly! Just run the program CLOCK and watch it go....

Press any key to stop execution of the program (except the ON key, doing so will stop the program but will leave extraneous stuff on the stack).


Notes:
Eric J. Zmyslowski
GRIK@MTUS5.Bitnet