PIC serial communication tutorial. RS232 uses voltages below (-5V)to represent a logical level '1', and voltages above (5V)to represent a logical level '0'. Therefore, to use this protocol we need voltage level conversion. This is possible using the device such as the MAX232. May 03, 2012 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. Tutorial para usar la comunicacion serial en los microcontroladores PIC con el compilador CCs.
Check the XMIT pin for activity with a logic probe, scope or whatever you can. If you can look at it with a scope, check the bit time (it should be 1/BAUD). Check again after the level converter.
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.
2 4 6 8 10 12 14 16 18 20 22 24 | #fuses HS,NOWDT,NOPROTECT,NOLVP #use rs232(uart1, baud = 9600) // Initialize UART module chari; putc(13);// Go to first column delay_ms(5000);// Wait 5 seconds putc(10);// Start a new line putc(13);// Go to first column while(TRUE){ i=getc();// UART read } } |
PIC16F877A UART example video: