fl { POV_I - Copy character to sheet by POV(Blue LED) -- PropForth5.5 2013/05/05 18:52:26 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 position L@ 3 and d15 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 { address column row n b31 b30 b29 . . . b1 b0 | n+4 0 0 0 0 0 | . | . \|/ n+d124 0 0 0 0 0 } variable row_line variable odd \ ( n -- ) n:character code : char_out_1 dup 1 and if 2 else 1 then odd L! \ Check even/odd hFE and d64 u* h8000 + \ Get ROM Font address d28 + \ Skip 7-line(7 Long) \ column=d16 d16 0 do dup d23 0 do i 2 <> if i 7 <> if i 9 <> if i d11 <> if i d13 <> if i d18 <> if i d20 <> if \ Skip lines row_line L@ 1 lshift row_line L! dup L@ odd L@ 2dup and if row_line L@ 1 or row_line L! then 2drop thens 4 + \ Add +4 to address loop drop \ Set LEDs row_line W@ shift_out d100 delms off \ Move 1mm Motor { \ Print 16bit-data to terminal row_line L@ 1 d16 0 do 2dup and if h2A else bl then emit 1 lshift loop 2drop cr } odd L@ 2 lshift odd L! \ next colummn bit loop drop ; \ Output string to POV \ ( cstr -- ) cstr:string addr : POV_str_1 C@++ \ ( c-addr+1 c1 ) c-addr+1: string's first char addr c1:string length dup if bounds do i C@ char_out_1 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" May the Forth be with you." POV_str_1 ; \ ************************************************************************** \ 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 - . ;