SAFReadWord

Syntax:

    'as a subroutine
    SAFReadWord ( location, data_word_variable )

    'as a function
    data_word_variable = SAFReadWord ( location )

Command Availability:

Available on all PIC microcontrollers with SAFM memory.

Explanation:

SAFReadWord is used to read information, word values, from SAFM so that it can be accessed for use in a user program.

location represents the location or relative address to read. The location ranges from 0 to SAF_BYTES - 1.    Each data word requires 2 SAF locations, so the location ranges from either 0 to 254 or 0 to 126 (in steps of 2), depending on the device.

data is the word data to be read from the SAFM location.    This must be a word variable.

This method reads word information from SAFM given the relative location in SAFM.   

Example 1:

    '... code preamble to select part
    '... code to setup serial

    'The following example uses a subroutine to read an SAFM location into a word variable.

    dim data_word_variable as word

    ;Write a word to SAF location 64
    SAFWriteWord(  64, 0x1234 )

    ; Read the Word from SAF location 64
    SAFReadWord ( 64, data_word_variable  )          ' <<< the subroutine form of SAFReadWord this page documents

    HSerPrint "Value = "
    HSerPrint data_word_variable
    HSerPrintCRLF

Key line: SAFReadWord ( 64, data_word_variable ) — reads the 16-bit value stored at SAFM location 64 into data_word_variable.

If example 1 were displayed on a serial terminal, the result would show:

    Value = 4660

Example 2:

    '... code preamble to select part
    '... code to setup serial

    'The following example uses a function to read an SAFM location into a word variable.

    dim data_word_variable as word

    ;Write a word to SAF location 64
    SAFWriteWord(  64, 0x4321 )

    ; Read the Word from SAF location 64
    data_word_variable = SAFReadWord ( 64 )          ' <<< the function form of SAFReadWord this page documents

    HSerPrint "Value = "
    HSerPrint data_word_variable
    HSerPrintCRLF

Key line: data_word_variable = SAFReadWord ( 64 ) — the function form of the same read, returning the 16-bit value directly.

If example 2 were displayed on a serial terminal, the result would show:

    Value = 17185

See Also: