- FAQ -
Interfacing a PIC
Microcontroller to a PC

by

Harvey
Twyman
About Me Email Me


    Question:
      I'm working with a PIC16C66 microprocessor. I need to get key hits from a keypad and transfer them using the PIC's internal USART to the PC.

      I've completed the keypad part but I'm having problems in communicating with the PC. What programs should I use on the PC to read the data?


    Reply:
     
    • USART Configuration

      The PIC MUST be driven by a QUARTZ CRYSTAL. The accuracy of the other modes like "RC" (Resistor/Capacitor) are not accurate enough as the frequency drifts with temperature.

      The Crystal Frequency must be chosen so that the BAUD ( bits per second ) of the transmitted data is a COMMON value that the PC can be set to. The best to choose is 9600 Baud. Hyperterminal in Windows can be set to this speed.

       
    • RS232 Cable

      The cable between the PIC and PC must comply with the RS-232 Format with Null Modem Links.

    •  
    • Null Modem Links

      Normally the PC thinks it has a MODEM attached to its serial comms ports. They use Handshake but we don't need it. So we LINK OUT or NULL the HANDSHAKE lines so that it just Receives and Transmits WITHOUT waiting for a modem.

    • The RS-232 Cable with Null Modem Links:
       

      • Purchase a Serial RS-232 cable with all Pins Connected
        ( e.g. Pin 1 connected to Pin 1 at the other end )


      • Connect as shown below with links:

     
    9 Way D-Type
    PIC End
    Pin
    Description
    1 LINK 1,4 and 6
    2
    PIC TX
    3
    PIC RX
    4
    LINK 1,4 and 6
    5
    GND
    6
    LINK 1,4 and 6
    7
    LINK 7 and 8
    8
    LINK 7 and 8
    9
    No Connection

     
      If you're using the 25 D-Type Connenctors then:-

     
    25 Way D-Type
    PIC End
    Pin
    Description
    Pin Description
    1 No Connection 14 No Connection
    2
    PIC RX 15 No Connection
    3
    PIC TX 16 No Connection
    4
    LINK 4 and 5 17 No Connection
    5
    LINK 4 and 5 18 No Connection
    6
    LINK 6,8 and 20 19 No Connection
    7
    GND 20 LINK 6,8 and 20
    8
    LINK 6,8 and 20 21 No Connection
    9
    No Connection 22 No Connection
    10 No Connection 23 No Connection
    11 No Connection 24 No Connection
    12 No Connection 25 No Connection
    13 No Connection    

     
    • Testing the Hardware

      Configure your PIC to give a 9600 Baud clock and write the code to continuously Transmit the ASCII letter "A" this is '41' in Hex. Remember to WAIT for last data byte to be completed BEFORE re-transmitting (poll the TXMT bit). This "polling" will also apply to the receive software using a different bit.


      Execute the code and you SHOULD see with an OSCILLOSCOPE a waveform that can be triggered WITH a little bit of care to display the data byte. You should be able to measure the BIT RATE as 9600 Baud which is approximately 10,000.

      This is 10,000 bits per second, therefore 1 Bit period on the oscilloscope should be 1/10,000 = 100uS period.

      The voltages on the PC cable should be +02V down to -12V peak to peak. These voltages are created by the RS-232 CONVERTER chip you have on your design. If not, check the TX O/P of the PIC to see if you get a +5V signal.
       

    • Using Hyperterminal in Windows

      Set to SAME Baud Rate as the PIC's USART is set. But start the PIC ONLY AFTER Hyperterminal is set up. You SHOULD then see a screen of the character "A"s



    • e.g. "AAAAAAAAAAAAAAAAA" etc.