Lread8, Lread16, Lread24, Lread32
Syntax
Variable = Lread8 Label [ Offset Variable ]
or
Variable = Lread16 Label [ Offset Variable ]
or
Variable = Lread24 Label [ Offset Variable ]
or
Variable = Lread32 Label [ Offset Variable ]
Overview
Read an 8, 16, 24, or 32-bit value from an Ldata table using an offset of Offset Variable and place into Variable, with more efficiency than using Lread.
Lread8 will access 8-bit values from an Ldata table. Lread16 will access 16-bit values from an Ldata table. Lread24 will access 24-bit values from an Ldata table. Lread32 will access 32-bit values from an Ldata table, this also includes floating point values.
Parameters
Variable is a user defined variable of type Bit, Byte, Word, Long, Dword, Float or Array. Label is a label name preceding the Ldata 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 Ldata table.
Lread8 Example
' Extract the second value from within an 8-bit Ldata table
Device = 16F1829 ' Select the device to compile for
Declare Xtal = 8 ' Tell the compiler the device will be operating at 8MHz
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
Cls ' Clear the LCD
Offset = 1 ' Point to the second value in the Ldata table
' Read the 8-bit value pointed to by Offset
MyResult = Lread8 Byte_Table[Offset]
Print Dec MyResult ' Display the decimal result on the LCD
Stop
' Create a table containing only 8-bit values
Byte_Table: Ldata as Byte 100, 200
Lread16 Example
' Extract the second value from within a 16-bit Ldata table
Device = 16F1829 ' Select the device to compile for
Declare Xtal = 8 ' Tell the compiler the device will be operating at 8MHz
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
Cls ' Clear the LCD
Offset = 1 ' Point to the second value in the Ldata table
' Read the 16-bit value pointed to by Offset
MyResult = Lread16 WordTable[Offset]
Print Dec MyResult ' Display the decimal result on the LCD
Stop
' Create a table containing only 16-bit values
WordTable: Ldata as Word 1234, 5678
Lread32 Example
' Extract the second value from within a 32-bit Ldata table
Device = 16F1829 ' Select the device to compile for
Declare Xtal = 8 ' Tell the compiler the device will be operating at 8MHz
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
Cls ' Clear the LCD
Offset = 1 ' Point to the second value in the Ldata table
' Read the 32-bit value pointed to by Offset
MyResult = Lread32 DwordTable[Offset]
Print Dec MyResult ' Display the decimal result on the LCD
Stop
' Create a table containing only 32-bit values
DwordTable: Ldata as Dword 12340, 56780
Notes
Data storage in any program is of paramount importance, and although the standard Lread command can access multi-byte values from an Ldata table, it was not originally intended as such, and is more suited to accessing character data or single 8-bit values. However, the Lread8, Lread16, Lread24, and Lread32 commands are specifically written in order to efficiently read data from an Ldata table, and use the least amount of code space in doing so, thus increasing the speed of operation. Which means that wherever possible, Lread should be replaced by Lread8, Lread16, Lread24, or Lread32.
See also : Cdata, cPtr8, cPtr16, cPtr24, cPtr32, Cread, Cread8, Cread16, Cread24, Cread32, Dim As Flash, Ldata, Lread.

