Good
Programming
Techniques
Before
we get
to the
nitty
gritty
of
programming
the PIC,
I think
now is a
good
time to
explain
some
good
programming
techniques.
If you
type a ;
(semicolon)
anywhere
in your
program,
the
compiler
will
ignore
anything
after it
until
the
carriage
return.
This
means we
can add
comments
in our
program
to
remind
us of
what on
earth we
were
doing in
the
first
place.
This is
good
practice,
even for
the
simplest
programs.
You may
well
fully
understand
how your
program
works
now, but
in a few
months
time,
you may
be
scratching
your
head.
So, use
comments
wherever
you can
– there
is no
limit.
Secondly,
you can
assign
names to
constants
via
registers
(more
about
these
later). It
makes it
far
easier
to read
in
English
what you
are
writing
to, or
what the
value
is,
rather
than
trying
to think
of what
all
these
numbers
mean.
So, use
real
names,
such as
COUNT.
Notice
that we
have put
the name
in
capitals.
This
makes it
stand
out, and
also
means
that (by
convention)
it is a
constant
value.
Thirdly,
put some
kind of
header
on your
programs
by using
the
semi-colons.
An
example
is below:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Author
:
;
; Date
:
;
;
Version:
;
;
Title:
;
;
;
;
Description:
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Notice
that We
have
made a
kind of
box by
using
the
semi-colons.
This
just
makes it
look
neat.
Finally,
try and
document
the
program
on paper
as
well.
You can
either
use flow
charts
or
algorithms
or
anything
else you
want.
This
will
help you
in
writing
your
program,
step by
step.
Right,
that’s
the
lecture
over
with,
lets
move on
to the
real
stuff.
Click
here >>>>
Tutorial
2
|