This web is a bare bones overview of what you need to know to compile load and run a CHBasic Program on the Portland Area Robotics Society, PARTS, Mark-III mini sumo robot.
Reference CH-BASIC code for the production robot is here.
Reference JAL and an updated JAL compiler that create native hex files that work with the MarkIII without the overhead of MPLab and the chpre/mbuild monkey business for the production robot is available here
Drop me a line if you have any comments at, firstname.lastname@example.org. I'd love to hear from you.
This page useful information and sample code showing the basics of how to program the Mark III. It goes over some of the steps and tools used to compile, assemble, and load your programs on the Mark III. For detailed programming information start by going to the Mark-III project page, get the schematics and specifications for all the hardware components.
The MarkIII CPU design is based on Rick Farmer's PicLoader Evaluation Board. It comes with a 16F877 PIC micro controller preprogrammed with Rick's boot loader firmware, with the watchdog timer in the processor switched off. The firmware version loaded on the Mark III differs from the one on the link in that the baud rate for the MarkIII is set to 38400 baud as opposed to the 9600.
The tools involved with writing and running your own programs for the Mark-III are the following:
1. MS Windows computer to run the tools.
2. MS Windows Hyper Terminal: Set to 38400 baud, no parity, 1 stop bit, no Flow control. My system uses COM2, yours may be something different, experiment with your setup to find the correct COM port you are plugging your Mark III into. The PICLoader requires a 100ms line delay for programming. You need to configure this delay in the ASCII setup sub dialog box launched from the Hyper Terminal properties dialog box settings tab.
3. CH Basic compiler, A MarkIII specific version is provided for down load as part of the kit. Install it from http://www.junun.org/MarkIII/CHBasic.jsp. CH Basic converts basic source code into PIC assembly language files. It does not output to a format that can be directly loaded on to the Mark III platform. See the CH-Basic web page for information on the full version of the CH-Basic products.
4. CHPre.exe, A simple program for tweaking the CH-Basic output to be compatible with the PICLoader.
5. MPASMWIN, which is part of MPLab, to assemble and the CH Basic generated ASM file., this is the Microchip standard programming tool set for developing code for the PIC16F877 micro controller. The output of the MPASM assembly is a *.HEX file. It is this *.HEX file that you will "Transfer" to the Mark III using the "Send text file..." using HyperTerminal one the Mark III is put into its upload mode to "upload user code to program memory".
6. MBUILD.BAT is a handy batch file that automates the sequential application of CHPre.exe and MPASM to create the *.hex file needed for uploading to the Mark III. Use this file to run chpre and mpasm on your CoolSumoProgram.asm created by compiling CoolSumoProgram.bsc file with CHBasic. The syntax for this is: "mbuild CoolSumoProgram" Note: no file extension is applied.
Once you have all these items installed you are ready to compile, pre-process, assemble, and upload your programs to the Mark III for testing. The following section provides an overview of the installation of the tool chain.
· CH-Basic: You need to down load the setup program off the Mark III web site http://www.junun.org/MarkIII/CHBasic.jsp , and then get an activation key from Celestial Horizons. This key is a function of the ID Number provided, and you need to get the key via email. Once you have this key, enter this key in the dialog box that comes up at the start of the CH Basic program.
· MPLab: you cannot just get MPASM you must get MPLAB. The latest version of MPLAB can be downloaded for free from the Microchip tools download page Get this and run its installation program to install.
· CHPre.exe: just copy this file into the MPLAB installation directory. Search your hard disk for the location of MPASM.EXE and copy this file to the same directory.
· MBUILD.BAT: place this in the directory with CHPre.exe.
· You MUST have mbuild.bat, mpasmwin.exe and chpre.exe in your computers search path. If you don’t you are screwed. Call Microsoft for instruction on updating your search path if you need to, just don’t ask me to explain it to you.
· HyperTerminal: If you are unlucky enough to NOT have your windows computer configured with HyperTerminal then call your Microsoft customer support if you need too. It should be under the Windows "Start\Accessories\Communications" menu. Once you've configured a HyperTerminal session that works, be sure to "save as..." the ht configuration file as a short cut on your desk top for easy launching next time. Just double click on this configuration file to launch HyperTerminal the next time you feel like it.
Now that your computer is setup, you probably would like to test out the Mark III develop platform. The following is a brief list of the steps one must go through to run a new program on the Mark III. In the following MYSUMOPROGRAM is the file name assumed.
1. Using CH Basic "Compile & Check" your MYSUMOPROGRAM.bsc program file. This creates the MYSUMOPROGRAM.ASM file that is needed for the next step.
2. From a DOS box (start menu->run "command" or "cmd" will start a DOS box depending on your version of MS Windows) run "MBuild MYSUMOPROGRAM" . This batch file will run CHPre the file to create the input ASM file that is PICLoader compatible with the Mark III boot loader, AND call MPASMWIN the file to create the final MYSUMOPROGRAM.HEX file that the PICLoader knows how to load.
3. With the Mark III connected to the serial port and while running HyperTerminal press the reset button on the Mark III to get to the PICLoader splash screen.
4. Hit the "u" key once or twice followed by a return, then answer the question the PICLoader print to the screen. "Y" will erase your last program and print "ready" at the point you can start the transfer of the *.HEX file.
5. Use the HyperTerminal Transfer menu to select the "Send text file..." menu item, and locate your MYSUMOPROGRAM.HEX file. Note: HyperTerminal always defaults to only showing *.txt files. You will need to type *.hex with a return in the "Send Text File" dialog box, File name field to have files with the HEX extension displayed. Find your updated HEX file and hit enter to start the upload.
6. At the end of the up load the PICLoader will query you for an identification string. This string is for your own versioning of what's loaded. Kind of handy when you've forgotten what's currently loaded on your Mark III. Enter whatever you like.
These are the steps you are pretty much stuck with unless your use the “botloader” http://groups.yahoo.com/group/MiniSumoMarkIII/files/BotLoader/, then you can skip some of the BS with HyperTerm.
CHPre.exe, mbuild.bat are in the mIII_tools.zip file. Unzip these two files and place them in the directory with MPASMWIN.EXE.
A nice set of sample programs I used for validating my Mark III prototype for your enjoyment are in contained within the testplatform.zip file.