Appendix B Installing CodeVision and the mech_lib
Appendix B: Installing CodeVision and the Mechlib
Mechlib is an open source library developed by the TekBots team at Oregon State University to aid users in programming an Atmel AVR microcontroller board. This library is released under the GPL; for source code, license info, and supporting materials please grab the tarball: mechlib-0.1.0.tar.gz. To set up CodeVision AVR for the first time, follow the instructions below. 1. To get started with CodeVision AVR and mechlib, download the CodeVision Installer from http://eecs.oregonstate.edu/tekbots/mechlib_html/files/setup.exe. Run the executable. Agreeing to the default options will install CodeVision in c:\cvavre\; the rest of these instructions will assume this location. 2. To make the mechlib available to CodeVision, save mechlib.h and mega8535asm.h to c:\cvavr\inc\. Copy mechlib.lib to c:\cvavr\lib\. These three files can be found in the zip file at http://eecs.oregonstate.edu/tekbots/mechlib_html/files/mechlib.zip. 3. Here is a step by step example of creating a CodeVision project, and using mechlib functions to program the mx_ctlr.0 microcontroller board: a. Switch the board off using the slide switch. Connect the 7.2V power supply or batteries to the power input marked with a “+” and “-.” Connect the small fitting on the programming dongle to the board. Connect the larger end of the programming dongle to your PC’s parallel port. b. Turn the board on and confirm that the “on” light illuminates. Note that you may need to disconnect any motors if don’t want them running and moving around while you are programming the board. The following example should demonstrate everything you need to know to use CodeVision to compile a program and transmit that program to your board. Start CodeVision and create a new project (File → New → Project → OK). Use the code generation wizard: a tabbed interface with many options should be displayed. For our purposes, you can ignore most of this and simply choose the chip type as “ATmega8535” with a clock speed of 16MHz. Choose File → Generate Save and Exit. Change to the directory where you want to save your programming, then enter the name “example” and hit “OK” each time you are prompted. c. You should now be looking at an editor window with a lot of C code (this is the example.c file that you created). Click anywhere in this editor window and then press CTRL-A, BACKSPACE this will delete all the code generated by CodeVision. Go to the mechlib website and choose the “forward” link from the menu on the left. After the description of the forward function, there are two examples. Copy and paste the second example in to the CodeVision editor window; don’t include the word “Example” when you copy the code. Set up the programmer: Settings → Programmer → Kanda Systems (from drop down menu). Change the CodeVision setting that will allow you to compile your code and program the board at the same time: choose Project → Configure → After Make → program the chip → OK. Now press SHIFT-F9 to compile the code and program your board. After a few seconds, the board should begin running motors 1 and 3, and then motors 2 and 4, alternating every second. You can verify this function by watching for the green lights next to the motor outputs.
Page 52
Oregon State University
ME 101 Lab Book
Appendix B: Installing CodeVision and the Mechlib
You can check for new versions of CodeVision at HP Info Tech.
Useful Links Programs CodeVisionAVR Library Functions http://eecs.oregonstate.edu/tekbots/mechlib_html/
Board Experiment Programs Basic Programming Basic Motor Control Motor Control Logic Elevator Service Motor Speed Light Detecting Motor Simple Tachometer Computer – Board: Motor Control Board – Computer: Voltmeter Bumpbot http://eecs.oregonstate.edu/tekbots/mx_ctlr.0/code_samples/
Mechlib Library Mech_lib: http://eecs.oregonstate.edu/tekbots/mechlib_html/
ME 101 Lab Book
Oregon State University
Page 53