Input (PinInput)
Syntax
Input Port.Pin or Pin Number
or
PinInput Port or Port.Pin or Pin Number
Overview
Makes the specified Port or Pin an input. The name PinInput can also be used instead of the name Input. They both work exactly the same but make the source code a little clearer to read and follow.
Parameters
Port must be the name of a Port. Port.Pin must be a Port, or Port.Pin constant declaration. Pin Number can be any variable or constant 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…
Example 1
Input PORTB.4
' Make pin-4 of PORTB an input
Input PORTB
' Make all of PORTB an input
Input 0
' Make pin-0 of PORTA an input
Input 16
' Make pin-0 of PORTB an input
PinInput PORTB.0
' Make pin-0 of PORTB an input
Example 2
' Flash each of the pins on PORTB
'
Device = 24FJ64GA002
' Select the device to compile for
Declare Xtal = 16
Dim PinNumber as Byte
High PORTB
For PinNumber = 16 to 31 ' Create a loop for the pin to flash
Output PinNumber
' Set the pin as an output
DelayMs 500
' Delay so that it can be seen
Input PinNumber
' Set the pin as an input
DelayMs 500
' Delay so that it can be seen
Next
Notes.
An Alternative method for making a particular pin an input is by directly modifying the TRIS register: -
TRISB.0 = 1
' Make bit-0 of PORTB an input
All of the pins on a port may be set to inputs by setting the whole TRIS register at once: -
TRISB = %1111111111111111 ' Set all of PORTB to inputs
In the above examples, setting a TRIS bit to 1 makes the pin an input, and conversely, setting the bit to 0 makes the pin an output. 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. 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
Do
' Create a loop
FlashPin(Pin_B0)
' Call the procedure to flash PORTB.0
FlashPin(Pin_B1)
' Call the procedure to flash PORTB.1
Loop
' Do it forever
'
' Set a pin high then an input for 500ms using a value as the pin to adjust
'
Proc FlashPin(pPinNumber As Byte)
PinHigh pPinNumber
' Set the pin output high
DelayMs 500
' Wait for 500 milliseconds
PinInput pPinNumber
' Make the pin an input
DelayMs 500
' Wait for 500 milliseconds
EndProc
Note
The name “PinInput” can also be used to replace the command Input, and this, sometimes, makes the BASIC code a little clearer to read. PinInput and Input perform exactly the same task.