Skip to content

IO Pins

kaiateic edited this page Jun 8, 2016 · 2 revisions

Syntax

PINMODE <pin> INPUT [PULLUP|PULLDOWN|ADC]

PINMODE <pin> OUTPUT

<pin> = expression

<variable> = <pin>

ANALOG REFERENCE, INTERNAL|EXTERNAL

ANALOG RESOLUTION, 8|10|12|14

Description

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 (naming convention)
P1(7) Pin P1_7
P2(0) Pin P2_0

Inputs

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.

Outputs

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.

Analog

The pins on group P0 can also read anlog signals. To enable a pin for analog input do the following:

PINMODE P0(0) INPUT 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:

ANALOG REFERENCE, 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:

ANALOG RESOLUTION, 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. 8191 corresponds to 1.24V, for the internal reference voltage, and to the external reference voltage (maximum Vdd [supply voltage]), when the external reference is enabled.