fl { Thermal printer ID597 PropForth 5.5 2014/12/11 13:21:38 ID597 PowerSupply 1 GND ------ GND 2 NC Propeller 3 VH ------ 5V4A Gnd ------ 4 Gnd P1 ------ 5 Rx P0 ------ 6 Tx RS232 19200bps Noparity Stopbit1 time ------------------------------------------------------------>> ------- --------- ------------ | | | | | | | | ----- ----------------------------- idle start bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 stop stop idle bit bit (always "0") (always "1") } \ =========================================================================== \ Constants \ =========================================================================== \ Priner command wvariable LF -2 allot 1 c, 0 c, h0A c, wvariable HT -2 allot 1 c, 0 c, h09 c, wvariable FF -2 allot 1 c, 0 c, h0C c, wvariable ESC_J -2 allot 2 c, 1 c, h1B c, h4A c, wvariable ESC_FF -2 allot 2 c, 0 c, h1B c, h0C c, wvariable ESC_d -2 allot 2 c, 1 c, h1B c, h64 c, wvariable ESC= -2 allot 2 c, 1 c, h1B c, h3D c, wvariable ESC_2 -2 allot 2 c, 0 c, h1B c, h32 c, wvariable ESC_3 -2 allot 2 c, 1 c, h1B c, h33 c, wvariable ESC_a -2 allot 2 c, 1 c, h1B c, h61 c, wvariable GS_L -2 allot 2 c, 2 c, h1D c, h4C c, wvariable ESC_$ -2 allot 2 c, 2 c, h1B c, h24 c, wvariable ESC_B -2 allot 2 c, 1 c, h1B c, h42 c, wvariable ESC_! -2 allot 2 c, 1 c, h1B c, h21 c, wvariable GS_! -2 allot 2 c, 1 c, h1D c, h21 c, wvariable ESC_E -2 allot 2 c, 1 c, h1B c, h45 c, wvariable ESC_SP -2 allot 2 c, 1 c, h1B c, h20 c, wvariable ESC_S0 -2 allot 2 c, 0 c, h1B c, h0E c, wvariable ESC_DC4 -2 allot 2 c, 0 c, h1B c, h14 c, wvariable ESC_{ -2 allot 2 c, 1 c, h1B c, h7B c, wvariable GS_B -2 allot 2 c, 1 c, h1D c, h42 c, wvariable ESC_- -2 allot 2 c, 1 c, h1B c, h2D wvariable ESC_% -2 allot 3 c, 0 c, h1B c, h25 c, 1 c, wvariable ESC_& -2 allot 2 c, 4 c, h1B c, h26 c, wvariable ESC_? -2 allot 3 c, 0 c, h1B c, h25 c, 0 c, wvariable ESC_R -2 allot 2 c, 1 c, h1B c, h52 c, wvariable ESC_t -2 allot 2 c, 1 c, h1B c, h74 c, wvariable ESC_* -2 allot 2 c, 3 c, h1B c, h2A c, wvariable GS_/ -2 allot 2 c, 1 c, h1D c, h2F c, wvariable GS_* -2 allot 2 c, 2 c, h1D c, h2A c, wvariable GS_v -2 allot 3 c, 5 c, h1D c, h76 c, 0 c, wvariable DC2_* -2 allot 2 c, 2 c, h12 c, h2A c, wvariable DC2_V -2 allot 2 c, 2 c, h12 c, h56 c, wvariable DC2_v -2 allot 2 c, 2 c, h12 c, h76 c, wvariable ESC_c -2 allot 3 c, 1 c, h1B c, h63 c, h35 c, wvariable ESC_@ -2 allot 2 c, 0 c, h1B c, h40 c, wvariable ESC_v -2 allot 2 c, 0 c, h1B c, h76 c, wvariable GS_a -2 allot 2 c, 1 c, h1D c, h61 c, wvariable ESC_u -2 allot 2 c, 0 c, h1B c, h75 c, wvariable GS_H -2 allot 2 c, 1 c, h1D c, h48 c, wvariable GS_h -2 allot 2 c, 1 c, h1D c, h68 c, wvariable GS_x -2 allot 2 c, 1 c, h1D c, h78 c, wvariable GS_w -2 allot 2 c, 1 c, h1D c, h77 c, wvariable GS_k_1 -2 allot 2 c, 1 c, wvariable GS_k_2 -2 allot 2 c, 2 c, wvariable ESC_7 -2 allot 2 c, 3 c, h1B c, h37 c, wvariable ESC_8 -2 allot 2 c, 1 c, h1B c, h38 c, wvariable DC2_# -2 allot 2 c, 1 c, h12 c, h23 c, wvariable DC2_T -2 allot 2 c, 0 c, h12 c, h54 c, 0 wconstant Rx 1 wconstant Tx d19200 constant baud \ =========================================================================== \ Main \ =========================================================================== { half duplex serial structure 00 - 03 -- bitticks 04 - 07 -- rx pin mask 08 - 0B -- tx pin mask } \ hdserialStruct X ( baud rxpin txpin -- ) X is structure's name : hdserialStruct lockdict variable 8 allot lastnfa nfa>pfa 2+ alignl freedict tuck swap >m swap 8 + L! tuck swap >m swap 4 + L! swap clkfreq swap u/ swap L! ; \ Assembler word Half Duplex serial Transmit \ ( n1 n2 -- ) n1:sending data n2:hdserialStruct's name lockdict create a_hdserialTx forthentry $C_a_lxasm w, h127 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z8i[ZB l, z20yPO8 l, z8i[eB l, z1SyLI[ l, z1biPS] l, zfyPO1 l, z2WyPbB l, z2WiPn[ l, z20iPqk l, z1YVPO1 l, z1rixn\ l, z3riPn[ l, zbyPO1 l, z3[yPfS l, z1SyLI[ l, z1[ixn\ l, z1SV01X l, 0 l, 0 l, zC0 l, freedict \ Assembler word Half Duplex serial Receive \ ( n1 -- n2 ) n1:hdserialStruct's name n2:receving data lockdict create a_hdserialRx forthentry $C_a_lxasm w, h126 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z8i[ZB l, z20yPO4 l, z8i[eB l, z2WyPW8 l, z2WyPO0 l, z2WiPf[ l, zbyPb2 l, z20iPf[ l, z3jF[f\ l, z3nF[f\ l, z20iPik l, z3riPf[ l, z1YF[il l, zbyPO1 l, z1vyPQ0 l, z3[yP[U l, z1SV01X l, 0 l, 0 l, freedict \ Build serial-structure baud Rx Tx hdserialStruct serial \ Send command to ThermalPrinter \ ( nn-nm n1 -- ) nn-nm:data if needed n1:command : prncom dup C@ over 2+ swap 0 do dup C@ serial a_hdserialTx 1+ loop drop \ Serial out command 1+ C@ dup 0<> if 0 do serial a_hdserialTx loop \ Serial out data else drop then ; \ Set up initial data when 5V is supplied on ID597 \ ( -- ) : setup \ Set controll parameter d255 d255 7 ESC_7 prncom d255 DC2_# prncom ; \ Print string on ID597 \ ( n1 -- ) n1:cstr : prn_str C@++ \ ( c-addr+1 c1 ) c-addr+1: string's first char addr c1:string length dup if bounds do i C@ serial a_hdserialTx loop \ Print string else 2drop then LF prncom ; \ Get status \ ( -- ) : GetStatus ESC_v 8 0 do serial a_hdserialRx . loop ; : demo1 setup LF prncom 0 ESC_t prncom c" Character code 437" prn_str \ Print characters h20 d224 0 do dup serial a_hdserialTx 1+ i 1+ d32 u/mod drop 0= if LF prncom then loop drop LF prncom 1 ESC_t prncom c" Character code 850" prn_str c" May the Forth be with you." prn_str \ Print characters h20 d224 0 do dup serial a_hdserialTx 1+ i 1+ d32 u/mod drop 0= if LF prncom then loop drop \ normal c" May the Forth be with you." prn_str \ reverse mode 2 ESC_! prncom c" May the Forth be with you." prn_str \ updown mode 4 ESC_! prncom c" May the Forth be with you." prn_str \ enphasized mode 8 ESC_! prncom c" May the Forth be with you." prn_str \ Double height mode h10 ESC_! prncom c" May the Forth be with you." prn_str \ Double width mode h20 ESC_! prncom c" May the Forth be with you." prn_str \ deleteline mode h40 ESC_! prncom c" May the Forth be with you." prn_str \ bold font 1 ESC_E prncom c" May the Forth be with you." prn_str LF prncom LF prncom LF prncom ; { ( n1 n2 -- ) entry n1:sending data n2:hdserialStruct's name Using register inside $C_treg2:loop counter $C_treg3:ticks(1bit) exit none fl build_BootOpt :rasm rdlong __bitticks , $C_stTOS add $C_stTOS , # 8 rdlong __txmask , $C_stTOS spop or $C_stTOS , __stopbit shl $C_stTOS , # 1 mov $C_treg2 , # d11 mov $C_treg3 , __bitticks add $C_treg3 , cnt __txloop test $C_stTOS , # 1 wz muxz dira , __txmask waitcnt $C_treg3 , __bitticks shr $C_stTOS , # 1 djnz $C_treg2 , # __txloop spop andn dira , __txmask jexit __bitticks 0 __txmask 0 __stopbit h300 ;asm a_hdserialTx } { ( n1 -- n2 ) entry n1:hdserialStruct's name Using register inside $C_treg1:loop counter $C_treg2:next bit count(1st:1.25bit, 2nd-8th:1bit) exit n2:receving data fl build_BootOpt :rasm rdlong __bitticks , $C_stTOS add $C_stTOS , # 4 rdlong __rxmask , $C_stTOS mov $C_treg1 , # 8 mov $C_stTOS , # 0 mov $C_treg2 , __bitticks shr $C_treg2 , # 2 add $C_treg2 , __bitticks \ Wait from hi to lo transition waitpeq __rxmask , __rxmask waitpne __rxmask , __rxmask \ first loop tick count (1.25bit+cnt) add $C_treg2 , cnt __rxloop \ 1bit+cnt waitcnt $C_treg2 , __bitticks test __rxmask , ina wz shr $C_stTOS , # 1 muxnz $C_stTOS , # h80 djnz $C_treg1 , # __rxloop jexit __bitticks 0 __rxmask 0 ;asm a_hdserialRx }