fl hex { Set time to DS1337 by using Denpatokei(Radio Controlled Clock) Read time from DS3231 PropForth 4.6 14/08/2011 08:14:57 Adding measure_timeshift 20/10/2011 13:23:36 } 6 wconstant _1Hz \ 1Hz squware-wave output 1 _1Hz lshift constant _1Hzm { \ ( -- ) set time to DS3231 [CONV=0 RS1=RS2=0 INTCON=0] : set_DS3231 0 _DS3231_control_w denpatokei \ set second/minute/hour/week/day/month/year on stack 0 minute W@ >bcd hour W@ >bcd week W@ day W@ >bcd month W@ >bcd year W@ >bcd _DS3231_time_w \ set time to DS3231 \ display ." Year " year W@ 7d0 + . ." Month " month W@ . ." Day " day W@ . ." Week " week W@ . ." Hour " hour W@ . ." Minute" minute W@ . cr ; } \ ( -- n1 n2 ) read temperature inside chip n1:integer portion n2:fractional portion : Temp _read_temp 6 rshift 19 u* ; \ ( -- ) write temperature-data to pad>out : _temp_datastr Temp # # drop 2e #C # # drop ; \ ( -- ) display rtc's data : read_DS3231 _DS3231_time_r ." Year :" bcd> 7d0 + . cr \ ." Month :" <# _rtc_mon 0 #> .cstr cr ." Month :" 10 over = if drop a else 11 over = if drop b else 12 over = if drop c thens <# _rtc_mon 0 #> .cstr cr ." Day :" bcd> . cr ." week :" <# _rtc_dow 0 #> .cstr cr ." Hour :" bcd> . cr ." Minute:" bcd> . cr ." Second:" bcd> . cr ." Temperature:" <# _temp_datastr 0 #> .cstr ." degree" cr ; \ ( -- ) measure 1sec(ticks) : check_1Hz _1Hzm _1Hzm waitpeq \ wait for _1Hz to go to high 0 _1Hzm waitpeq \ wait for _1Hz to go to low cnt COG@ _1Hzm _1Hzm waitpeq \ wait for _1Hz to go to high 0 _1Hzm waitpeq \ wait for _1Hz to go to low cnt COG@ swap - dup cr ." 1sec(ticks):" . cr ." Difference(ticks):" clkfreq - . cr ; \ (n1 -- ) temperature-compensated : conpensate _write_offset 20 _DS3231_control_w begin _DS3231_control_r 20 = if ." ." 0 else 1 then until check_1Hz ; : check_temp begin _DS3231_time_r 3drop drop bcd> . bcd> . bcd> . <# _temp_datastr 0 #> .cstr ." degree" cr 3e8 delms 0 until ; : timeshift_>1sec denpatokei \ wait 0second _DS3231_time_r ." Year :" bcd> 7d0 + . cr ." Month :" <# _rtc_mon 0 #> .cstr cr ." Day :" bcd> . cr ." week :" <# _rtc_dow 0 #> .cstr cr ." Hour :" bcd> . cr ." Minute:" bcd> . cr ." Second:" bcd> . cr ; : timeshift_<1sec denpatokei \ wait 0second cnt COG@ _1Hzm ina COG@ and \ 1Hz-pulse's current status is Low or High? if begin _1Hzm ina COG@ and 0= until \ wait untl 1Hz-pulse's current status is Low else begin _1Hzm ina COG@ and until \ wait untl 1Hz-pulse's current status is High begin _1Hzm ina COG@ and 0= until \ wait untl 1Hz-pulse's current status is Low then cnt COG@ swap - . \ calculate time ; decimal