# Asynchronous CCS-C programming for PIC

Status
Not open for further replies.

#### yuenkit

Hi,

I need help to code Asynchronous Transmission Protocol in CCS-C.

I am using one IO pin. So I cann't use "#use rs232" (which use one XMIT and one RCV pin).

Someone told me ppl usually use ASM to code Async protocol, instead of C, because of tight timing.

1. How to code it using C? I know it's possible, but I dont know how to calculate the delay and timing.

2. If i have to use ASM, i will tend to use #ASM which mix with C code. The problem is, It might mess up my code, because C and ASM may use the same memory location, and I don't know in advance where C will use to store data.

Thanks for solving my problem.

#### checkmate

In microcontrollers, everything is synchronous to the clock. Do you mean a protocol with variable delays between bits? If so, what kind of delays are you expecting?

#### yuenkit

for example, the bit delay is 104 us.
However, besides the 104 us, the for loop it self creates delay, shift_left creates delay, and every instruction also cause delay.

Calculate those delay could take up some efford.
Code:
Code:

#define  BIT_DELAY   104;

void RS232_xmit(BYTE data)
{
int i;

output_low(RS232_XMIT);
delay_us(BIT_DELAY);
for (i = 8; i != 0; i--)
{
output_bit(RS232_XMIT, shift_left(&data, 1, 0));
delay_us(BIT_DELAY);
}
output_high(RS232_XMIT);
delay_us(BIT_DELAY);
}
I only take RS232 as a way of learning Async. At the end of day i have to code Async for one pin IO for another smart card device.
Thanks for solving my problem.

This is my schematic. I need to program the PIC to receive and transmit data using one IO pin.