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)
Showing posts with label CCS C. Show all posts
Showing posts with label CCS C. Show all posts

20/02/2011

●Sending Data by Using PIC16F628A with Serial Communication

Here is the program written by using CCS C.


#include <16f628.h>
#fuses NOPROTECT, NOWDT, NOLVP, NOMCLR, INTRC_IO, XT
#use delay(clock=4M) //Be aware you set the same clock frequency for PIC
#use rs232(baud=9600 , xmit=PIN_B2) //Be aware you have the same baud rate for virtual terminal and use the B2 pin for transmitting the data

void main(){
while(1){
printf("Sezgin"); //Sending data as a string
delay_ms(250); //Setting the time for the delay
}
}



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