fl { POV_I - Copy character to sheet by POV(Blue LED) -- PropForth5.5 2013/05/04 13:18:13 Serial-pararel-conversion by using shift-register(74HC595 2pcs) P0 -- Shift Clock P1 -- Data P2 -- Latch Clock P16 -- P19 StepMotor(Unipolar) } \ ---------------- LEDs ---------------------------------------------------------------- 0 wconstant _sc 1 wconstant _data 2 wconstant _lc : _sc_l _sc pinlo ; : _sc_h _sc pinhi ; : _data_l _data pinlo ; : _data_h _data pinhi ; : _lc_l _lc pinlo ; : _lc_h _lc pinhi ; \ Set LED-port to output \ ( -- ) : set_up _sc 3 0 do dup pinout 1+ loop drop ; \ --------------- StepMotor --------------------------------------------------------------- d16 wconstant _motor variable position variable step_mask wvariable full_step -2 allot 3 c, 6 c, hC c, 9 c, \ phase_data for full-step \ initialize step-motor(Unipolar) \ ( -- ) : init_motor _motor 4 0 do dup pinout 1+ loop drop \ Set dira hF _motor lshift invert outa COG@ and step_mask L! 0 position L! ; \ ----------------------------------------------------------------------------------------- \ Off LEDs \ ( -- ) : off _data_l \ Set data d16 0 do _sc_h _sc_l loop \ Set data to SR _lc_h _lc_l \ Set data to SR's output ; \ Shift out 16bits-data \ ( n -- ) n:16bit data : shift_out d16 0 do dup 1 and \ Check bit0 if _data_h else _data_l then \ Set data to hi/lo 1 rshift \ Shift 16bit-data to right ( next bit is bit[n+1]) _sc_h _sc_l \ Shift clock loop drop _lc_h _lc_l \ Latch clock ; \ Move step-motor \ ( -- ) : Motor \ init_motor position L@ 3 and d30 0 do 1+ dup 4 = if drop 0 then \ Get number(0 - 3) dup full_step + C@ _motor lshift \ Get address for stepping-motor-data step_mask L@ or outa COG! \ Set step-motor-data to motor position L@ 1+ position L! \ Update position 1 delms loop drop ; \ Output character ( Correctly not output except for alphabet/numeric ) wvariable char_line wvariable odd \ ( n -- ) n:character code : char_out dup 1 and if 2 else 1 then odd W! \ Check even/odd hFE and d64 u* h8000 + \ Get ROM Font address d20 + \ Skip 5-line(5 Long) d27 0 do dup L@ odd W@ \ Get 1-row (16bits) d16 0 do 2dup and if char_line W@ h10000 or else char_line W@ then 1 rshift char_line W! 2 lshift loop \ Set LEDs char_line W@ shift_out d100 delms off \ Move 2mm Motor { \ Print 16bit-data to terminal char_line W@ 1 d16 0 do 2dup and if h2A else bl then emit 1 lshift loop 2drop cr } 2drop 4 + loop drop ; \ Output string to POV \ ( cstr -- ) cstr:string addr : POV_str C@++ \ ( c-addr+1 c1 ) c-addr+1: string's first char addr c1:string length dup if bounds do i C@ char_out loop \ Print string else 2drop then ; : POV_I \ Initialize LED set_up \ Set LED-port to output off \ Reset shift-register's output \ Initialize motor init_motor c" Forth" POV_str ; { d16 wconstant _motor variable position variable step_mask wvariable full_step -2 allot 3 c, 6 c, hC c, 9 c, \ phase_data for full-step \ initialize step-motor(Unipolar) \ ( -- ) : init_motor _motor 4 0 do dup pinout 1+ loop drop \ Set dira hF _motor lshift invert outa COG@ and step_mask L! 0 position L! ; } \ Move step-motor \ ( -- ) : testM init_motor position L@ 3 and d50 0 do 1+ dup 4 = if drop 0 then \ Get number(0 - 3) dup full_step + C@ _motor lshift \ Get address for stepping-motor-data step_mask L@ or outa COG! \ Set step-motor-data to motor position L@ 1+ position L! \ Update position 1 delms loop drop ; \ ************************************************************************** \ LED HardWare test \ ( -- ) : shift_test \ Set to output set_up 1 d16 0 do dup st? 1 and if _data_h else _data_l then 1 lshift _sc_h _sc_l \ Shift clock _lc_h _lc_l \ Latch clock d500 delms loop drop off ; \ it takes 161808ticks(2.0026msec) for shift-out 16bit-data. : test set_up cnt COG@ h1234 shift_out cnt COG@ swap - . ;