Positron Compiler Documentation

High (PinHigh)

Positron16 · Revision 1.1.3.5 · PDF pages 172–173

High Port or Port.Bit or Pin Number

or

PinHigh Port or Port.Pin or Pin Number

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.

Port must be any valid port. Port.Bit can be any valid port and bit combination, i.e. PORTA.1 Pin Number can be a variable or constant that holds a value from 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…

Device = 24HJ128GP502           ' Select the device to compile for
Declare Xtal = 16

Symbol LED_Pin = PORTB.4
PinHigh LED_Pin               ' Set Pin PORTB.4 output high

High PORTB                    ' Set all pins of PORTA output high
PinHigh PORTA.0                ' Set Pin PORTA.0 output high

PinHigh 1                     ' Set Pin PORTA.1 output high
PinHigh PORTB.4               ' Set Pin PORTB.4 output high
' Flash each of the pins on PORTB
'
    Device = 24HJ128GP502        ' Select the device to compile for
    Declare Xtal = 16

    Dim MyPin as Byte

    For MyPin = 16 to 31          ' Create a loop for the pin to flash (PORTB)
        PinHigh MyPin             ' Set the pin high
        DelayMs 500              ' Delay so that it can be seen
        PinLow MyPin              ' Pull the pin low
        DelayMs 500              ' Delay so that it can be seen
    Next

The compiler will write to the device’s LAT SFR and will always set the relevant Port or Port.Bit to an output.

View original PDF page 172Open page in PDFOriginal PDF page 172

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 low for 500ms using a variable as the pin to adjust
'
Proc FlashPin(pPinNumber As Byte)
  PinHigh pPinNumber             ' Set the pin output high
  DelayMs 500                    ' Wait for 500 milliseconds
  PinLow pPinNumber             ' Pull the pin output low
  DelayMs 500                    ' Wait for 500 milliseconds
EndProc
' Clear then Set each pin of PORTC
  Device = 24HJ128GP502             ' Select the device to compile for
  Declare Xtal = 16

  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
       PinLow 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
       PinHigh PinNumber            ' Set each pin of PORTC
       DelayMs 100                  ' Slow things down to see what's happening
     Next                           ' Close the loop
  Loop                              ' Do it forever

The name PinHigh can also be used to replace the command High, and this, sometimes, makes the BASIC code a little clearer to read. PinHigh and High perform exactly the same task.

See also : Clear, Dim, Low, Set, PinSet, Symbol.

View original PDF page 173Open page in PDFOriginal PDF page 173