Pic Programming

One of the things I found hard with PIC programming is understanding even the basics of coding using assembly code. Although there are just 33 instructions it might as well of been written in Klingon for all I knew as I simply didn't understand it. I therefore looked for an alternative and came across several languages including three or more versions of BASIC.

The following sections outline the things I tried, and shows (where possible) a typical example of the standard beginners program, the "Flash the LED" so you can compare the structure and see which one works for you. The code has been centred simply for presentation, normally its left justified

JAL - (Just Another Language)

The first language I used was JAL. For weeks I tried to write the simple "Flash a LED" program in assembly, then in less than an hour had a PIC flashing an LED when using JAL. This was great stuff, as most of my PIC requirements initially was to flash LEDs or do things on the activation of switches. In fact after a few days I was able to write code to control a standard RC servo direct from a 12F675 PIC. However JAL has its limitations, and a lot of things that PICs offer has not been covered, so you have to drop out to assembly, which somewhat defeats the object really. The good thing about JAL is that its free, and has an active Yahoo user group that helps out when you have a problem.

The 1st line of the code calls an INC file which contains pre set settings and saves having 1000's of lines of code to set the PIC up. The second line includes the JAL library files. Next a variable is set and assigned to pin a0, with the pin set as output. Then a simple loop runs changing the state from high (on) to low (off) with a delay of 100ms (20 * 5) between states.

include f675_4i
include jlib
var bit LED1 is pin_a0

pin_a0_direction = output

Forever loop
LED1 = high
delay_20ms( 5 )
LED1 = low
delay_20ms( 5 )
end loop

Mikro Basic

Mikrobasic is designed to compliment the excellent range of development boards from Mikro Electronics. The language is a free download, with a limitation of 2K of programming. However 2K is a lot of programming space and shouldn't pose a problem for hobby use. However in practice I found the PIC would not run the resulting HEX file the compiler produced. I'm not sure if this was down to the settings in the application (you have to set up the PIC via the software rather than writing them into the code or using an include file), or some bug in the compiler. However after several attempts I gave up.

The compiler comes with an excellent IDE (application for writing the code and de-bugging) and has excellent support via an active forum and lots of download examples and reference manuals in the form of PDFs.

while true
PORTB = %00000001
while true




Unlike the other two applications featured here PicBASIC is not free, (although there is a free download it is limited to just 50 lines making it more or less impractical to use). I've found that PicBASIC is simple and easy to understand and the better structured of these languages.

The example here is for an 8 pin PIC (like the 12F675) The first like sets the variable LED to the pin GPIO.0. The next two lines set all outputs to digital and turns of the comparators. Then we have the main loop which runs round with a half second (500 ms) delay between setting the variable LED high and low

As you can see PBP is more logical and thus (in my opinion) easy to understand and get to grips with.

LED Con 0

low LED
high LED
Goto Loop