LPrint for attached serial printer - legacy BASIC statement

Modified on 2017/12/22 11:26 by CaptainBoing — Categorized as: Control, Hardware, Printers and Printing, Program Flow, Strings

I have a couple of systems that log to small embedded Printers. It's not always convenient or necessary to go to the lengths of building a centronics port and getting hold of a trusty Epson FX80. This solution coupled with the printer in the above article will have you up and running in minutes!

You could use one of the existing built in COM ports but as you often need these for other stuff (the printer only needs Tx from the MM anyway) it's a bit of a waste and even if you have one spare, it kind-of sticks in my throat to waste it for a single pin.

In the software distribution of MMBasic (Not MMXBasic), there is a folder called "Embedded C Modules" and in here is a PDF called "SerialTx.pdf" which contains the code for a software serial transmit routine that can use any pin on the micromite and supports most of the common baud rates - depending on the clock speed of your CPU.

This provides a Sub that called "SerialTx" to provide a Tx output to the printer on any free pin. This has a couple of advantages:


This Lprint Sub is a very simple wrap which provides a nice throw-back and makes following the program code easier. A couple of disadvantages over the original LPrint; it only accepts a string as the argument (so any numbers should be converted using Str$() and it doesn't support ; or , for spacing, concatenation, newline suppression etc. The string is sent as is with a newline after, so make sure your string contains everything you need.

Syntax:
LPrint MyStr

Example Use:
LPrint "The time is "+Time$
LPrint "2*2="+Str$(4)


Code:


	Const LPin=3     ' change this to whatever pin you are using for the printer
	Const LBaud=9600 ' change this to whatever speed your printer is working at

	Sub LPrint(x$)
		SerialTx(LPin,LBaud,x$)
		SerialTx(LPin,LBaud,Chr$(13)+Chr$(10)) ; send a newline char
	End Sub




	CSub SerialTx    ' from the Embedded C Modules folder of the software distribution
		00000008
		00001021 40824800 40024800 0044102b 1440fffd 00000000 03e00008 00000000
		27bdffc8 afb40020 3c149d00 8e820000 afb00010 8c500000 8ca30000 00108042
		0203001b 006001f4 afb10014 8e820010 00808821 8c840000 afbf0034 afb60028
		afb3001c afb20018 00c0b021 24050008 00003021 afbe0030 afb7002c afb50024
		0040f809 00008012 8e240000 8e820014 0040f809 24050001 8e240000 8e820024
		0040f809 24050006 00409021 8e240000 8e820024 0040f809 24050005 00409821
		8e240000 8e820028 0040f809 2610fffb 82c30000 18600027 24110001 00518804
		24150001 ae710000 02002021 0411FFC4 00000000 241e0008 24170001 10000009
		02d5a021 ae510000 02002021 0017b840 27deffff 0411FFBA 00000000 13c0000d
		32f700ff 82820000 02e21024 1440fff5 00000000 ae710000 02002021 0017b840
		27deffff 0411FFAE 00000000 17c0fff5 32f700ff ae510000 02002021 0411FFA8
		00000000 82c20000 02a2102a 1440ffdd 26b50001 8fbf0034 00001021 00001821
		8fbe0030 8fb7002c 8fb60028 8fb50024 8fb40020 8fb3001c 8fb20018 8fb10014
		8fb00010 03e00008 27bd0038
	End CSub