miSim DE Back Index Next

Appendix A

A First Program

Once miSim DE has started, click on the 'File' menu then select 'New' to create a new, empty file. A new tab called 'File 1' is added to the main window. Type the following lines into the editor:

                processor 16f84
                org 0          
main            movlw 10       
                nop            
loop            addlw 4        
                goto loop      

If the code is correct, it should look like this:

Note that words that the editor recognises are capitalised, and that their colour shows their meaning. In this case, the words 'processor' and 'org' are commands for the assembler, and turn green. Assembly instructions that will be run by the microcontroller turn purple. Numbers turn orange.

Once you are happy that the program has been correctly typed, click 'File' then select 'Assemble'. The assemble command will turn the currently selected file into executable binary data - the raw food of microcontrollers. If the program has been entered ok, miSim DE should report:

'Assembled sucessfully with 0 warnings. Click 'Run' to execute binary.'

miSim DE will then turn automatically to the tab that shows the contents of the microcontroller - the binary data that represents the program that has just been assembled. The tab is labelled '16F84' to indicate the device that is being simulated. If the assembler reports errors, check the program again to see if you have typed it correctly.

Once the program has assembled correctly, you can run it. The Icons along the top of the screen control the microcontroller. The third one along from the left makes the microcontroller execute a single instruction (known as 'STEPping').

Click it whilst looking at the '16F84' tab window, and see what happens. The while bar that shows the current instruction will move down one line. At the bottom of the tab window there is text that now reads 'W=10'. The MOVLW 'MOVes a Literal to W' - that is, it copies a number (10) into the W register. The next instruction is NOP which is short for NO oPeration - do nothing. If you click the 'Step' icon again, the processor follows that instruction - and does nothing!

The next instruction is ADDLW - short for 'ADD Literal to W'. It adds a number (in this case, 4) to the W register. When you click 'Step' the line at the bottom of the window will now read 'W=14'. Note that numbers are shown in hexidecimal format - so '1F' (hexadecimal) would represent the number 31 (decimal).

The final instruction in our short program is GOTO which GOes TO a specified instruction - in this case, back to the instruction immediately before it. Clicking 'Step' a few times will show that the processor is now in a loop - endlessly adding 4 to the W register. As the W register is only eight bits wide, it will count up to 255 and then go back to 0 again. You have now written, assembled and simulated your first simple program.

This is just a brief introduction to running programs in miSim DE, so we shall leave it there. The following chapters will explain the functions of miSim DE in more detail. For more information on programming specfic microcontrollers, check the resource links on the previous page.

Index Next