Comunicacion Serial Rs232 Pic Ccs

I’m trying to incorporate a PIC chip into my next Arduino project so that I can send serial data back and forth between the two. I’m using the PIC16F690 that comes with the PICkit2 programmer/Low Pin Count demo board from Microchip.

  • I have a PIC 16F887A connected to the serial port. I want it to lit a green led when it receives 0x01 and lit a red led when it receives 0x00 from pc. I send the characters from a C# windows forms application, the PIC itself is programmed with CCS C.
  • Some of the serial protocols include RS232, Ethernet, I2C, I2S, PCI, PCI Express, USB etc. In this lab we will be using RS-232 standard protocol. PC Serial Port vs Microcontrollers Serial Port. This method of serial communication used by a uController is referred to as TTL serial (transistor-transistor logic).
Comunicacion Serial Rs232 Pic CcsComunicacion Serial Rs232 Pic Ccs

The first step is trying to figure out how to get serial data out of the PIC. Right now I’m just using the Arduino as a USB serial interface. It should just pass any serial data it gets over to the serial monitor inside the IDE. The following code is for that. Does this look correct?

So this should be able to pass any serial data received on the RX pin to the serial monitor.

The next step is setting up the PIC chip. For some reason, I can’t get results that make any sense out of the PIC. Here’s my code written with the CCS C compiler for the midrange PIC devices:

The output I get in the serial monitor is as follows:

The female COM port is connected to the PC using RS232 cable, this cable has to be male-female because the PC COM port is male. UART Example for PIC16F887 CCS C code: The code used in this example is shown below. The function #use rs232(UART1, baud = 9600) is used to configure the UART protocol. Here the hardware UART module is used.

and so on. The “11” at the end of the second line is noise from where I plug the PIC into the arduino. I remove it when I’m programming the arduino because I’m scared it’ll fry the PIC somehow.

So the question is: Why isn’t the output on the lines after the first two correct? The incoming serial data should be the same.

Do I need a hex inverter on the PIC chips output for the serial data to be correct? Inverting the output in the PIC code didn’t seem to work. Or does it have to do with some difference between CMOS and TTL that I’m missing?

Any help on this would be great. I’ll write up a little tutorial for it if I get it working.

Thanks!
jamis

PicSerial

This is a small example shows how to use PIC16F877A UART module using CCS PIC C compiler.
PIC16F877A UART connection circuit schematic:
Pin RC6 (TX) and pin RC7 (RX) are used for the UART (serial) communication between the microcontroller and the computer. To change between TTL logic levels (5V) and RS232 signals (+/-12V), an IC is needed which is max232.
Don’t connect TX and RX pins directly to an RS232 serial port which may damage your microcontroller.
CCS C compiler serial monitor can be used to communicate with the microcontroller.

PIC16F877A UART example CCS C code:
This is the full C code for this example.

Serial Rs232 Cable