For communications between the host computer and the programmer, RS-232 asynchronous serial was chosen because of its wide availability and software support across computer platforms. RS-232 is also commonly used in embedded systems, which made finding the appropriate hardware and software to use with the programmer easy.
Voltage and logic level conversion
The voltage and logic levels used by the programmer's microcontroller and RS-232 do not match, so voltage and logic level conversion between the host computer and the microcontroller is required. For this task, a MAX232 IC is used. The MAX232 is designed specifically for this task. It accepts RS-232 inputs directly, includes charge pump circuitry to supply RS-232 voltage levels on outputs, and logically inverts all inputs and outputs to account for the difference in TTL and RS-232 logic levels. To make designing and building the programmer circuit easier, the MAX232 operates from only a 5 volt power supply rather than require several supplies of different voltages.
Several RS-232 connections are used in addition to the receive and transmit lines in order to implement a robust communications link. The additional lines are used for a programmer reset control and flow control. Optional lines can be connected to inform the host computer of the programmer's status.
DTR (Data Terminal Ready)
The DTR line is used to reset the programmer. The host computer normally sets the state of the DTR line based on whether or not it is using the serial line. The programmer is designed such that the host computer resets the programmer until the serial line is opened for communication. When the serial line is not in use, the DTR line is driven low. To reset the programmer, the reset line to the microcontroller must also be taken low.
The DTR line is taken through two components between the host computer and the microcontroller to operate the programmer's reset. First, DTR is connected to a receiver on the MAX232 to convert the input to TTL voltage levels. Next, the output from the MAX232 is put through a logic inverter to undo the inversion done in the MAX232. Finally, the output from the inverter is connected to the reset of the programmer's microcontroller.
CTS (Clear To Send)
The CTS line is a flow control line used to tell the host computer to temporarily suspend sending data. While the programmer is processing data, especially when writing data to the target PIC, it needs time to work on activities other than receiving data from the host computer. By changing the state of the CTS line, the programmer controls when the host computer can send data.
The programmer's microcontroller uses a pin to output CTS. That output is connected to a transmitter on the MAX232. From there, CTS is connected to the host computer.
DSR (Data Set Ready)
The DSR line is an optional connection that informs the host computer whether or not the programmer has power. The state of DSR is not affected by resetting the programmer. To provide the proper RS-232 voltage, the DSR line from the host computer is connected to positive end of the MAX232's voltage doubler on pin 2.
CD (Carrier Detect)
The CD line is an optional connection that informs the host computer whether or not the programmer is running. With this line, the host computer will be told that a connection has been made, in modem terms, a short while after the programmer starts running. The CD line to the host computer is connected to the Active LED output of the programmer's microcontroller. The output voltage does not meet RS-232C specifications, however, most computers will interpret the signal properly. This is a compromise done to avoid using a larger, more expensive RS-232 tranceiver than the MAX232.
RD (Receive Data)
The RD line is used by the programmer to transmit data to the host computer. The line is called receive data because the host computer receives data on it. The transmit pin on the programmer's micocontroller is connected to a transmitter on the MAX232. The output from the MAX232 is connected to the host computer's RD line.
TD (Transmit Data)
The TD line is used by the programmer to receive data from the host computer. The line is called transmit data because the host computer transmits data on it. The receive pin on the programmer's micocontroller is connected to a receiver on the MAX232. The input from the MAX232 is connected to the host computer's TD line.
The software on the programmer's microcontroller uses the asynchronous serial routines of the CCS C compiler. The CTS flow control is implemented as a single instruction to chage the state of the microcontroller's CTS pin placed around the function calls to receive data.