> Your best hope here is using the interrupt feature of the UART on received
> bytes. Basically you write your int routine to buffer bytes in a circular
> buffer as they come in. In the pauses when you are waiting for
> bytes to be
> sent and in times when there is no outgoing you can loop and handle
> incoming bytes.
>
> You could do some type of state machine implementation and bit
> bang things,
> but this gets much more complex. Basically I would use one of your
> counters as a reference and have background processes that are guaranteed
> to be called in your code at least every bit time. With interbit
> timing of
> 208uS at 4800 baud this could be potentially sticky depending on what you
> are doing in the background. Its doable, but I'd avoid it. You can find
> bit-banged uarts around on the web, I'm sure. Most compilers come with an
> example, and I believe there is one on the Mchip website.
>
> At 4800 bps on a 4MHz PIC you will have about 2ms to do stuff
> while you are
> sending and receiving.
>
> I'm not real sure of the utility of the sent byte interrupt, but if you're
> clever there might be some good use for that... anyone?
>
> psuedo code for the use of a UART looks like this :
>
> receive_byte_interrupt
> {
> buffer_incoming_data(); /* size your buffer based on processing
> requirements */
> clear_interrupt();
> }
>
> main()
> {
> while(TRUE)
> {
> if (bytes_to_be_sent && last_byte_is_gone)
> give_uart_a_byte();
>
> if (there_are_incoming_bytes)
> handle_some_number_of_incoming_bytes();
> /*number of bytes */
>
> /* is based on your */
> /* real
> time budget of 2mS */
> }
> }
>
> Erik Reikes
> Software Engineer
> Xsilogy, Inc.
>
>
.....ereikesKILLspam
@spam@xsilogy.com
> ph : (858) 535-5113
> fax : (858) 535-5163
> cell : (858) 663-1206
>