High (PinHigh)
Syntax
High Port or Port.Pin or Pin Number
or
PinHigh Port or Port.Pin or Pin Number
Overview
Place a Port or Port.Pin in a high output state. For a Port, this means setting it as an output and filling it with 1's. The name PinHigh can also be used instead of the name High. 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.Pin combination. 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, 8 will be PORTB.0 etc…
Example 1
Device = 18F26K40
' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Symbol LED = PORTB.4
High LED
' Set Pin PORTB.4 output high
High 1
' Set Pin PORTA.1 output high
High Pin_B0
' Set Pin PORTB.0 output high
PinHigh PORTB.4
' Set Pin PORTB.4 output high
Example 2
' Flash each of the pins on PORTA and PORTB
'
Device = 18F25K20
Declare Xtal = 16
Dim MyPin as Byte
For MyPin = 0 to 15
' Create a loop for the pin to flash
High MyPin ' Set the pin high
DelayMs 500 ' Delay so that it can be seen
Low MyPin ' Pull the pin low
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. 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. For example:
'
' Flash an LED attached to PORTB.0 via a procedure
' Then flash an LED attached to PORTB.1 via the same subroutine
'
Device = 18F26K40
' 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 low 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
Low PinNumber
' Pull the pin low
DelayMs 500
' Wait for 500 milliseconds
EndProc
Example 2
' Clear then Set each pin of PORTC
Device = 18F26K40
' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Dim PinNumber as Byte
Low PORTC
' Make PORTC output low before we start
Do
' Create a loop
For PinNumber = Pin_C0 to Pin_C7 ' Create a loop for 8 pins
Low PinNumber
' Clear each pin of PORTC
DelayMs 100
' Slow things down to see what's happening
Next
' Close the loop
For PinNumber = Pin_C0 to Pin_C7 ' Create a loop for 8 pins
High PinNumber
' Set each pin of PORTC
DelayMs 100
' Slow things down to see what's happening
Next
' Close the loop
Loop
' Do it forever