CREATE SMALL ROUTINES
The art to writing a program that can be easily "de-bugged" is to create
small "self-contained" routines. When trying to de-bug a program
it is much easier to have a complete routine on the page rather than jumping
to instructions all-over the place. It may take a few more instructions to
have everything in the one place but it makes things a lot easier.
Introduce routines one-at-a-time to the project and test them before adding
another. If a sub-routine does not work, try changing some of the variables
(called literals in PIC programming) and the instructions, until something happens. Make sure you are
not using any of the files from another routine and make sure any of the
"exotic" instructions (XOR, BTFSS etc) are actually doing what you
think they are doing. It is always best to take code from a previous project
or from the Library of
Routines - the instructions
tried and tested. But if you are using a
different port, or already using some of the files, the code will have to be
changed - and that's when you have to be careful.
Always include a description for each line. Nearly every line can have a
description of the reason why the instruction has been used. Don't simply
explain the meaning of the instruction. Write the PURPOSE of the
instruction. When you are creating the code, the purpose is obvious. But
when you come back after 6 months or so, you will be asking: "What is
this instruction doing??" "Why has this particular value been
Reading a program in Mnemonics is difficult because the files have values
such as 06, 10h, 1A, 20h, 2F and the values loaded into a file also have
exactly the same values. When the instruction has the letter
"L" in it, the hex value that follows is a number.
The other difficulty in reading the instructions, applies to: ,0
,1 This sometimes refers to the instruction placing the
result in W or in the file being operated on, OR it may refer to bit
0 or bit 1. If the instruction starts with "B" (BTFSS etc) the
digit is bit 0 or bit 1. In all other cases the ,0 or ,1 refers to the place
where the result of the operation will be stored.