Cread8, Cread16, Cread24, Cread32
Syntax
Variable = Cread8 Label [ Offset Variable ]
or
Variable = Cread16 Label [ Offset Variable ]
or
Variable = Cread24 Label [ Offset Variable ]
or
Variable = Cread32 Label [ Offset Variable ]
Overview
Read an 8, 16, or 32-bit value from a Cdata table using an offset of Offset Variable and place into Variable, with more efficiency than using Cread . For device’s that can access their own flash memory.
Cread8 will access 8-bit values from an Cdata table. Cread16 will access 16-bit values from an Cdata table. Cread24 will access 24-bit values from an Cdata table. Cread32 will access 32-bit values from an Cdata table, this also includes floating point values.
Parameters
Variable is a user defined variable or an Array. Label is a label name preceding the Cdata statement of which values will be read from. Offset Variable can be a constant value, variable, or expression that points to the location of interest within the Cdata table.
Cread8 Example
' Extract the second value from within an 8-bit Cdata table
Device = 18F26K40 ' Tell the compiler what device to compile for
Declare Xtal = 16 ' Tell the compiler the device is operating at 16MHz
Declare Hserial_Baud = 9600
Dim Offset as Byte ' Create a Byte size variable for the offset
Dim MyResult as Byte ' Create a Byte size variable to hold the result
' Create a table containing only 8-bit values
Dim Byte_Table as Flash8 = 100, 200
Offset = 1 ' Point to the second value in the Cdata table
' Read the 8-bit value pointed to by Offset
MyResult = Cread8 Byte_Table[Offset]
HRsoutLn Dec MyResult ' Display the decimal result on the serial terminal
Cread16 Example
' Extract the second value from within a 16-bit Cdata table
Device = 18F4520
Dim Offset as Byte ' Create a Byte size variable for the offset
Dim MyResult as Word ' Create a Word size variable to hold the result
' Create a flash memory table containing only 16-bit values
Dim WordTable as Flash16 = 1234, 5678
Offset = 1 ' Point to the second value in the Ldata table
' Read the 16-bit value pointed to by Offset
MyResult = Cread16 WordTable[Offset]
HRsoutLn Dec MyResult ' Display the decimal result on the serial terminal
Cread24 Example
' Extract the second value from within a 24-bit Cdata table
Device = 18F4520
Dim Offset as Byte ' Create a Byte size variable for the offset
Dim MyResult as Long ' Create a Long size variable to hold the result
' Create a flash memory table containing only 24-bit values
Dim LongTable as Flash24 = 1234, 5678
Offset = 1 ' Point to the second value in the Ldata table
' Read the 16-bit value pointed to by Offset
MyResult = Cread24 LongTable[Offset]
HRsoutLn Dec MyResult ' Display the decimal result on the serial terminal
Cread32 Example
' Extract the second value from within a 32-bit Cdata table
Device = 18F26K40 ' Tell the compiler what device to compile for
Declare Xtal = 16 ' Tell the compiler the device is operating at 16MHz
Declare Hserial_Baud = 9600
Dim Offset as Byte ' Create a Byte size variable for the offset
Dim MyResult as Dword ' Create a Dword size variable to hold the result
' Create a flash memory table containing only 32-bit values
Dim DwordTable as Flash32 = 12340, 56780
Offset = 1 ' Point to the second value in the flash table
' Read the 32-bit value pointed to by Offset
MyResult = Cread32 DwordTable[Offset]
HRsoutLn Dec MyResult ' Display the decimal result on the serial terminal
Notes
Data storage in any program is of paramount importance, and although the standard Cread command can access multi-byte values from a flash memory data table, it was not originally intended as such, and is more suited to accessing character data or single 8-bit values. However, the Cread8, Cread16, Cread24, and Cread32 commands are specifically written in order to efficiently read data from an Cdata table, and use the least amount of code space in doing so, thus increasing the speed of operation. Which means that wherever possible, Cread should be replaced by Cread8, Cread16, Cread24, or Cread32.
See also : Cdata, Cread, Dim as Flashx, CPtr8, CPtr16, CPtr14, CPtr32, CPtrF.

