lookup_tables - GreatCowBASIC/Help GitHub Wiki
Overview
A lookup table is a list of values stored in the
microcontroller’s memory and accessed using ReadTable.
Key Features
- Efficient memory usage
- Supports
byte,word,long, andintegertypes - ASCII string definitions supported
- Constants and inline calculations permitted
- External data sources allowed
Note: Decimal values are not supported
Contents
Defining Tables
Single Values
Table TestDataSource
12
24
36
48
60
72
End Table
Multiple Values
Table TestDataSource
12, 24, 36
48, 60, 72
End Table
Constants & Calculations
#define calculation_constant 2
Table TestDataSource
1 * calculation_constant
2 * calculation_constant
3 * calculation_constant
8 * calculation_constant
4 * calculation_constant
5 * calculation_constant
End Table
String Tables
Simple Examples
Table Test_1
"ABCDEFGHIJ"
End Table
Table MnuTxt_1
" Display_1 Display_2 Display_3 "
End Table
Table MnuTxt_2
"1: Display"
"2: System Setup"
"3: Config 1"
"4: Config 2"
"5: Data Log"
"6: Diagnostic"
"7: Help+"
End Table
Equivalent Representations
"String1", "String2", "String3""String1String2String3"-
"String1""String2""String3"
ASCII Escape Sequences
| Escape | Meaning |
|---|---|
| \a | Beep |
| \b | Backspace |
| \f | Formfeed |
| \n or \l | Newline |
| \r | Carriage Return |
| \t | Tab |
| \0 | Null value (ASCII 0) |
| \&nnn | ASCII character (decimal) |
| \\ | Backslash |
| \" | Double quote |
| \' | Single quote |
Reading Lookup Tables
Basic Reading
Dim TableCounter, Invalue as byte
CLS
For TableCounter = 1 to 6
ReadTable TestDataSource, TableCounter, Invalue
Print InValue
Print ","
Next
Reading Table Length
Dim lengthoftable as word
ReadTable TestDataSource, 0, lengthoftable
Print lengthoftable
Importing from External File
#chip 16f877a
Table TestDataSource from "sourcefile.raw"
For nn = 1 to 10
ReadTable TestDataSource, nn, inc
Print inc
Next
EEPROM Table Storage
#chip 16F628
TableLoc = 2
ReadTable TestDataSource, TableLoc, SomeVar
EPWrite 1, 45 'Optional write
Table TestDataSource Store Data
12
24
36
48
60
72
End Table
EEPROM Limitations
- Only
BYTEvalues are supported -
WORD,INTEGER, orLONGare not compatible with EEPROM tables
Reference
See: ReadTable