SAFWriteBlock

Syntax:

    SAFWriteBlock ( block_number,  buffer(), [, num_bytes] )

Command Availability:

Available on all PIC micro-controllers with SAFM memory.

Explanation:

SAFWriteBlock is used to write information from a user buffer to SAFM.    Once the block is written it can be accessed for use within a user program.

The parameters are as follows:

block_number represents the block to be written to.    The block_number parameter is used to calculate the physical memory location(s) that are updated.

buffer() represents an array or string.    The buffer will be used as the data source that is written to the SAFM block.    The buffer is handled as a buffer of bytes values.    In most cases the buffer should be the same size as a row/block of SAFM.    For most PIC Microcontrollers this will be 32 bytes.    Best practice is to size the buffer using the SAF_ROWSIZE_BYTES constant.    If the size of the buffer exceeds the device specific SAF_ROWSIZE_BYTES, the excess data will not be handled and the buffer will be truncated at the SAF_ROWSIZE_BYTES limit.   

num_bytes is an optional parameter, and can be used to specify the number of bytes to write to HEFM, starting at the first location in the selected HEFM block.    This parameter is not normally required as the default is set to the GCBASIC constant HEF_ROWSIZE_BYTES.

Example 1:

    #chip 18F24K42, 16
    '... code preamble to setup PPS
    '... code to setup serial

      Dim My_Buffer(HEF_ROWSIZE_BYTES)
      Dim index as byte

      ;Write some data to Block 2
      My_Buffer = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
      SAFWriteBlock(2, My_Buffer())

      ;Read the data back from SAFM using SAFReadBock
      SAFReadBlock( 2 , My_buffer() )

     ;Send the data to a terminal in decimal format
      index = 1
      Repeat SAF_ROWSIZE_BYTES
          Hserprint(My_Buffer(index))
          HserPrint " "
          index++
     End Repeat



See also SAFM Overview, SAFRead, SAFReadWord, SAFWrite, SAFWriteWord, SAFReadBlock, SAFWriteBlock, SAFEraseBlock