28123 Parallax Inc, 28123 Datasheet - Page 165

TEXT WHAT'S A MICROCONTROLLER

28123

Manufacturer Part Number
28123
Description
TEXT WHAT'S A MICROCONTROLLER
Manufacturer
Parallax Inc
Type
Programmingr
Datasheet

Specifications of 28123

Style
Book
Title
What's a Microcontroller?
Contents
Whats a Microcontroller? Text
Product
Microcontroller Accessories
Core Processor
PIC16C57c
Flash
128 Bytes
Operating Supply Voltage
9 V
Board Size
31 mm x 16 mm
Lead Free Status / RoHS Status
Not applicable / Not applicable
Using Constants in Programs
In larger programs, you may end up using the
scale factor (which was 185) and the offset (which was 500) many times in the program.
You can use alias names for these values with the
Now, anywhere in your program that you want to use one of these values, you can use the
words
You can also apply the same technique with the I/O pins. For example, you can declare a
constant for I/O pin P7.
There are two places in the previous example program where the number 7 is used to
refer to I/O pin P7. The first can now be written as:
The second can be written as:
If you change your circuit later, all you have to do is change the value in your constant
declaration, and both the
offset
scaleFactor CON 185
offset CON 500
time = time */ scaleFactor
time = time + offset
rcPin
HIGH rcPin
RCTIME rcPin, 1, time
Substitute your
Add this line of code between the
can view your results.
Run the modified program and check your work. Because the values were
rounded off, the limits may not be exactly 500 and 1000, but they should be
pretty close.
These alias names are just about always declared near the beginning of the program so
that they are easy to find.
DEBUG HOME, DEC5 time
or
scaleFactor
CON 7
scale
HIGH
instead. For example,
and
and
offset
RCTIME
' Display adjusted time value.
values in ControlServoWithPot.bs2.
PULSOUT
commands will be automatically updated.
PULSOUT
CON
directive like this:
and
command and the value of the
LOOP
' Scale by 0.724.
' Offset by 500.
commands so that you

Related parts for 28123