This topic comes from Beijing Puxi General Company. Since the stand-alone versions of the company’s existing spectrometers (such as 1810 and T6) use parallel port printing technology, with the gradual popularization of USB printer technology, there are fewer and fewer parallel port printers, and some users’ original printers are only The USB interface is not the parallel port, so the existing instrument’s support for the printer cannot meet the needs of the user. In order to make the company’s parallel port instrument directly connected to the USB printer, the author designed a LPT-USB printer driver to realize the connection between the parallel port instrument and the USB printer.

This topic comes from Beijing Puxi General Company. Since the stand-alone versions of the company’s existing spectrometers (such as 1810 and T6) use parallel port printing technology, with the gradual popularization of USB printer technology, there are fewer and fewer parallel port printers, and some users’ original printers are only The USB interface is not the parallel port, so the existing instrument’s support for the printer cannot meet the needs of the user. In order to make the company’s parallel port instrument directly connected to the USB printer, the author designed a LPT-USB printer driver to realize the connection between the parallel port instrument and the USB printer.

The author realizes the design of LPT-USB printer driver by using single chip microcomputer and USB bus interface device. Using this design, the data of the parallel printing port can be directly printed on the USB printer, which overcomes the disadvantage that some parallel port instruments must be connected to the parallel port printer to print, and greatly facilitates the use of users.

2 Features and working principle of CH375

2.1 Features of CH375

CH375 is a USB bus general interface circuit, which supports HOST host mode and SLAVE device mode. CH375 integrates PLL frequency multiplier, master-slave USB interface SIE, data buffer, passive parallel interface, asynchronous serial interface, command interpreter, protocol processor to control transmission, general firmware program, etc. On the local side, CH375 has 8-bit data bus, read, write, chip select control lines and interrupt output, which can be easily connected to the system bus of microcontrollers, DSPs, MCUs and other controllers. The USB host mode of CH375 supports various common USB full-speed devices, and external microcontroller, DSP and MCU can communicate with USB devices through CH375 according to the corresponding USB protocol. The features of CH375 are as follows:

(1) The full-speed USB-HOST host interface conforms to USB1.1, supports dynamic switching of host and device modes, and only requires 1 crystal and 2 capacitors for peripheral components;
(2) The host endpoint input and output buffers each have 64 bytes, supporting commonly used 12Mb/s full-speed USB devices;
(3) Support control transfer, batch transfer and interrupt transfer of USB devices;
(4) Automatically detect the connection and disconnection of USB devices, and provide notification of device connection and disconnection;
(5) Built-in protocol processor for control transmission, simplifying commonly used control transmission;
(6) Parallel interface includes 8-bit data bus, 4-wire control: read strobe, write strobe, chip select input and interrupt output;
(7) The serial interface includes serial input, serial output and interrupt output, and supports dynamic adjustment of the communication baud rate.
(8) Support 5V power supply voltage and 3.3V power supply voltage.

2.2 The working principle of CH375

As shown in Figure 1, CH375 can be easily connected to the system bus of various 8-bit microcontrollers, DSPs, and MCUs through passive parallel interface circuits, and can coexist with multiple peripheral devices. The parallel port signal line includes 8-bit bidirectional data bus D7-DO, read strobe input RD, write strobe input WR, chip select input CS, interrupt output INT and address input line AO. The RD and WR of CH375 can be respectively connected to the read strobe output pin and the write strobe output pin of the microcontroller. INT can be connected to the interrupt input pin of the microcontroller, and the interrupt request is active low. When CS, RD and AO are all low level, the data in CH375 is output through D7-DO; when CS, WR and AO are all low level, the data on D7-DO is written into CH375; when CS, WR are all low level When it is low level and A1 is high level, the data on D7-DO is written into CH375 as a command code.

Design of LPT-USB Printer Driver Based on CH375

3 Hardware circuit design

Figure 2 shows the hardware circuit of the microcontroller controlling the USB printer through CH375. CH375 is connected to the system bus of 8-bit microcontroller through passive parallel interface circuit, the TXD pin of CH375 is grounded, so that CH375 works in parallel port mode. The 8-bit bidirectional data bus D7-DO of CH375 is directly connected with the PO data port of the MCU, and RD and WR are respectively connected to the read strobe output pin and the write strobe output pin of the MCU. The chip selection signal CS is connected to the P2.6 pin of the microcontroller, and the CH375 is selected when the pin is low. INT can be connected to the interrupt input INTO pin of the microcontroller, and the interrupt request is active low. The address input line AO ​​is connected to the P2.5 pin of the microcontroller. When the AO pin is high, the command port is selected, and commands can be written. When the AO pin is low, the data port is selected, and data can be read and written.

Design of LPT-USB Printer Driver Based on CH375

The 74HC245 tri-state bidirectional bus driver is used as the interface for transferring parallel port data from the printer port to the microcontroller. The chip select signal is connected to P2.7 of the microcontroller, and the direction control bit DIR is connected to P3.4 of the microcontroller. When DIR is high, The data is transmitted from the A port to the B port. At this time, the microcontroller can obtain the data of the parallel port by reading the 74HC245 data port. The printer status signal BUSY is connected to the P1.5 pin of the microcontroller, and the parallel port data acquisition control signal CTRL is directly connected to the microcontroller’s INT1. Interrupt pin, when INT1 generates an interrupt, the microcontroller reads the data from the parallel port, and then sends it to the printer for printing.

4.1 Software Process

The software flow is shown in Figure 3. The software is programmed in C language, and the communication process mainly includes initialization and parallel port data acquisition.

Design of LPT-USB Printer Driver Based on CH375

The collection of parallel port data is carried out by means of interrupts. The control signal CTRL for collecting data is connected to the interrupt INT1 pin of the microcontroller, and the parallel port data is collected by continuously detecting the state of INT1. When the printer is not busy (BUSY=0), if an INT1 interrupt is generated, the parallel port data is read from the data port of the 74HC245, and the printer busy flag BUSY is set to 1 (indicating that the printer is busy). When the data has been sent to the printer for printing, Then set the printer busy flag BUSY to 0. Then repeat the above steps to collect and print parallel port data.

The initialization process is divided into microcontroller initialization and printer enumeration initialization. The initialization process of the microcontroller is to directly write the initialization value to the corresponding I/0 port and set the watchdog, and the function watchdog_init() can be called to set the watchdog.

The enumeration and initialization process of the printer is very important. To print the collected parallel port data, the printer must be successfully enumerated and initialized first. The initialization USB printer function init_print() mainly uses the following main functions:

Design of LPT-USB Printer Driver Based on CH375
Design of LPT-USB Printer Driver Based on CH375

Design of LPT-USB Printer Driver Based on CH375

4.2 Main program source code

The main program code is as follows:

Design of LPT-USB Printer Driver Based on CH375
Design of LPT-USB Printer Driver Based on CH375
Design of LPT-USB Printer Driver Based on CH375

5 Conclusion

This paper introduces the design and C language realization of LPT-USB printer driver based on 80C51 single-chip microcomputer and CH375 USB bus general interface circuit in detail. The test results show that the design can realize the direct printing of the data of the parallel port instrument through the USB printer, and the printing results are correct. This design has been used in parallel port instruments. Parallel port instruments can directly connect to USB printers and print by using this driver, which overcomes the disadvantage that some parallel port instruments must be connected to parallel port printers to print, which is convenient for users.

The Links:   CM150DY-12H MG400H1FL1