ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING USB-COM-LPT converter on a microcontroller Encyclopedia of radio electronics and electrical engineering / Computers The article describes a simple converter that allows you to connect peripheral devices equipped with an LPT interface to a computer that has only a USB interface. The conversion is carried out in two stages - a specialized microcircuit converts USB to COM (RS-232), and then the microcontroller converts COM to LPT. Since the computer in this case exchanges information through a virtual COM port, only programs developed or modified with this feature in mind will be able to interact through the proposed converter with an external LPT device. For everyone else, you will need to connect a special software driver to the operating system, which is yet to be developed. At one time, many electronic devices and devices connected to the LPT port of a personal computer were developed and manufactured. They still exist today. At the same time, LPT ports (as well as COM ports, by the way) in computers are gradually replacing the USB interface. This process is especially fast in portable computers (notebook). But due to their compactness and autonomy, it is very convenient to use such computers as portable tools for setting up various electronic equipment, including those with an LPT interface. The elimination of LPT ports in computers makes working with such equipment problematic. To solve this problem, a converter is proposed that uses inexpensive and affordable electronic components and has an open architecture for developing your own programs. The presence of a microcontroller in it allows, if necessary, to develop any necessary protocol for the exchange of information between a computer and a device connected through the converter. The figure shows the converter circuit. The information transmitted through the X1 connector via the USB interface is converted using the CP2103-GM chip [1] into the RS-232 serial interface format. It also performs the reverse transformation. The outputs of the control lines of the RS-232 interface of this microcircuit are connected by jumpers corresponding to the constant readiness for information exchange. The TXD and RXD pins are connected respectively to the information input and output of the built-in UART microcontroller ATmega8515-8AC [2]. Connector X2 is intended for in-circuit programming of the microcontroller. Working according to the program, the boot codes of which are given in the table, the microcontroller processes the computer commands received at the input of the built-in UART. Performing them, it generates the output signals of the LPT port on its outputs and the contacts of the XXNUMX connector connected to them and receives the input signals of this port. The program is written in C language in the CodeVision development environment. According to the information exchange protocol developed by the author and embedded in the microcontroller program, the computer must send two- or three-byte commands to the converter. The least significant bit of the first byte of the command specifies the direction of information transfer: O - from the computer to the converter (record); 1 - in the opposite direction (reading). The next bit defines the address space: 0 - LPT port register; 1 - non-volatile data memory of the microcontroller. The six most significant bits of the first byte are not used yet. The second byte of the command contains the address of a register or memory location, which can be in the range 0-255. The third byte is present only in write commands and contains a code intended to be entered into a register or memory cell. In response to a two-byte read command, the converter sends one byte to the computer - the contents of the requested register or memory cell. The initiator of the transfer of information in any direction is always a computer. The ability to read and write information from the EEPROM of the microcontroller, although not required for the application in question, is useful for the development and improvement of the functions performed by the converter. For example, in order to write byte 0x01F to the EEPROM of the microcontroller at address 0x5, the computer must send a sequence of three bytes through the virtual COM port: 0x03, 0x01, 0x5F. And to read data at the same address, a command of two bytes is enough: 0x02, 0x01. In response to it, the converter will send the byte read from the specified EEPROM cell. As you know, from the point of view of the programmer, the LPT port in normal (not EPP or ECP) mode of operation consists of three registers: data (DR), status (SR) and control (CR). The address of the DR register is the same as the base address of the port, the addresses of the SR and CR registers are larger by one and two units, respectively. This structure of the LPT port is also implemented in the proposed device. The assignment of bits of all registers is also completely preserved. This allows you to recycle previously created computer programs to work with the described converter at minimal cost. The program includes header files describing the names of microcontroller registers and entries of binary values of numbers used to initialize variables and other operations. The program configures the UART of the microcontroller to work in asynchronous mode at a speed of 115200 baud with eight information (no parity) and one stop bit. The computer's virtual COM port must be configured in the same way. There are routines for receiving (UART_RXD) and transmitting bytes (UART_TXD) via UART, as well as routines for writing (WRLPT) and reading RD_LPT of LPT port registers and non-volatile memory cells (WR_EEPROM and RD_EEPROM). For maximum compatibility with LPT, register masks MaskSR and MaskCR are provided. When information is output to the microcontroller port lines connected to the XXNUMX connector, or it is input from these lines, certain bits of the SR and CR registers are automatically inverted using the mentioned masks and the XOR logical operation (exclusive OR). The source text of the program is provided with a detailed commentary, which allows you to understand it without much difficulty. To ensure operation with the converter, it is necessary to install a software driver for the virtual COM port in the computer, which ensures the exchange of information with the CP2103 chip. This driver is freely available on the website of the manufacturer of these chips at silabs.com/public/documents/software_doc/drivers/Microcontrollers /lnterface/en/CP210x_VCP_Win2K_XP_S2K3.exe. To check the converter, you can use a variety of test and debug programs that allow you to work with the COM port if they do not directly access the registers of this port, as was usually done in DOS and Windows9X/Me. Such calls should be replaced with port functions (eg, CreateFile, Get-CommConfig, SetCommConfig, Read-Corn, WriteFile) provided by the operating system. After the converter is turned on, the HL3 LED lights up. Receiving the first byte of the command will extinguish it. After receiving the command in full and executing it, the LED will turn on again, which means that it is ready to receive the next command. Such an algorithm is convenient for monitoring the passage of commands and the normal operation of the converter. In case the microcontroller freezes, the program uses a watchdog timer that will restart the microcontroller when such a situation occurs. This improves the stability of the inverter even when operating in a strong interference environment. A complete set of microcontroller program project files can be downloaded here. Literature
Author: O.Valpa, Miass, Chelyabinsk Region; Publication: radioradar.net See other articles Section Computers. Read and write useful comments on this article. Latest news of science and technology, new electronics: Artificial leather for touch emulation
15.04.2024 Petgugu Global cat litter
15.04.2024 The attractiveness of caring men
14.04.2024
Other interesting news: ▪ Marvell 88EM8189 LED driver IC ▪ The pendant will protect from criminals ▪ Biochemical Reboot of the Eye: Treating Blindness ▪ Explosives will improve the safety of electric cars News feed of science and technology, new electronics
Interesting materials of the Free Technical Library: ▪ section of the site for the radio amateur-designer. Article selection ▪ article Trumpet of Jericho. Popular expression ▪ article What is the upper temperature limit at which microorganisms can live? Detailed answer ▪ article Work on waxing machines. Standard instruction on labor protection
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |