Whats a "Compiler"?

PIC's are essentially micro chips with user designed programs on them to perform any range of tasks. The creation of these programs is an integral part during the development phase, so its best to choose a compiler that suits you.

Whats this about a compiler? Digital-DIY focuses more on the higher language programming that provides quick and powerful integration into any project, but that's not where it all begins for PIC's.

Program information stored in the ROM of a PIC is in the form of machine code; which would appear to any normal person as a bunch of random hex numbers. The next level up of program code is called assembly language.

Assembly programming is also known as "bit banging" and while its the original programming language of the PIC range, to perform a simple tasks quickly becomes extremely complex. As micro controllers boomed in popularity, so too did the range of development software available for end-users which allowed common programming languages such as Basic and C to be utilised. These program tools are called compilers and put simply, they compile all of the required Assembly code so that the programs behaves with the same intent of that of the higher language. Consider this small program written with Swordfish;

Device = 18F452                                 // Declare the device in use
Clock = 20                                      // Clock speed
Dim Result As Word                              // Declare a variable defined as a word (0-65535)
Const Const1 = 100                              // Declare a constant 
Include "LCD.bas"                               // Include the LCD library
Include "Convert.bas"                           //   and the Convert library
DelayMS(200)                                    // Allow the LCD to initialize
LCD.Cls                                         // Clear the LCD screen
Result = (Const1 - 5) * 500                     // Do some simple math
LCD.WriteAt(1,1,Convert.DecToStr(Result))       // Display the result on the LCD screen
While True                                      // End of program, loop here forever

The program is fairly well commented so you can see what is happening, but did you notice how simple the commands are? Swordfish compiles this code to 609 program bytes of machine code.

Which brings me to my next point - some compilers are better then others, much better. Some compilers are buggy and do not produce efficient code, inducing undesired overheads. It is worth the $100-$200 on a good compiler as it will save you hours upon hours of development time. Important features to look for in compilers are; free updates, rich libraries, extensive support.

Popular compilers out there that are worth the venture are explained and can be downloaded here.

Forum Activity

Member Access