SAFRead

Syntax:

    'as a subroutine
    SAFRead ( location, data )

    'as a function
    data = SAFRead ( location )

Command Availability:

Available on all PIC microcontrollers with SAFM memory.

Explanation:

SAFRead is used to read information, byte 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 location 0 to SAF_BYTES - 1. This can be 0-127 or 0-255, depending on the specific device. SAF_BYTES is a GCBASIC constant that represents the number of bytes of SAF memory.   

data is the data to be read from the SAFM data storage area.    This can be a byte value or a byte variable.

This method reads data from SAFM given the specific relative location.    This method is similar to the EPRead method for EEPROM.

Example 1:

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

    'The following example reads the SAFM data value into the byte variable byte_value using a subroutine.

    Dim data_byte as byte
    Dim byte_value as byte

    ;Write a byte of data to SAF Location 34
    SAFWrite( 34, 144)

    ;Read the byte back from SAF location 34
    SAFRead( 34, byte_value )          ' <<< the subroutine form of SAFRead this page documents

    ;Display the data on a terminal
    HserPrint "byte_value = "
    Hserprint byte_value

Key line: SAFRead( 34, byte_value ) — reads the byte stored at SAFM location 34 into byte_value using the subroutine form.

Example 2:

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

    'The following example reads the SAFM data value into the byte variable byte_value using a function.

    Dim byte_value as byte

    ;Write a byte of data to SAF Location 34
    SAFWrite( 34, 144)

    ;Read the byte back from SAF location 34
    byte_value = SAFread( 34 )          ' <<< the function form of SAFRead this page documents

    ;Display the data on a terminal
    HserPrint "byte_value = "
    Hserprint byte_value

Key line: byte_value = SAFread( 34 ) — the function form of the same read, returning the value directly instead of writing it into an output parameter.

See Also: