Mechanically scanned RS232 display (with dynamic speed)
After I made the clock, the pong and tetris games I thought that it also would be cool to connect the game system to a standard rs232 port and scroll text comming from the port.
When I thought about it, I found that there is a problem scrolling text comming from a RS232 port because you don’t know in what speed the letters are comming, so you don’t know how fast to scroll each letter at pixel level. The problem could be solved by using another port, like the parallel port, but then a special program would be needed to communicate with the display, so it had to be rs232. Another solution could be to type each character 8 times, so it would scroll one pixel for each time, but that would really suck. The solution I choosed was to use a timer that measured how long time had passed since last character was received and then assume this character would take the same timem and use a buffer to handle speed changes. And when I was finished, it seemed to work quite nice. There is one problem though, during the communication, the interrupt is turned off, so there are some chars that disappear. This problem could be fixed by adding some stuff to the communication routines, but i’m getting tired of this project so I choose to let it be.
Most of the code is written in C and compiled with Hi-tech PIC-C. It is the best c-compiler available for the PIC, but it comes with a primitive DOS IDE. However, it is possible to integrate the compiler with MPLAB and then you’ll have an extremely powerful easy-to-use development environment. It is this combination that I’ve used developing the virtual rs232 display, and it is what I recommend you to use when developing stuff for PIC. It is amazing to see how tight code it produces.
To receive data from a serial port I use an interrup routine. This is based on the interrupt driven serial driver example that comes with the c-compiler, but I had to rewrite most od it. The characters received is stored into a 8byte ring-buffer by the interrupt routine, that is also taking care of the scrolling. The scrolling is quite simple, it is just a index to the ring-buffer that is updated, and then the main-loop uses the index to read the ring buffer when showing the text on the screen.
How to use the clock
First you’ll need a special cable to connect the RS232 input. It is the fire button on joystick port 2 that is used as serial input. It is connected to the TxD on the computer, and to be sure the input buffer won’t blow up due to the overvoltage, a 10k resistor is used as current limiter. To get echo back you could also connect the TxD to RxD. Of course the groundpins should also be connected. Se schematic here at the right.
To communicate you simply use a terminal program like the Hyperterminal in Windows, set the speed to 300bps, 8 databit, one stopbit, no parity, no handshake. What you write in the window is what you get on the screen.
For more detail: Mechanically scanned RS232 display (with dynamic speed)