Thanx Menno J Houtman -----Original Message----- From: Michael Rigby-Jones To: PICLIST@MITVMA.MIT.EDU Date: Tuesday, June 15, 1999 5:03 PM Subject: Re: PIC to PC's Parallel Port > >Van: Menno <10925465@OPN-NOV1.PUK.AC.ZA> > >Aan: PICLIST@MITVMA.MIT.EDU > >Onderwerp: PIC to PC's Parallel Port > >Datum: zondag 13 juni 1999 10:55 > > > >> Hi everyone... > > > >Hello Menno, > > > >> Does anybody have assembler code that I can use to interface a >PIC16C84 > >to the > >> parallel port of my PC? > >> > >> Thanx in advance > >> Menno J Houtman > > > >Are you sure you want to do that ? It'll cost you about 10 pin's >(outof 13 > >available). Maybe a RS232 connection is in order (2 lines) ? The >blunt > >way is to connect the PC's RXD & TXD with 1 kOhm resistors directly >to your > >PIC. Voltages exeeding the PIC's supply voltage will be blocked by >the > >internal clamping-diodes & converted into heat in the resistors. > > > >Greetz, > > Rudy Wieser > > -----Original Message----- > From: Menno [SMTP:10925465@OPN-NOV1.PUK.AC.ZA] > Sent: Tuesday, June 15, 1999 2:37 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: PIC to PC's Parallel Port > > Hi Rudy... > > I've got 10 pins availible and if connection to the parallel port is >easier > than connection to the serial port - as I understand - then I'd >rather try > parallel connection. So I still need assembler code to connect the >PIC with > my PC's parallel port. > > Thanx anyway > Menno J Houtman > > >It's really not that much easier. You will need to implement >handshaking/strobes to acheive reliable parallel data transfer, whereas this >is all done for you in RS232. > >10 pins gives you posibility of 8 bit half duplex i.e. both the PC and the >PIC can talk, but not at the same time, or 4 bit full duplex. To use the 8 >bit you will have to use a bi-directional parallel port on the PC side. The >4 bit solution would be much easier to implement. > >Possible solution: D0 to D3 on the PC port (Pins 2 to 5 I think) will >connect (via, say 1k resistors) to pins RA0 to RA3 on the PIC. The strobe >pin on the PC (pin 1) will go to RB0/INT. > >Now you will need to enable the external interrupt on the PIC and write a >small routine to capture the value on RA0 to RA3. As this is only a nibble, >you will need two transfers to transmit a full byte. The PIC will have to >reassemble the byte, which is very easy (hint: look at the swapf >instruction). > >So, to transfer a byte to the PIC from the PC, the PC would first put the >high nibble onto it's D0-D3 pins, and then pulse the strobe line (pin 1). >This would cause an interrupt on the PIC, which would then grab the data on >it's RA0-RA3 pins and store it. For the next transfer the PC would put the >low nibble on D0-D3 and pulse the strobe. The PIC would again grab the data >on RA0-RA3 and reassemble the 2 nibbles into a byte. There is a small snag >here, there is no synchronisation between the PC and the PIC. If the PC was >outputing the low nibble and the PIC was expecting the high nibble, your >data would be corrupted. You can either live with this and hope it dosen't >happen, or use another pin to indicate high or low nibble on the PC port. > > >To get the PIC talking to the PC would be simmilar, except that using >interrupts on the PC parallel port may not be possible. Soundcards and >network cards tend to grab the printer port IRQ. Instead you can poll the >port to look for the PICs strobe signal. The connection might look like >this: > >PIC PC >RB3 pin 11(Busy) >RB4 pin 15(Error) >RB5 pin 13(Select) >RB6 pin 12(Paper out) >RB7 pin 10(Ack) > >To use this the PIC would put a nibble of data onto RB4-RB7, again the swapf >instruction will come in handy here to swap nibbles around. The PIC would >then pulse (strobe) RB3. The PC will have to be continuously monitoring pin >11 of the printer port. When it see's a suitable signal, (either high or >low, you decide) it will grab the value on pins 15-10 and process it in much >the same way as the PIC. Again the same problem of synchronisation might >occurr and you could use another wire to indicate high or low nibble, but by >this time you will have only 1 pin left on the PIC. > >You will need some info on port addresses on the PC, try: >http://shell.rmi.net/~hisys/parport.html > >The code really should be very simple for the PIC, although a serial link >really isn't much harder, and all the code has been written, many, many >times. If you really want to try this I think you ought to at least have a >go at writting it. Generaly people are far more willing to help if you have >made some effort. If you have problems then post what you have managed to >acheive and you will get some help. > >To get started I would do something really simple, like configure the PIC >for external interrupts and in your interrupt routine, grab the data from >RA0-RA3 and output the same data to RB4-RB7 with some LED's attached. Once >you get that working, try the link the other way. Program to PIC to ouput a >count on RB4-RB7 and after each count, strobe RB3. Then write the PC side >of the software and see if you can read the counts in. Note that the Strobe >pulse from the PIC will have to be fairly long in order for the PC to detect >it if you are using software polling. > >Regards > >Mike Rigby-Jones