Positron Compiler Documentation

PinMode

Source: Positron16 Compiler User Manual, PDF page 194

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, 16 will be PORTB.0 etc… Mode can be the texts Input or Output.

Mode Input will turn the pin into an input. Mode Output will turn the pin into an output.

Example 1

PinMode PORTB.0, Input
                              ' Make pin-0 of PORTB an input
PinMode 0, Input
                              ' Make pin-0 of PORTA an input
PinMode 16, 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 16, Output
                              ' Make pin-0 of PORTB an output

Example 2

' Flash each of the pins on PORTA
'
   Device = 24HJ128GP502
                                ' Select the device to compile for
   Declare Xtal = 16
   Dim MyPin as Byte
   High PORTA
   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_A1, Pin_A2, Pin_B0…Pin_B15, Pin_C0…Pin_C15, Pin_D0…Pin_D15 to Pin_L15 etc… Each of the names has a relevant value, for example, Pin_A0 has the value 0, Pin_B0 has the value 16, up to Pin_J15, which has the value 143.

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 = 24HJ128GP502
                                   ' Select the device to compile for
  Declare Xtal = 16
  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()
  PinHigh 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

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