Positron Compiler Documentation

PinMode

Source: Positron8 Compiler User Manual, PDF page 173

Syntax

PinMode Port.Pin or Pin Number , Mode

Overview

Makes the specified Port or Pin an input, output or enables internal pull-up resistors.

Parameters

Port.Pin must be a Port.Pin constant declaration. Pin Number can be any variable or constant or expression holding 0 to the amount of I/O pins on the device. A value of 0 will be PORTA.0, if present, 1 will be PORTA.1, 8 will be PORTB.0 etc… Mode can be the texts Input, Output or PullUp or Input_PullUp.

Mode Input will turn the pin into an input. Mode Output will turn the pin into an output. Mode PullUp will enable the internal pull-up resistor for a pin that has previously been made an input. Mode Input_PullUp will set the pin to an input and enable the internal pull-up resistor.

Example 1

PinMode PORTB.0, Input
                             ' Make pin-0 of PORTB an input
PinMode 0, Input
                             ' Make pin-0 of PORTA an input
PinMode 8, Input
                             ' Make pin-0 of PORTB an input
PinMode PORTB.0, Output
                             ' Make pin-0 of PORTB an output
PinMode 0, Output
                             ' Make pin-0 of PORTA an output
PinMode 8, Output
                             ' Make pin-0 of PORTB an output
PinMode PORTB.0, PullUp
                             ' Enable the pull-up resistor for pin-0 of PORTB
PinMode 0, PullUp
                             ' Enable the pull-up resistor for pin-0 of PORTA.0
PinMode 8, PullUp
                             ' Enable the pull-up resistor for pin-0 of PORTB
PinMode PORTB.0, Input_PullUp ' Make input and enable the pull-up resistor on RB0
PinMode 0, Input_PullUp
                                ' Make input and enable the pull-up resistor on RA0
PinMode 8, Input_PullUp
                                ' Make input and enable the pull-up resistor on RB0

Example 2

' Flash each of the pins on PORTA and PORTB
'
  Device = 18F25K40
                                ' Select the device to compile for
  Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
  Dim MyPin as Byte
  High PORTA
  High PORTB
  For MyPin = 0 to 15
                           ' Create a loop for the pin to flash
     PinMode MyPin, Output   ' Set the pin as an output
     DelayMs 500            ' Delay so that it can be seen
     PinMode MyPin, Input    ' Set the pin as an input
     DelayMs 500            ' Delay so that it can be seen
  Next

Notes

Each pin number has a designated name. These are Pin_A0…Pin_A7, Pin_B0…Pin_B7, Pin_C0…Pin_C7, Pin_D0…Pin_D7 to Pin_L7 etc… Each of the names has a relevant constant value, for example, Pin_A0 has the value 0, Pin_B0 has the value 8, up to Pin_L7, which has the value 87. For 8-pin devices, the pins can be referenced as Pin_IO0...Pin_IO5. The pin names can be found within the device’s .def file, within the compiler’s directory.

These can be used to pass a relevant pin number to a procedure or subroutine. For example:

'
' Flash an LED attached to PORTB.0 via a procedure
' Then flash an LED attached to PORTB.1 via the same procedure
'
  Device = 18F25K40
                                  ' Select the device to compile for
  Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
  Dim PinNumber As Byte
                                  ' Holds the pin number to set high and low
  Do
                                  ' Create an infinite loop
     PinNumber = Pin_B0
                                  ' Give the pin number to flash (PORTB.0)
     FlashPin()
                                  ' Call the procedure to flash the pin
     PinNumber = Pin_B1
                                  ' Give the pin number to flash (PORTB.1)
     FlashPin()
                                  ' Call the procedure to flash the pin
  Loop
                                  ' Do it forever
'
' Set a pin high then an input for 500ms using a value as the pin to adjust
'
Proc FlashPin()
  High PinNumber
                                  ' Set the pin output high
  DelayMs 500
                                  ' Wait for 500 milliseconds
  PinMode PinNumber, Input
                                  ' Make the pin an input
  DelayMs 500
                                  ' Wait for 500 milliseconds
EndProc

Note.

Not all devices have the ability to have individual pull-up resistors set or cleared on their pins. Most of the newer microcontroller’s have this ability, but if the microcontroller does not have the ability, the compiler will give a warning message. To see if the microcontroller has the ability of enabling or disabling individual pull-up resistors, look in its datasheet for the WPUx SFRs (Special Function Registers). For example WPUA or WPUB or WPUC etc…

See also : Output, Input, PinClear, PinSet, PinPullup, High, Low.