fl { Serial for Inkjetkit PropForth 5.2 2012/12/12 12:21:36 Modified Sal's code(halfdup) Need level-converter(TC74LCX245) TC74LCX245 3.3V | Propeller(3.3V) --------- | Vcc | 3.3V | | 5V | | | | 10k | | 10k Serial InkjetPrinter(Parallax) refering InkjetkitDocs-v1.o.pdf (5V) | | | | refering InkjetkitDocs-v1.0.pdf (5V) P2 ------| A1 B1 |------------ S P3 ------|DIR | |-- G GND -| --------- | | | GND GND GND signal-dir A1-->B1 when DIR=Low signal-dir A1<--B1 when DIR=High RS232 9600bps Noparity Stopbit1 time ------------------------------------------------------------>> ------- --------- ------------ | | | | | | | | ----- ----------------------------- idle start bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 stop idle bit bit (always "0") (always "1") } hex 3 wconstant dir d27 wconstant ESC d62 wconstant > d02 wconstant STX d03 wconstant ETX d67 wconstant Inter_column d78 wconstant N d84 wconstant T d68 wconstant Display \ Get 1byte \ ( n1 n2 -- n3 ) n1:hdserialStruct n2:dir n3:receive-data(1byte) lockdict create hdserialRx forthentry $C_a_lxasm w, h128 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2WyPj1 l, zfiPmB l, z1SyLI[ l, z1bixZE l, z8iQ3B l, z20yPO8 l, z2WyPj8 l, z8iQBB l, z2WyPO0 l, z2WiPuG l, zbyPr2 l, z20iPuG l, z3jFQBH l, z3nFQBH l, z20iPyk l, z3riPuG l, z1YFQFl l, zbyPO1 l, z1vyPQ0 l, z3[yPnY l, z1SV01X l, freedict \ Send 1byte \ ( n1 n2 n3 -- ) n1:transmit-data(1byte) n2:hdserialStruct n3:dir lockdict create hdserialTx forthentry $C_a_lxasm w, h12A h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2WyPW1 l, zfiPZB l, z1SyLI[ l, z1[ixZC l, z1SyLIZ l, z20yPW4 l, z8iQ3C l, z20yPW8 l, z8iQBC l, z1biPSc l, zfyPO1 l, z2WiPuG l, z20iPyk l, z2WyPjB l, z3riPuG l, z1YVPO1 l, z1rixmH l, zbyPO1 l, z3[yPnX l, z1SyLI[ l, z1[ixmH l, z1SV01X l, zC0 l, freedict { half duplex serial structure 00 - 04 -- rx bitticks 04 - 08 -- tx bitticks 08 - 0C -- rx pin mask 0C - 10 -- tx pin mask } \ hdserialStruct ( rxbaud txbaud rxpin txpin -- ) : hdserialStruct lockdict variable hC allot lastnfa nfa>pfa 2+ alignl freedict tuck swap >m swap hC + L! tuck swap >m swap h8 + L! tuck swap clkfreq swap u/ swap h4 + L! swap clkfreq swap u/ swap L! ; \ HalfDuplex [Receive 9600bps P2 Transmitt 9600bps P2 ] d_9600 d_9600 d_2 d_2 hdserialStruct ser : test \ Set dir to output dir pinout ESC ser dir hdserialTx ser dir hdserialRx . ; decimal { \ ( n1 n2 n3 -- ) n1:1byte data n2:hdserialStruct n3:dir fl build_BootOpt :rasm \ treg6 - serpin mask \ treg5 - bitticks \ treg4 - cnt nextbit \ treg1 - serialStruct \ stTOS - data \ Get dir mov $C_treg1 , # 1 shl $C_treg1 , $C_stTOS spop \ Set dir to lo (3.3V-->5V) andn outa , $C_treg1 spopt add $C_treg1 , # h4 rdlong $C_treg5 , $C_treg1 add $C_treg1 , # h8 rdlong $C_treg6 , $C_treg1 \ \ serpin high \ \ or outa , $C_treg6 \ or dira , $C_treg6 \ \ data + 2 stop bits + start bit \ or $C_stTOS , __h300 shl $C_stTOS , # 1 \ \ first loop tick count count \ mov $C_treg4 , $C_treg5 add $C_treg4 , cnt mov $C_treg3 , # d_11 __txloop waitcnt $C_treg4 , $C_treg5 test $C_stTOS , # 1 wz \ muxnz outa , $C_treg6 muxz dira , $C_treg6 shr $C_stTOS , # 1 djnz $C_treg3 , # __txloop spop \ \ serpin in \ andn dira , $C_treg6 \ jexit __h300 h300 ;asm hdserialTx \ ( n1 n2 -- n3 ) n1:hdserialStruct n2:dir n3:receive-data fl build_BootOpt :rasm \ treg6 - serpin mask \ treg5 - bitticks \ treg4 - cnt nextbit \ treg1 - serialStruct \ stTOS - data mov $C_treg3 , # 1 shl $C_treg3 , $C_stTOS spop \ Set dir to hi (3.3V<--5V) or outa , $C_treg3 rdlong $C_treg5 , $C_stTOS add $C_stTOS , # h8 \ \ receive bit counter \ mov $C_treg3 , # d_8 \ rdlong $C_treg6 , $C_stTOS \ \ serpin as input \ \ andn dira , $C_treg6 \ \ data byte \ mov $C_stTOS , # 0 \ \ first loop tick count, 1.25 bit times so we sample closer to the middle \ necessary in the assembler routine, in the forth routine, the delays of the loop setup \ make this unecessary so we only use 1 bit time \ mov $C_treg4 , $C_treg5 shr $C_treg4 , # 2 add $C_treg4 , $C_treg5 \ \ wait for a hi to lo transition \ waitpeq $C_treg6 , $C_treg6 waitpne $C_treg6 , $C_treg6 \ \ first loop tick count \ add $C_treg4 , cnt __rxloop waitcnt $C_treg4 , $C_treg5 test $C_treg6 , ina wz \ shr $C_stTOS , # 1 muxnz $C_stTOS , # h_80 \ djnz $C_treg3 , # __rxloop \ jexit ;asm hdserialRx }