PIC18 is not quite effective controller to drive VGA monitor, but they are able to be implemented for these purposes. This example shows how to use PIC18F2550 to build video game. In 2004 I developed VGA-terminal, where I used PIC18 to produce VGA control signals to form text data on the screen. When I was a boy (in early 80-th) I had a ZX Spectrum. My favorite game was a Bulder Dash by First Star Software. Now I tried to encode this game woth PIC18 controller. Here are source code, video and description of my works.
Source codes: vga_game.rar
All modules in this program were written in C (HT-PICC18), except interrupt service routine - it was fully written in assembler. Program controlled by RTOS OSA.
Program specification:
Controller | PIC18F2550 |
Fosc | 48 MHz (12 MIPS) |
RTOS | OSA |
VGA | 256x200 pixels, 15 colors |
Polyphony | 5 voices (4 for music, 1 for game effects). Sample rate = 15 KHz |
Game field | 40x20 objects |
Viewable field size | 16x12 objects |
Here is a small video. The quality is not very well since I used low-cost web-camera. Sound was recorded through line-in.
The principal scheme it rather simple:
Logically, scheme can be splitted into four parts:
How to form image on VGA-monitor is described here.
Here is device's photo:
As you can see, controller should to do many jobs simultaneously: sync signals for VGA generating, RGB-signals generating, multyvoice sound generating. All these jobs should be synchronized to within a cycle, otherwise the picture on the monitor will shake. Besides, the game should work in real-time: buttons reading, animation, objects moving, music playing, soung effects and ect.
I decided to put all time critical processes into interrupt service routine, and all other to put into OS tasks functions.
These tasks are placed into ISR:
Other tasks are placed in remaining program part:
(see russian text)