The Design of a Parallel-toSerial Adapter Using the AT89C2051 Microcontroller
The heart of the adapter is the microcontroller AT89C2051. AT89C2051 is a Atmel 20-pin microcontroller with 2k bytes of programmable and erasable read only memory (PEROM) with 15 I/O lines including a full duplex serial port and 8-bit bi-directional port and is compatible with the MCS-51 instruction set. All the data transfer described below was done with the microcontroller being set to mode one (one start bit, 8 data bits, one stop bit) and baud rate given by the following equation:
Baud rate = ((2<sup>SMOD</sup>)*12*(106))/(32*12*(256-nu))
where nu is the number to be loaded in the timer 1 register (=CCh for 1200, EEh for 3600, F9h for 9600), SMOD = 1. The data transfer was carried out at various baud rates using 12MHz crystal oscillator used at the microcontroller end.
Parallel to Serial Port Communication
Parallel to serial port communication using same PC can be established as follows. Strobe, Busy, and Ack signals of the SPP are used for handshaking whereas RS232 serial port is used in software handshake mode. Listings 1 and 2 (at the of this article) present the assembly and C program used to test the adapter in parallel-to-serial data transmission mode. Figure 2 is the circuit diagram for this. Figure 3 is the timing diagram for parallel-to-serial data transfer using handshake signals. The timing cycles for parallel to serial data transfer are:
- The program on the PC first checks the Busy line. If Busy is low (i.e. microcontroller is ready to receive data), it writes data on the data register and sends Strobe signal (changes Strobe to low) and waits for Ack from the microcontroller.
- On receiving strobe signal, microcontroller deasserts Busy to high, reads data and sends Ack (sets Ack to high).
- As soon as PC receives Ack signal, it removes Strobe and removes data (writes 0xff on data lines since, microcontroller requires all the pins on which it is receiving data i.e. port 1 to be set to high in order for it to read data on the data lines) and waits for Busy to be asserted low by the controller.
- After receiving Strobe, microcontroller deasserts Ack to low and sends the byte to the PC over the serial port and deasserts Busy to low.
- Program reads the byte from the serial register and the next cycle begins.
The program was tested successfully with baud rates of 1200 and 3600.