THE POT COMMAND
The compiler provides the POT command to make it easy to read the resistive load placed on a pin. See the PICBASIC PRO manual for details. In order to use this com- mand, it is necessary to set up the connection to the Lab-X1 as follows:
1. Set up the MCU for analog mode.
2. Select the pin to be used for input.
3. Select what the excitation voltage source will be (internal or external).
There are only 16 pins that may be used with the POT command, and they are the 16 pins that have been assigned the aliases from PIN0 to PIN15. These are assigned in the include file BS1DEFS.BAS. For the 16F877A, these are the pins on PORTB (0 to 7)
and PORTC (8 to 15). There are different designations for the different MCUs based on the pin count. See Section 4.11 in the PICBASCIC PRO manual for a discussion of how the pin numbers are assigned for each PIC device.
The POT command is:
POT pin, scale, NBR.
The value of these variables is as follows:
N Pin is the pin number we have been discussing.
N Scale is the adjustment for various RC constants. If the RC constant is large, the value of scale should be small. Scale is determined experimentally with a potenti- ometer in place of the resistive load. At the low end of the resistance the value of scale should be 0, and at the high end it should be 255.
N NBR is the variable the result will be placed in.
Values between 5 and 50K ohms may be read with a 0.1 L F capacitor as shown in the Compiler manual under the POT command.
CAPACITANCE
Capacitance can be measured by determining how long it takes to charge a capacitor through an accurately calibrated resistor or by setting up an oscillator with the two components and measuring its frequency.
VOLTAGE
Voltage is measured by setting up an appropriate dividing network with precision resistors and measuring the voltage across an appropriate resistance.
FREQUENCY
The PIC 16F877A can measure frequencies directly. The timers and counters within the MCU are used to set the measurement intervals and counting hardware.
READING SWITCHES
Switches can be read from the lines of any port that is set up as an input port. Debouncing must be performed either in hardware or in software to avoid false read- ings. (See BUTTON command in the PICBASIC PRO manual.)
Make sure that other hardware that may be connected to the pins does not interfere with the switch function and its detection.
Reading Switches in a Matrix
Switches arranged in a matrix can be read by setting and reading the rows and columns in the matrix. The technique activates a row of buttons at a time by making it high or low and then seeing if any of the columns has been affected. A detailed description
of how this is done is in Chapter 5, which discusses the keyboard of the LAB-X1 in detail.