fl { Thermal printer ID597(ver 2.68) PropForth 5.5 2014/12/13 20:14:13 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, \ No operation \ wvariable FF -2 allot 1 c, 0 c, h0C c, \ Same as LF 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, \ No operation 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 \ No operation 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, 0 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 : prtcmd 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 ; \ ----------------------------------------------- \ Word for Thermal Printer \ ----------------------------------------------- \ Initialize printer ( -- ) : init_prt ESC_@ prtcmd ; \ Carrige return ( -- ) : linefeed LF prtcmd ; \ code437 ( -- ) : code437 0 ESC_t prtcmd ; \ code850 ( -- ) : code850 1 ESC_t prtcmd ; \ Set bold font ( -- ) : bold_on 1 ESC_SP prtcmd ; \ Cansel bold font ( -- ) : bold_off 0 ESC_SP prtcmd ; \ Set double-width ( -- ) : double_width_on ESC_S0 prtcmd ; \ Cansel double-width ( -- ) : double_width_off ESC_DC4 prtcmd ; \ Set character updown ( -- ) : updown_on 1 ESC_{ prtcmd ; \ Cansel character updown ( -- ) : updown_off 0 ESC_{ prtcmd ; \ Set reverse mode ( -- ) : reverse_prt_on 1 GS_B prtcmd ; \ Cansel reverse mode ( -- ) : reverse_prt_off 0 GS_B prtcmd ; \ Set font size ( n -- ) n:font size 7