Using the COSMIC C Compiler



Using the COSMIC C Compiler

The COSMIC compiler, IdeaCPU12 v2.10f, allows code written in C to be compiled into Assembly code, and linked and built into a binary Motorola S19 file that can be downloaded into the processor. This document will step through the process of generating the final program.

Creating a New Project

1) Before starting, create a new folder with a meaningful name, such as the current date.

2) Copy all files from other projects that will be reused, such as the linker file, the vector table, startup code, or an old program to be updated.

3) Next, run CX6812, which will bring up IdeaCPU12, the programming environment. There should be a shortcut on the desktop if it was installed with default settings.

4) To create a new project, select Project -> New.

5) Now select Project -> Save As, and give the project a name, inside the folder just created. It will have a .prj extension.

Initializing the Project

1) Set up the working directory to the folder created above. Do this by selecting Setup -> Working Directory, browse to the folder, then click OK.

2) Right click the “Include Paths” tab on the left side of the screen and click Update. Now select any folder that contains files included by the code, such as COMMON.H or IOB32.H. Once the folder is selected, click “Append” to add it to the included paths before clicking “OK.”

3) Click Tools -> Linker -> Options. The Tools window can be called up from the menu or from the window on the left of the screen. Enter a binary file to output in the first box (not used), and a command file in the second box. The command file is the name of the linker file imported from a previous project, if it exists. This file will have a .lkf extension. Most of the names for files that need names can be the same as the project name with a different extension.

4) Open the Link file by clicking Tools -> Linker -> Command File. Edit this file to use the correct vector, startup, and code files. Also change the starting location for RAM and FLASH and the stack, if necessary. Save this file, and then close the window.

5) Click Tools -> Compiler -> Options -> Listings and click the box labeled “Generate Listings.” This option will generate a list file with assembly code that is useful for debugging.

6) Click Tools -> Builder -> Options and click on the box to Convert to S-Records. Then click the button across from it labeled “Options.” Click “Output to File” and enter a name. The project name followed by .s19 is usually a good name.

7) Right click “Files” on the toolbar and then select “Add File.” Select all the files except the linker file that will be included in the project. This includes startup code, vector tables, and C subroutines.

8) Before starting to write code, be sure to save the project again with Project -> Save.

Points on Programming the 68HC12 in C

1) Load the file to edit with File -> Edit, or start a new file with File -> New. First include comments at the start of the program identifying the function of the program, the programmers’ names, and the date.

2) Next include any files that the code references. COMMON.H includes BIT_CHAR declarations that may be useful, and IOB32.H includes declarations for each memory address by its functional name.

3) Next write a main method called main() according to standard C syntax.

4) Subroutines follow normal C syntax.

5) Interrupt routines use the syntax “@interrupt void interrupt_routine_name(void)” where interrupt_routine_name can be chosen to be any name that does not use invalid characters. This name must also appear in the vector table, or it will not trigger the interrupt. The vector file must declare the interrupt routine name before the vector table. In the example above, the file would read “void interrupt_routine_name(void);” as the first line of code.

6) Hex addresses can be entered in the format “0xXX” where XX is the byte used. For instance to set all the pins on port A high, use the command: “PORTA = 0xFF;”

7) Reading or setting bits in a byte can be accomplished with the bitwise AND operator. Assuming IOB32.H is included, the following command can be used to wait until bit 1 goes low on port A: “while (!(PORTA & BIT1)) {}”

Compiling the Program

1) Once all the code is complete, click the “Compile” button from the toolbar, or select Project -> Compile File.

2) If there are errors they will appear in the Error box, which is viewable by selecting Errors -> Show Error File. To make this window show up by default, select Options -> Automatic Errors Toggle.

3) If all the files in the Files section on the left are green, then they have all compiled successfully and can be built.

4) Build the project by clicking the “Build” button from the toolbar, or select Project -> Build. This will produce an S-record file that can be downloaded into the microprocessor with the programmer.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download