Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Asynchronous CCS-C programming for PIC

Status
Not open for further replies.

yuenkit

Advanced Member level 4
Joined
Jan 20, 2005
Messages
107
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,298
Activity points
1,047
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.
 

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?
 

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.

Added after 21 minutes:

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

104us is pretty tight. For such strict timing, you'll have to do it in asm. You do know how to calculate dealys from ASM right? If you use CCS, you may take a look at the LST file.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top