fl hex { PropForth4.6 pulse monitor Blood Using LBR-127HLD as sensor. 12/10/2011 23:26:20 } d wconstant _pulse 5F5E1000 constant 20sec wvariable pulse_count variable total_time variable pulse_array 1c allot wvariable pulse_rate 1 _pulse lshift constant _pulsem \ ( -- ) shift contents of pulse_array from pulse_array[n] to pulse_array[n-1] : pulse_array_shift pulse_array 7 0 do dup i 1+ 4 u* + dup L@ swap 4 - L! \ store pulse_array[n] to pulse_array[n-1] loop drop ; \ ( -- not-zero/zero ) _pulsem's status( High or Low) : pulse_status ina COG@ _pulsem and ; \ ( cnt not-zero/zero -- cnt not-zero/zero t/f ) pulse-time is valid? t:no good f:good : pulse_valid? over cnt COG@ swap - clkfreq > if 1 else 0 then ; \ ( -- ) mesurement of pulse per minute \ pulse-value is average of 8 pulse-time. : pulse _pulse pinin \ set _pulse to input begin 0 pulse_count W! 0 total_time L! pulse_array 8 0 do dup 0 swap L! 4+ loop drop _pulsem _pulsem waitpeq \ wait until _pulse is high _pulsem _pulsem waitpne \ wait until _pulse is low begin cnt COG@ begin \ stay while _pulse is low pulse_status 0<> pulse_valid? if 2drop 0 1 \ NG pulse-time exceed 1sec else dup if 1 then \ OK then until if begin \ stay while _pulse is high pulse_status 0= pulse_valid? if 2drop 0 1 \ NG pulse-time exceed 1sec else dup if 1 then \ OK then until if cnt COG@ swap - dup pulse_count W@ 8 < if total_time L@ + total_time L! pulse_count W@ 4 u* pulse_array + L! \ store pulse-time to pulse_array[0] - pulse_array[7] else total_time L@ + pulse_array L@ - total_time L! pulse_array_shift pulse_array 1c + L! \ store pulse-time to pulse_array[7] then 1 pulse_count W+! \ check pulse_array { pulse_array 8 0 do dup L@ . 4+ loop drop cr 20sec total_time L@ dup . pulse_count W@ dup 8 > if drop 8 then dup . u/ dup . u/ 3 u* . cr } 20sec total_time L@ pulse_count W@ dup 8 > if drop 8 then u/ u/ 3 u* pulse_rate W! 0 else 1 then else 1 then until 0 until ; : pulse_monitor c" pulse" 5 cogx lcd_init 10 2 lcd_setup \ 16characters 2line \ Defsult setting is 16Charcters & 4Lines bf_set \ set number of BigFont's characters and lines set_char_segment \ set character for bigfont bf_clear \ clear BigFont LCD 0 begin 3e8 delms pulse_count W@ 0> if pulse_rate W@ dup dup . dup c8 < if rot if 3 1 bf_pos 20 set_big_font then \ if display is more than 100, lowest digit is erased. 1 1 bf_pos bf_dec 63 > if 1 else 0 then else \ if more than 200 3drop 0 then else 1 1 bf_pos 2d set_big_font 2 1 bf_pos 2d set_big_font 3 1 bf_pos 20 set_big_font then \ st? 0 until ; decimal