Introduction

I have written a couple of articles on computer control projects using parallel ports. In fact majority of PC interfacing in the past relied mainly on either series or parallel ports for their simplicity and ease of control until the Universal Series Bus (USB) came along. The USB offers standards and uniformity in computer communications and has now dominated PC peripheral designs and supports. It is just a matter of time before parallel ports are phased out in new computers. It would be a shame that we have to give up the ease and fun of parallel control altogether. Relax, this article demonstrates a simple way to convert a USB into a parallel port and revive all your favourite printer port control projects!

USB Interfacing

The fact that USB interfaces are plug and play wins popularity among computer end users. A USB device can be plugged in or disconnected any time and is very user friendly. Unfortunately, for developers, the implementation USB into their devices, is just the opposite side of the story. Unlike the conventional serial/parallel communication modes, USB protocols are very complicated. In additional to the requirement of writing a host control program, one has to develop not only the device embedded firmware but also a device driver for the operating system. While device firmware conforms data packets transfer between device and host in USB protocol format, device driver on the other hand lays a data flow framework within which the device can converse with the host system. All these loops are enough to stop most hobbyists from adopting the USB in their projects.

MicroControllers

The scheme of this article is to convert a USB device with the least amount of hardware into a parallel port controller without getting concerned about the complexity of firmware and driver writing. On the hardware side, the introduction of programmable USB dedicated microcontrollers from Microchip opens the door to USB control applications. The PIC16C745 singlechip processor emulates USB interface, provides over 20 input/output pins, and surprisingly requires only a handful of support component. One does not have to start from scratch in firmware development either. There are adaptable standard sets of firmware available for the processors ready to be used. It is just a matter of modifying these sets to suit applications. The flowchart shows the firmware logics for our USB interface. A way to avoid writing your own USB device driver is to use the Human Interface Device (HID) class. Under the Windows operating system, there is a comprehensive library of HIDs defining sets of structured input/output configurations. Keyboards, computer mices, and audio/video instruments are just some of the examples supported in the HID class. Microchip also offers HIDComm ActiveX as a simple communicating channel in control program between their microcontrollers and host. Incredibly the Company even provides MPLAB package free for veteran hobbyists to program, simulate and diagnose in microcontroller development.

Making the USB Parallel Converter work

The pictorial diagram depicts the functional compatibility of the USB Parallel Interface and the conventional printer port in parallel port applications. For comparison I post both the printer port control program and the USB control program performing the same function to illustrate how easy it is to migrate from one to the other.
Both programs control indicating leds display and monitor input states of switches. Generally in printer port control applications, depending on the LPT number (N), N and N+2 are output ports and N+1 is the input port. Similarly we define 1 and 3 in the USB case to be the output ports (portB and portA in the PIC16C745) and 2 the input port (portC). The data after the port identification number is the control bytes representing LEDs/Switches states. As a word of caution, it is important to remember that some of the printer port bits are inverted and therefore must be taken care of accordingly in the control byte value.
Procedures to use the USB-LPT interface for the test circuit:
1. Install Visual Basic and HIDComm Active Control on to the PC.
2. Download to a PIC16C745 and construct the interface circuit. Owing to file limitations in Geocities, the attached file is a txt name file. Download and save it as a hex file.
3. Attach the device to the host and make sure that the PC recognizes this device (It will show up in the Hardware manager under the HID category in the name of USB-LPT Converter).
4. Under the VB environment, place a copy of the HIDComm on the form. Define the USB-LPT interface to be the device the HIDComm to communicate with by choosing MicroChip to be the MatchManufacturer condition. One ActiveX control can only communicate with one device at a time.
5. Write and run the sample program.
6. Under normal operating conditions, the LEDs and switches should correspond to the data byte correctly.

Conclusion

This article outlines a simple method to harness USB communication in computer control. Loaded with the firmware provided, a microchip PIC16C745 can be readily converted into a plug and play control device in parallel mode. My objective is to take away the technical if not mysterious firmware/driver details in USB peripheral development and let readers once again continue their quest to computer parallel port control applications.

Parts List:

U1: Microchip Pic16C745;
XTAL1: 6MHz oscillator;
C1,C2: 22pF capacitors;
C3,C4: 0.2uF capacitors;
R1: 15K resistors;
R2, R: 10K x 6 resistors;
RL: 1K x 12 resistors;
LED: 12 red leds;
SW: 5 push buttons
Miscellaneous:
USB socket, Printer Cable, DB25 socket.

Email Contact
keensd@hotmail.com











1