Pin Variables
Positron16 · Revision 1.1.3.5 · PDF page 31
A Pin type variable is unique to the Positron compilers and allows a Port.Pin’s mask to be transferred, instead of the contents of the Port.Pin to be read or written.
Example 1.
' Create an SPI interface procedure to talk to several separate devices
'
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
'
' Create the clock and data and CS lines as Pin variables
'
Dim MyDataPin as Pin ' Holds the pin to use for the SPI data line
Dim MyClockPin as Pin ' Holds the pin to use for the SPI clock line
Dim MyCSPin as Pin ' Holds the pin to use for the SPI CS line
'
' Talk to a device using an SPI interface
'
Proc SPI_Send(pData as Pin, pClock as Pin, pCS as Pin, pValue as Byte)
PinLow pCS
Shout pData, pClock, MsbFirst_L, [pValue]
PinHigh pCS
EndProc
'
' Set the clock and data and CS lines
'
MyDataPin = PORTB.3
MyClockPin = PORTB.4
MyCSPin = PORTB.5
SPI_Send(MyDataPin, MyClockPin, MyCSPin, 127)
'
' Or send the clock and data and CS lines as Port.Pin
'
SPI_Send(PORTB.0, PORTB.1, PORTB.2, 127)
Example 2.
' Flash an LED on each pin of PORTB
'
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Dim MyPin as Pin ' Holds the pin to use for the flashing LED on the port
Do
For MyPin = PORTB.0 To PORTB.7
PinHigh MyPin
DelayMs 500
PinLow MyPin
DelayMs 500
Next
Loop
See also : Aliases, Arrays, Dim, Symbol, FloatIng Point Math.
