Saturday, 20 October 2012

A Few Positive Comments

So in this post, let's make a start on fixing some of the problems with the world's smallest (and worst) PIC microcontroller program.

First, lets add a comment which will serve as a title and an introduction to what the program does and how it works.

;Comments start with a semicolon, so in assembly source code, this sentence is a comment.

Here's the updated program:

;Assembly language program for the 16F690 which lights LED DS1 on the Low Pin Count Demo Board. It works, but it's full of bugs.

bsf 7,0 ;change 0 to 1, 2, or 3 to light different LEDs
bsf 3,5
clrf 87

You'll notice I've also added a comment to the end of the first line of code. This technique can be used to explain what that particular line does. Everything after a semicolon (until the line ends) is treated as a comment and is ignored by the assembler.

The rule with comments is:

Add as many comments as necessary to remind yourself how your program works.

No comments:

Post a Comment