Have a look at the approach I used in "getting started" for the AVR. The dontronics site has a reasonable version, or I can email you the latest and greatest.