I've written an example software-based serial data transmitter that shows how to implement a state-machine. This transmitter can be used to send asynchronous serial data to external devices using a digital I/O pin. Though it has many uses, I specifically wrote this to send data to a serial LCD. From the header:
This software demonstrates the use of a timer and associated interrupt to precisely clock a software-based serial transmitter which can be used to communicate with other common serial devices like serial LCDs.
In this example we'll setup a timer to generate an interrupt at a rate of 2400 interrupts per second. In response to this interrupt, the microcontroller will execute a specific piece of code called an interrupt handler (see user_routines_fast.c). Within this interrupt handler is a software state-machine that emulates the transmitter section of Universal Asynchronous Receiver/Transmitter (i.e., common PC serial port) running at a baud rate of 2400 bps. The output can be configured to use positive logic for communication with TTL-level serial receivers or negative logic for communication with RS-232 devices that are also compatible with inverted TTL signaling. The TTL serial port on the EDU robot controller can only signal using positive logic.
This code has been sucessfully tested with Scott Edwards Electronics' (http://www.seetron.com) BPP-420VY and SGX-120L serial LCDs (other than being a satisfied customer, the author has no relationship with this company).
In the zip file I've also included a PDF document that shows how the generated serial waveform should look and how each serial bit maps to a specific state of the state-machine. The code can be found here:
http://kevin.org/frc
-Kevin