-
Notifications
You must be signed in to change notification settings - Fork 0
IO Pins
PINMODE <pin> INPUT [PULLUP|PULLDOWN]
PINMODE <pin> OUTPUT
PINMODE <pin> ADC
<pin> = expression
<variable> = <pin>
ANALOGREFERENCE INTERNAL|EXTERNAL
ANALOGRESOLUTION 8|10|12|14
The CC254X has many input and output pins which can be used in a program. These are managed in three groups, P0, P1 and P2. P0 and P1 have 8 pins each (0 to 7) while P3 has 5 pins (0 to 5). How each pin is used can be set independently of other pins, but there are a few occasions when pins in the same group must have the same properties. For example, if one pin in group P0 is set to PULLUP, then no other pin in that group can be set to PULLDOWN.
Pins are addressed by group, and pin within that group:
BASIC | CC254X |
---|---|
P0(0) | Pin P0_0 (the naming convention in the datasheet) |
P1(7) | Pin P1_7 |
P2(0) | Pin P2_0 |
To set a pin for input do the following:
PINMODE P0(0) INPUT
This sets pin P0(0) as a digital input pin. If this pin is now read:
PRINT P0(0)
The value 0 or 1 will be returned. Input pins have the option of being pulled up or pulled down:
PINMODE P0(0) INPUT PULLUP
If the pin is floating, it will now be pulled up internally and so will read as "1" unless actively pulled down by an external device.
To set a pin for output do the following:
PINMODE P0(0) OUTPUT
To set the value of the pin do the following:
P(0) = 1
This sets the pin high, while setting the value to 0 will make the pin low.
The pins on group P0 can also read anlog signals. To enable a pin for analog input do the following:
PINMODE P0(0) ADC
Values are read from the pin just as if they were digital inputs, but now the pin returns an integer value rather than a simple 0 or 1.
All analog pins share two additional properties; the analog resolution and the analog reference. By default, analog pins use the internal reference and have a resolution of 14 bits. These can be changed. For example:
ANALOGREFERENCE EXTERNAL
This sets the analog pins to use an external reference. The external reference must be connected to pin P0(7).
The resolution of the conversion can be changed as follows:
ANALOGRESOLUTION 10
The following resolutions are available: 8 bit, 10 bit, 12 bit and 14 bit. Note that the CC254X returns a signed value for all ADC conversions. For the default, 14 bit, resolution the pin will return a value between 0 and 8191.