Positron Compiler Documentation

Pin Variables

Positron8 · Revision 4.0.6.5 · PDF page 27

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.

' Create an SPI interface procedure to talk to several separate devices
'
  Device = 18F26K40      ' Select the device to compile for
  Declare Xtal = 16  ' Tell the compiler the device will be operating at 16MHz
'
' Set 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
'
' Alter the clock and data and CS lines
'
  MyDataPin = PORTA.3
  MyClockPin = PORTA.4
  MyCSPin = PORTA.5
  SPI_Send(MyDataPin, MyClockPin, MyCSPin, 127)
'
' Or send the clock and data and CS lines as Port.Pin parameters only
'
  SPI_Send(PORTA.0, PORTA.1, PORTA.2, 127)
' Flash an LED on each pin of PORTB
'
  Device = 18F26K40      ' 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                      ' Create a loop
     For MyPin = PORTB.0 To PORTB.7 ' Create a loop for the amount of pins to alter
       PinHigh MyPin               ' Set a pin output high
       DelayMs 500                  ' Delay for half a second
       PinLow MyPin               ' Set a pin output low
       DelayMs 500                  ' Delay for hald a second
     Next                           ' Close the For loop
  Loop                    ' Do it forever

See also : Aliases, Arrays, Dim, Constants, Symbol, Floating Point Mathematics.

View original PDF page 27Open page in PDFOriginal PDF page 27