fl fl { VFD driver(PT6312) PropForth 5.5 2014/06/01 23:34:18 ------------------------ 3.3V | 5V | propeller | | |(PullUp R) PT6312 | P0 -----> S G D ------------------> CLK | 3.3V | 5V | | | |(PullUp R) | P1 -----> S G D ------------------> STB | 3.3V | 5V | | | |(PullUp R) | P2 <----> S G D <-----------------> DIO | MOSFET(2N7000) | | | VFD board | ------------------------ } \ =========================================================================== \ Constants \ =========================================================================== 0 wconstant CLK 1 wconstant STB 2 wconstant DIO DIO >m constant DIOm \ Display mode for command1 0 wconstant 4dig16seg 1 wconstant 5dig16seg 2 wconstant 6dig16seg 3 wconstant 7dig15seg 4 wconstant 8dig14seg 5 wconstant 9dig13seg 6 wconstant 10dig12seg 7 wconstant 11dig11seg \ Data read/write mode for command2 h40 wconstant com2_disp h41 wconstant com2_led h42 wconstant com2_key h43 wconstant com2_sw \ Address 0 wconstant increAddr 4 wconstant fixedAddr \ Mode 0 wconstant normal 8 wconstant test \ Assress setting for command3 hC0 wconstant com3 \ Display control for command4 h80 wconstant com4 0 wconstant dispOff 8 wconstant dispOn \ =========================================================================== \ Variables \ =========================================================================== \ =========================================================================== \ Main \ =========================================================================== \ Set CLK to Hi or Lo \ ( -- ) : CLK_h CLK pinhi ; : CLK_l CLK pinlo ; : clk_wr CLK_l CLK_h ; : clk_rd CLK_h CLK_l ; \ Set STB to Hi or Lo \ ( -- ) : STB_h STB pinhi ; : STB_l STB pinlo ; \ Set DIO to Hi or Lo \ ( -- ) : DIO_h DIO pinhi ; : DIO_l DIO pinlo ; \ Shift out data \ ( n1 -- ) n1:data : shift_out 1 8 0 do 2dup and if DIO_h else DIO_l then 1 lshift clk_wr loop 2drop ; \ Read data \ ( n1 -- n2 ) n1:command n2:data : rd_PT6312 \ write command 1 8 0 do 2dup and if DIO_h else DIO_l then 1 lshift clk_wr loop 2drop \ Set DIN to input DIO pinin CLK pinlo 0 8 0 do 1 lshift clk_rd ina COG@ DIOm and 0<> if 1 else 0 then or loop \ Set DIN to output DIO pinout ; \ Initialize PT6312 \ ( -- ) : init_PT6312 \ Setup ports d200 delms CLK dup pinout pinhi STB dup pinout pinhi DIO pinout \ Set command2 STB_l com2_disp increAddr or shift_out STB_h \ Set command3(clear RAM) h16 0 do STB_l com3 i or shift_out 0 shift_out STB_h loop \ Set command1 STB_l 6dig16seg shift_out STB_h \ Set command4 STB_l com4 dispOn or 7 or shift_out STB_h ; \ Needing data to display on VFD \ ( -- ) : setcommand \ Set command1 STB_l 6dig16seg shift_out STB_h \ Set command4 STB_l com4 dispOn or 7 or shift_out STB_h ; \ Erase data \ ( n1 -- ) n1:address : erase STB_l com3 or shift_out 0 shift_out STB_h setcommand ; \ Display each element on VFD \ ( -- ) : demo1 init_PT6312 \ address10 STB_l d10 com3 or shift_out 1 shift_out STB_h setcommand d200 delms STB_l d10 com3 or shift_out 2 shift_out STB_h setcommand d200 delms STB_l d10 com3 or shift_out 4 shift_out STB_h setcommand d200 delms STB_l d10 com3 or shift_out 8 shift_out STB_h setcommand d200 delms STB_l d10 com3 or shift_out h10 shift_out STB_h setcommand d200 delms d10 erase \ address0 1 9 0 do STB_l 0 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop \ address1 1 8 0 do STB_l 1 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop \ address2 STB_l 2 com3 or shift_out 1 shift_out STB_h setcommand d200 delms STB_l 2 com3 or shift_out h10 shift_out STB_h setcommand d200 delms STB_l 2 com3 or shift_out h20 shift_out STB_h setcommand d200 delms STB_l 2 com3 or shift_out h40 shift_out STB_h setcommand d200 delms STB_l 2 com3 or shift_out h80 shift_out STB_h setcommand d200 delms 2 erase \ address3 2 8 0 do STB_l 3 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop \ address4 2 8 0 do STB_l 4 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop \ address5 2 8 0 do STB_l 5 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop STB_l 5 com3 or shift_out 1 shift_out STB_h setcommand d200 delms 5 erase \ address6 2 8 0 do STB_l 6 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop \ address7 2 8 0 do STB_l 7 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop STB_l 7 com3 or shift_out 1 shift_out STB_h setcommand d200 delms 7 erase \ address8 4 7 0 do STB_l 8 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop \ address9 1 8 0 do STB_l 9 com3 or shift_out dup i lshift shift_out STB_h setcommand d200 delms loop drop 9 erase STB_l 8 com3 or shift_out 1 shift_out STB_h setcommand d200 delms STB_l 8 com3 or shift_out 2 shift_out STB_h setcommand d200 delms 8 erase ; \ Display string'Forth' \ ( -- ) : demo2 init_PT6312 STB_l 5 com3 or shift_out h5A shift_out STB_h STB_l 6 com3 or shift_out hF0 shift_out STB_h STB_l 7 com3 or shift_out h50 shift_out STB_h STB_l 8 com3 or shift_out hB0 shift_out STB_h STB_l 9 com3 or shift_out h79 shift_out STB_h setcommand ;