Positron Compiler Documentation

Parameter as an Alias to a Global Variable or SFR

Positron16 · Revision 1.1.3.5 · PDF page 57

A parameter can also be aliased to an SFR (Special Function Register). For example:

Proc MyProc(pValue as WREG0)

The above procedure template will use the microcontroller’s WREG0 as the container for the name pValue.

  Dim MyWord as Word             ' Create a global Word variable

Proc MyProc(pValue as MyWord)  ' Use global MyWord to hold value sent to procedure
' A test procedure using two global variables as the containers for the parameters
'
  Device = 24EP128MC202           ' Select the device to compile for
  Declare Xtal = 140.03 ' Tell the compiler the device will be running at 140.03MHz
  Declare Hserial_Baud = 9600   ' Set the Baud rate for HRSout
  Declare Hrsout1_Pin = PORTB.11  ' Select pin to be used for USART1 TX

  Dim MyWord1 as Word             ' Create a global Word variable
  Dim MyWord2 as Word             ' Create a global Word variable
  Dim MyWord3 as Word             ' Create a global Word variable
'
' Create a demo procedure to multiply 2 parameter values and return the result
'
  Proc TestProc(pValue1 as MyWord1, pValue2 as MyWord2), Word
     Result = pValue1 * pValue2
  EndProc

' Setup the Oscillator to operate the device at 140.03MHz
' Fosc = (7.37 * 76) / (2 * 2) = 140.03MHz
  PLL_Setup(76, 2, 2, $0300)
  RPOR4.Byte1 = 1                         ' Make PPS Pin RB11 U1TX

  MyWord3 = TestProc(2000, 10)   ' Call the procedure to multiply the 2 parameters
  HRSoutLn Dec MyWord3  ' Display the value held in MyWord3 (The procedure's return)

As with standard variables, the aliased parameter can also be cast to a type that has fewer bytes. For example, a Word variable can be cast to a Byte type, or a Dword can be cast to a Word or Byte type etc…

Proc MyProc(pMyByte as WREG2.Byte0)
View original PDF page 57Open page in PDFOriginal PDF page 57