Log in

View Full Version : parallel port interfacing - 16f84



devil6600
- 20th March 2008, 17:46
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.

skimask
- 20th March 2008, 17:50
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.
Parallel port operation is well document throughout the Internet, literally millions of hits on a Google search as well as here.
As far as using an 'F84, how many bits do you plan on transferring at a time?
8 bits is going to be a bit difficult and still have enough pins left over to control....anything...
How much other PIC programming have you done so far?

mackrackit
- 20th March 2008, 17:55
This might get you started on how to set it up.
http://www.picbasic.co.uk/forum/showthread.php?t=218

devil6600
- 20th March 2008, 18:51
Parallel port operation is well document throughout the Internet, literally millions of hits on a Google search as well as here.
As far as using an 'F84, how many bits do you plan on transferring at a time?
8 bits is going to be a bit difficult and still have enough pins left over to control....anything...
How much other PIC programming have you done so far?

I haven't used any other PIC.

well, what I want to do is to store the incoming data from the parallel port into a variable. Now, let us suppose once the PORTA has been set to be input (trisa = %11111111), then how to read the value of all the pins in PORTA and store them in a variable?

suppose if the incoming data is say "2" whose binary equivalent is 00000010, so now how to read this value on PORTA pins & store it in a variable?

thanks

JD123
- 20th March 2008, 19:01
trisa = %11111111
Variable var byte
Variable = PORTA

... but that won't work on PORTA with 8-bit data. Read the datasheet.

skimask
- 20th March 2008, 19:20
I haven't used any other PIC.[........suppose if the incoming data is say "2" whose binary equivalent is 00000010, so now how to read this value on PORTA pins & store it in a variable?
At the risk of being wrong...'cause it's entirely possible...
Before you go messing with a parallel port and blowing it up, I'd suggest you go for Mr. Blinky LED first, then throw a button or two into the mix, add an LCD, and so on.
If you don't know how to assign a value from a port to a variable, then how do you expect to do any handshaking with a parallel port?

sougata
- 21st March 2008, 06:55
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


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.

devil6600
- 21st March 2008, 15:42
Hello Sougata,

thanks for the information. I'll try it out.

Basically i want to do a PC->PIC communication.

what i want is that:
1) i'll send some string to the PIC via the Parallel port, ex: "mov-1-5"
2) PIC will interpret it as "move motor number 1 for 5 seconds"
3) Now PIC will make a particular pin high for 5 seconds.

thanks.

sougata
- 22nd March 2008, 18:22
Hi,

I am just curious why the parallel port. Serial communication is easy to handle on the PC side. But for Parallel you need to have your own soft. I once developed a software for the parallel port using some third party dll. It was in VB.net 2005.

All I can say is it is 100% possible as I have done it and one of my printer port interceptor is still in production.

devil6600
- 23rd March 2008, 10:03
Hi!

actually i am already using my serial port for some other purposes. Now the only communication port i am left with is the parallel port.

What ever you told I applied that and now I am able to read a character through the parallel port. I want to read a string (as i told earlier), so I require your help.

Thanks

mackrackit
- 23rd March 2008, 10:08
Have you thought about a USB to SERIAL converter?

devil6600
- 23rd March 2008, 10:11
yes...

i will be working on DOS..

sougata
- 23rd March 2008, 12:18
Hi,

I started my programming with Qbasic in DOS. And my first implementation of electronics was a Voltmeter using ADC0808 and Qbasic.