
Originally Posted by
devil6600
hello all,
I want to read some data from the parallel port of my PC, the data would be in the from of strings. After some research I came to know that parallel port sends data bitwise (set of 8 bits). Now I do not know how to read each bit. Would it require the use of buffer IC's?
I don't know how to do it. Any help is solicited.
My target uC is 16f84
Thanks.
Hi,
Forgive me for not understanding your requirement (actually not reading in details other posts) properly. So I would try to cover both PC --> PIC and PIC --> PC (within my limited knowledge though)
Please note that PC parallel ports have evolved (and possibily dead by this time) from the SPP to Bi-Dir to ECP/EPP. To keep everything simple and under the scope of a 16F PIC and PBP you should use the SPP (Standard Parallel Port) mode. This can be set from your PC's BIOS.
In a SPP the data from the PC is presented at a time to the 8bit wide dataout pins. That's why it is called a parallel port. Handshaking is done through Strobe/Busy signals on the port. Since it was basically made to drive printers it also takes inputs in the form of Online (detects whether a printer is connected and ready to accept data), PaperOut (detects the printer is out of paper and stop sending data prompting user) and Error. There are other bits also.
When the port is in online mode without any errors (easy to hardwire so that the PC side software finds it okay to send the data) the data is first presented on the port itself folllowed by a strobe signal. You need to detect (thorugh interrupt to make sure that a byte is not lost) this strobe signal to detect a fresh new valid data to initiate your read/process routine. You should then pull-down the busy line to indicate that your PIC is busy to prevent any further data flow from the PC. When you finish reading the byte then you should release your busy signal and send an acknowledge pulse through the acknowledge pin. (In newer BIOSes I have found that the PC doesn't care for the ack signal rather dumps another byte when you release strobe) . And it goes on like this. If you are short on a 8bit wide port then you may map any bit to any discrete pin.
For example
Code:
Data_byte var byte ' byte read from the PC
Busy var portb.7
busy = 0
TRISB.7 = 0
; parallel read
read_data:
busy = 1 ' put a busy on the pc port till grabbed
Data_byte = PORTD ' PC parallel port data connected here
busy = 0 ' data grabbed end busy
; discrete read
busy = 1
data_byte.0 = porta.0
data_byte.1 = porta.1
...
...
...
data_byte.6 = portc.4
data_byte.7 = portc.5
busy = 0
So it is important to grab the strobe signal. The signal is about 0.5uS wide. You can use a inverter pulse stretcher with its ouput ored to the PIC busy out pin to rule out any missing pulse or working at low Fosc
Thus grabbing (reading from the PC is easy to accomplish). I have done in on a PIC18F452 @ 40Mhz but then it intercepts data going to printer and parses on the fly.
For storing sequential data you can use an array.
However to send a byte from the pic to the PC under SPP mode is bit tricky. You need to send them in nibbles (only 4/5 pins work as input) and assemble it into a byte in your PC side soft. You definately need handshaking though through the strobe or the data port itself.
If you could elaborate me with some more details stating practical usage I would try to cooperate.
Bookmarks