Positron Compiler Documentation

Ptr8, Ptr16, Ptr24, Ptr32

Source: Positron8 Compiler User Manual, PDF page 339

Syntax

Variable = Ptr8 (Address) Variable = Ptr16 (Address) Variable = Ptr24 (Address) Variable = Ptr32 (Address)

or

Ptr8 (Address) = Variable Ptr16 (Address) = Variable Ptr24 (Address) = Variable Ptr32 (Address) = Variable

Overview

Indirectly address RAM for loading or retrieving using a variable to hold the 16-bit address on enhanced 14-bit core devices and 18F devices.

Parameters

Variable is a user defined variable that holds the result of the indirectly address RAM area, or the variable to place into the indirectly addressed RAM area. Address can be a Word, Long, or Dword variable or expression that holds the 16-bit address of the RAM area of interest.

Address can also post or pre increment or decrement:

(MyAddress++) Post increment MyAddress after retrieving it’s RAM location. (MyAddress --) Post decrement MyAddress after retrieving it’s RAM location. (++MyAddress) Pre increment MyAddress before retrieving it’s RAM location. (--MyAddress) Pre decrement MyAddress before retrieving it’s RAM location.

Ptr8 will load or retrieve a value with an optional 8-bit post or pre increment or decrement. Ptr16 will load or retrieve a value with an optional 16-bit post or pre increment or decrement. Ptr24 will load or retrieve a value with an optional 24-bit post or pre increment or decrement. Ptr32 will load or retrieve a value with an optional 32-bit post or pre increment or decrement.

8-bit Example.

' Load and Read 8-bit values indirectly from/to RAM
'
  Device = 18F25K20
                                          ' Choose an 18F device
  Declare Xtal = 16
                                ' Tell the compiler the device is operating at 16MHz
  Declare Hserial_Baud = 9600
                                          ' Set Baud rate to 9600
  Dim MyByteArray[20] As Byte          ' Create a byte array
  Dim MyByte As Byte                   ' Create a byte variable
  Dim bIndex As Byte
  Dim wAddress as Word
                                          ' Create a variable to hold address
      Main:
      '
      ' Load into RAM
      '
         wAddress = AddressOf(MyByteArray)
                                              ' Load wAddress with address of array
         For bIndex = 19 To 0 Step -1
                                              ' Create a loop
           Ptr8(wAddress++) = bIndex
                                              ' Load RAM with address post increment
         Next
      '
      ' Read from RAM
      '
         wAddress = AddressOf(MyByteArray)
                                              ' Load wAddress with address of array
         Do
                                              ' Create a loop
           MyByte = Ptr8(wAddress++)       ' Retrieve from RAM with post increment
           HRsout Dec MyByte, 13            ' Transmit the byte read from RAM
           If MyByte = 0 Then Break         ' Exit when a null(0) is read from RAM
         Loop

16-bit Example.

' Load and Read 16-bit values indirectly from/to RAM
'
  Device = 18F25K20
                                       ' Choose an 18F device
  Declare Xtal = 16
                                ' Tell the compiler the device is operating at 16MHz
  Declare Hserial_Baud = 9600        ' Set Baud rate to 9600 for HRsoutLn
  Dim MyWordArray[20] As Word
                                       ' Create a word array
  Dim MyWord As Word
                                       ' Create a word variable
  Dim bIndex As Byte
   Dim wAddress as Word
                                       ' Create a variable to hold the address
Main:
'
' Load into RAM
'
  wAddress = AddressOf(MyWordArray)
                                       ' Load wAddress with address of array
  For bIndex = 19 To 0 Step -1
                                       ' Create a loop
     Ptr16(wAddress++) = bIndex      ' Load RAM with address post increment
  Next
'
' Read from RAM
'
  wAddress = AddressOf(MyWordArray)
                                       ' Load wAddress with address of array
  Do
                                       ' Create a loop
     MyWord = Ptr16(wAddress++)       ' Retrieve from RAM with post increment
     HRsout Dec MyWord, 13            ' Transmit the word read from RAM
     If MyWord = 0 Then Break         ' Exit when a null(0) is read from RAM
  Loop

24-bit Example.

' Load and Read 24-bit values indirectly from/to RAM
'
  Device = 18F25K20
                                       ' Choose an 18F device
  Declare Xtal = 16
                                ' Tell the compiler the device is operating at 16MHz
  Declare Hserial_Baud = 9600        ' Set Baud rate to 9600
  Dim MyLongArray[20] As Long
                                       ' Create a long array
  Dim MyLong As Long
                                       ' Create a long variable
  Dim bIndex As Byte
   Dim wAddress as Word
                                       ' Create a variable to hold the address
Main:
'
' Load into RAM
'
  wAddress = AddressOf(MyLongArray)
                                       ' Load wAddress with address of the array
  For bIndex = 19 To 0 Step -1
                                       ' Create a loop
     Ptr24(wAddress++) = bIndex      ' Load RAM with address post increment
  Next
'
' Read from RAM
'
  wAddress = AddressOf(MyLongArray)
                                       ' Load wAddress with address of array
  Do
                                       ' Create a loop
     MyLong = Ptr24(wAddress++)       ' Retrieve from RAM with post increment
     HRsout Dec MyLong, 13            ' Transmit the long read from RAM
     If MyLong = 0 Then Break         ' Exit when a null(0) is read from RAM
  Loop

32-bit Example.

' Load and Read 32-bit values indirectly from RAM
'
  Device = 18F25K20                  ' Choose an 18F device
  Declare Xtal = 16
                                ' Tell the compiler the device is operating at 16MHz
  Declare Hserial_Baud = 9600        ' Set Baud rate to 9600
  Dim MyDwordArray[20] As Dword
                                       ' Create a dword array
  Dim MyDword As Dword
                                       ' Create a dword variable
  Dim bIndex As Byte
  Dim wAddress as Word
                                       ' Create a variable to hold the address
Main:
'
' Load into RAM
'
  wAddress = AddressOf(MyDwordArray) ' Load wAddress with address of the array
  For bIndex = 19 To 0 Step -1
                                       ' Create a loop
     Ptr32(wAddress++) = bIndex      ' Load RAM with address post increment
  Next
'
' Read from RAM
'
  wAddress = AddressOf(MyDwordArray) ' Load wAddress with address of array
  Do
                                       ' Create a loop
     MyDword = Ptr32(wAddress++)     ' Retrieve from RAM with post increment
     HRsout Dec MyDword, 13           ' Transmit the dword read from RAM
     If MyDword = 0 Then Break        ' Exit when a null(0) is read from RAM
 Loop

See also

AddressOf.