Let the future tell the truth and evaluate each one according to his work and accomplishments. The present is theirs; the future, for which I really worked, is mine. (Nikola Tesla)

27/01/2011

●Serial Communication Using PIC16F628A

Serial communication refers to sending one bit data at a time on a line or a computer bus. It is used for long distance communications, especially computer networks where difficulties on cabling and synchronization makes parallel communication inconvenient.

While we're using PIC16F628A for serial communication, we use RS-232 standard. So, we need to know some terms as baud rate and some instructions used in CCS C for RS-232.

We define instructions for RS-232 in CCS C as below:
#use rs232 (...)

One of the definitions for RS-232 is the baud rate (baud=x). The baud rate is used to denote the number of bits transferred per second. We may define baud rate as different values like 9600.
Here is an table for RS232 cable length according to Texas Instruments:

Baud rateMaximum cable length (ft)
1920050
9600500
48001000
24003000


In our examples, we use 9600 as our baud rate. So we can define;
#use rs232 (baud=9600)

The other thing is the transmitting the data. We should specify the pin that we choose for transmitting the data (xmit=x). We are free to choose a pin. So we can define;
#use rs232 (xmit=PIN_B0)

The other thing is the receiving the data. We should specify the pin that we choose for receiving the data (rcv=x). We are free to choose a pin. So we can define;
#use rs232 (rcv=PIN_B2)

Parity is the another thing in RS232 communication (parity=x). We can define the parity as even(E), odd(O) or not(N). So we can define;
#use rs232 (parity=N)

Bits definition is another step in our rs232 definition (bits=x). While using software UART, CCS supports from 5 bits up to 9 bits. If we want to use two stop bits, we should define 9 bits and make the 9th bit as high. So we can define;
#use rs232 (bits=8)

For RS485 communication, we may use a intstruction (enable=x). So we can define;
#use rs232 (enable=PIN_B4)

Finally, we should regulate the virtual terminal operating properties compatible with the arranged values on our program. For instance on Proteus:





ShareThis