Bit-Banging Serial Interfaces for the Low-End and Mid-Range PICMicros using PIC16F84

Summary of Bit-Banging Serial Interfaces for the Low-End and Mid-Range PICMicros using PIC16F84


The article details the software implementation of an asynchronous NRZ serial interface for PICMicros lacking built-in UARTs, specifically using the YAP programmer. It explains how to write bit-banging code for low-end and mid-range chips like the PIC16F84, utilizing arbitrary I/O pins (RA3/RA4) with TTL/CMOS levels. The text covers the 8-N-1 data packet format and notes that electrical level conversion is handled by the MAX232 chip or the YAP itself, eliminating the need for external circuits in this specific setup.

Parts used in the YAP Project:

  • YAP PICMicro Programmer
  • PIC16F84 Microcontroller
  • MAX232 Chip
  • Three-wire Serial Interface (TX, RX, Ground)
  • Terminal Emulator Software
  • YAP Windows Interface Software
  • Debug Connector Pins (Pin 5 and Pin 6)
  • PICMicro I/O Pins (RA3 and RA4)
  • 1K to 10K Pullup Resistor

When I designed the “YAP” for the “YAP” PICMicro programmer presented in “Programming and Customizing the PIC Microcontroller”, I felt that the serial interface provided in “execution mode” of the programmer would be very useful for people developing their own software. With this interface, the user could input new values into the PICMicro application or output temporary values to help with debugging. This feature was probably not considered that useful until I developed the “YAP Windows” interface software with a Terminal Emulator built into it for just this purpose. This Terminal Emulator interface is shown in the screen shot above.

Mid-Range PICMicros

In this article, I want to focus on how asynchronous Non Return to Zero (“NRZ”) serial interface software is written for the low-end and mid-range PICMicros which do not have built in UARTs. There are many sources for information on creating the electrical side for this interface (and the YAP provides this as a matter of course), so I really haven’t persued it in this article.

If you are looking for more information on the electrical side of things, check out the Maxim “MAX232” chip at http://www.maxim-ic.com (seach under “Interface Products”). The MAX232 is commonly used for this purpose because it only uses a single +5 Volt power supply, is widely available and has been second source (which means it is very cheap). When I design RS-232 interfaces, I normally create a “Three-wire” (TX, RX and Ground) interface and short CTS-RTS and DSR-DTR together to avoid having to worry about hardware “handshaking” in my applications.

Because the genesis for this topic was the “YAP”, I used a YAP as the only hardware for the application. As can be seen in the picture below, Pin 5 of the YAP’s debug connector (Serial Input) is connected to Pin 10 (the PICMicro’s RA3) and Pin 6 (Serial Output) is connected to Pin 11 (the PICMicro’s RA4 Pin).

 

The pins that were chosen are arbitrary, with RA4 being selected as an input simply because most applications do not require the “open-drain” capabilities of the pin. The serial signals used in the application are at TTL/CMOS levels with the YAP providing the electrical level conversion, eliminating the need for level conversion circuits to wire the PIC16F84 to the YAP’s serial I/O.

The macros presented in this article are designed to use any of the PICMicro’s I/O pins. If RA4 is used for serial output, make sure a 1K to 10K pullup is put on the line to allow it to be used to output digital signals.

Before going through the code for the article, I just want to review what I mean when I say “asynchronous Non-Return to Zero” serial communications. This method of communication has been around for many years; first used as part of the “Baudot” standard for teletypes. In modern communications, each byte is transferred in “8-N-1” format which means that eight data bits are sent with a single (“low”) “Start Bit” and High “Stop Bit” to make up a data “packet”. This is shown in the diagram below:

 

For more detail: Bit-Banging Serial Interfaces for the Low-End and Mid-Range PICMicros using PIC16F84

Quick Solutions to Questions related to YAP Project:

  • How is the serial interface connected on the YAP?
    Pin 5 of the debug connector connects to Pin 10 (RA3) for input, and Pin 6 connects to Pin 11 (RA4) for output.
  • What chip is commonly used for electrical level conversion?
    The Maxim MAX232 chip is commonly used because it uses a single +5 Volt supply and is widely available.
  • Does the PIC16F84 have a built-in UART?
    No, the article focuses on PICMicros that do not have built-in UARTs and require software bit-banging.
  • What data format is used for byte transfer?
    Each byte is transferred in 8-N-1 format, consisting of eight data bits, one start bit, and one stop bit.
  • Why was RA4 selected as an input pin?
    RA4 was selected simply because most applications do not require its open-drain capabilities.
  • Is hardware handshaking required for this interface?
    No, CTS-RTS and DSR-DTR lines are shorted together to avoid worrying about hardware handshaking.
  • What voltage levels are used for the serial signals?
    The serial signals operate at TTL/CMOS levels with the YAP providing necessary electrical level conversion.
  • Can the macros use any I/O pins?
    Yes, the macros are designed to use any of the PICMicro's I/O pins.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter