PDA

View Full Version : Using LPT port dot matrix printer with PIC



sougata
- 26th January 2007, 07:07
Hi,

In one of my application I need to use a classic dot matrix printer. A search on the net revealed the pinouts of the centronics port and procedure to dump data.(/strobe<-PIC side, ack->printer side and so on like )) But I have no idea how the characters need to be sent. (Printer control protocol??) Sending a linefeed, paper feed works , but I couldn't print a single character. I suppose I need to load the printer buffer first with characters and then issue a print command or so. Please guide.

I also tried to build a parallel port data capture device, a PIC18F452@40MHz with the strobe line connected to RB0/INT. An assembly interrupt grabs the data and puts in a buffer(256 byte array). The buffer is then rolled out @115kbps to the hardware usart. I got some characters but nothing (ASCII) that I sent for printing. I will try the old dos way today.
So another question ,
I have found that the strobe is active for atleast 0.5uS and I am running at 100nS Instruction cycle time so by the time I fall into the interrupt and load the data it should be valid. BTW I dump the port data to a temporary variable in the first instruction of the assembly ISR and then find out the right array using indirect addressing and finally load the indexed array from the temporary variable (I still don't know the parallel port timings --> valid data --> strobe--> ack) So is this approach feasible.

Ioannis
- 26th January 2007, 08:09
Hi,

I got some characters but nothing (ASCII) that I sent for printing.

From that, it could be timing issue. Also try to send just one character followed by CR and LF. It should absolutely print the character and advance the paper.

Ioannis

Luciano
- 26th January 2007, 08:46
Hi,

See this link.
http://www.phanderson.com/stamp/i2c/print1.html

Verify the DIP switches of the printer.
With some printers, with the DIP switches you can select the printer
emulation mode. (Epson LQ emulation or IBM emulation).

Best regards,

Luciano

sougata
- 26th January 2007, 09:04
Hi Luciano,

I found the DIP switches but no idea what they do, not in the manual too. It is a MSP 245.

Ioannis I have tried making the timing high enouhg but results were same.

I have found an article in the EPE mag July 2001 called PIC to Printer Interface by John Becker for printing on an EPSON printer. I have also found the epson documentation (escape sequences). I will give them a try and let you all know.

BTW as far as grabbing data from the parallel port is concerned can anybody suggest me a software that monitors and records a parallel port data just like serial monitor.

Thanks to everyone for responding.

websmith
- 26th January 2007, 10:04
There is also a marvelous site on all things serial and parallel at:
http://www.lvr.com/parport.htm

Luciano
- 26th January 2007, 12:28
Hi Sougata,

The printer has an Hex Dump mode. This mode will show you
exactly what codes the printer is receiving.
(The printer will print each byte in HEX on paper).

See the printer manual how to enable the HEX dump.

* * *

To see if the selected emulation is a problem, boot
the PC with DOS 6.22 and type:

Copy myfile.txt > PRN

(Put first 2 or 3 lines of text in the file myfile.txt).
If you see the text of myfile.txt printed on paper you are fine.

(The printer must be connected to LPT1 in order to use PRN).

* * *

I was unable to downlaod a manual from the web site.
http://www.tvs-e.in

Try to phone them. (India).

Contact:
http://www.tvs-e.com/may12-05_contact.asp


MSP 245 brochure:
http://www.tvs-e.com/may12-05_downloads/brochures/MSP%20245.pdf

Note that you can install an optional serial port in this printer.


Best regards,

Luciano

BobK
- 26th January 2007, 22:39
Hi sougata,

Are you interested in the code for a 16F84 serial to parallel converter? If so, here it is:

(This was on this forum back in January 2004)

Serial 2 Paraller PRinter Converter
________________________________________
HI! I don't know if this is what you want but give it a try

THANKS HARRISON PHAM ,for the codding!

'Serial to Parallel Printer Converter for Generic Printers
'By: Harrison Pham March 30, 2003
'---------------------------------------------------
'PIC: 16F84 at 4mhz
'
' PIC Printer (DB25 Connector)
' Pin A1 Pin 16 (Init)
' Pin A0 Pin 1 (strobe)
' Pin B0 Pin 2
' Pin B1 Pin 3
' Pin B2 Pin 4
' Pin B3 Pin 5
' Pin B4 Pin 6
' Pin B5 Pin 7
' Pin B6 Pin 8
' Pin B7 Pin 9
' Pin 17 to gnd (Printer Select)
' *Pin 14 to gnd (if needed for autofeed feature)*
' Pin 18 to gnd (gnd)
'----------------------------------------------------
init con A1
strobe con A0
char var byte
trisb = $00 'set portb to all outputs

high init 'clear init line
high strobe 'clear the strobe line
portb = %11111111 'put all data lines high
pause 1000 'pause for a second

low init 'init the printer
pause 500 'pause 500mill seconds to let printer init
high init 'clear the line

main:
serin A2,N9600,[char] 'get characters with serial
if char = 13 then 'if detected a cr then insert cr and lf
PortB = 10 'lf
low strobe 'tell printer to read in byte
pauseus 200 'wait 200usec for printer to read in byte
high strobe 'clear the strobe
PortB = 13 'cr
low strobe
pauseus 200
high strobe
endif
portb = char 'set portb to the char byte
low strobe
pauseus 200
high strobe
goto main


I'm sorry but I really don't know how to put this into one of those nice little windows. I think I need to find out how to do that. You might want to do a search for this post as there were some people who posted comments about the code.

HTH!

BobK

I use a serial dot matrix printer on one of my projects. I use the DebugOut setup and it works great. I know you're using a parallel but thought I might be able to help!

sougata
- 27th January 2007, 11:48
Hi,

First thanks Luciano for the effort. I am not trying to use that particular printer. I want to develop a hardcopy supported Datalogger. I have already tried the dos way. You would be glad to know that I have had some success. I would post the entire routine once it is complete. The other way round I needed a parallel to serial converter to take a look at the data that is being passed over the parallel port.

BobK I am looking for the other way round but still your post is helpful. And if you are concerned about how to put a snippet into a code window then it is right down this (and every page) http://www.picbasic.co.uk/forum/misc.php?do=bbcode