News:

;) This forum is the property of Proton software developers

Main Menu

Restore and data tables

Started by See_Mos, Jul 07, 2021, 11:43 AM

Previous topic - Next topic

See_Mos

In the help file several of the pages covering flash memory and EEPROM command indicate:

See also : Cdata, Cread, Dim as Code, Data, Edata, Lread, Read, Restore

but I cannot see any connection to restore other than interrupts?  I seem to remember that is was used in the very early days of picin' in connection with data tables.

Also, the code that I am working on at the moment requires multiple data tables.  Am I correct in thinking that LDATA which can use labels: is the best method?

See_Mos

I solved the second part of my query using a procedure for each data table and using the LookUp command

top204

#2
The Read and Restore words are texts I forgot to remove from the manual.

The early compiler had Data, Read and Restore, but once I created true data table mechanisms, they were no longer required. They were a remnand to the older interpreted BASIC languages that were not very flexible because the old BASIC languages did not have different variable types, so the Data and Read could only store and read 8-bit values, which is rather pointless in the 21st century.

LookUp and LookDown are throwbacks to the original syntax of the compiler and were to keep compatability to the BASIC Stamp. They are very inefficient compared to the Flash memory table mechanisms.

The better way to access Flash memory is the Dim As FlashX tables, then either cPtrX or CreadX. The name of the flash memory table is used as its start, then a a simple Index variable reads each piece of data from it, if using CReadX. Or the address of the flash memory table, then increment it to read each piece of data if using cPtrX. The compiler also auto places the flash memory tables in the device for more efficiency.

See_Mos

I copied the data from the Lookup tables to the flash8 tables but the results were not right.  The code compiled without errors. It took me a while to work out but it is there in the help file, all of the numbers are shown in decimal

1C 33 21 29 45 16 1E correct
6E 2D DF 29 79 6A 78 errors

When I changed the Flash8 data to decimal values instead of Hex values it worked as expected.

Now to convert the rest of the tables



top204

If using Hexadecimal constant values, make sure you had the '$' character preceding them, and no '$' character for decimal values.

Below is a code snippet to show how simple it is to create and access flash memory data tables:

    Device = 18F25K20
    Declare Xtal = 16
'
' Setup USART1
'
    Declare Hserial1_Baud = 9600                            ' Setup the Baud rate of USART1
    Declare HRSOut1_Pin = PORTB.6                           ' Setup the pin used for USART1 TX
'
' Create a Flash memory data table containing values in hexadecimal notation
'
    Dim Hex_Table As Flash8 = $01, $02, $03, $04, $05, $06, $07, $08, $09, $0A
'
' Create a Flash memory data table containing the same values as above, but in decimal notation
'   
    Dim Dec_Table As Flash8 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
'
' Create some variables for the demo
'   
    Dim bIndex As Byte                          ' Holds the index to a data table
    Dim bValue As Byte                          ' Holds the value read from a data table

'-------------------------------------------------------
Main:
   
    For bIndex = 0 To Bound(Hex_Table)          ' Create a loop for the length of a flash memory data table
        bValue = CRead8 Hex_Table[bIndex]       ' Read an 8-bit value from the Hexadecimal notation data table
        HRSOut Dec bValue, ",", Hex2 bValue, " : " ' Display the value on a serial terminal in decimal and hex
       
        bValue = CRead8 Dec_Table[bIndex]       ' Read an 8-bit value from the Decimal notation data table
        HRSOutLn Dec bValue, ",", Hex2 bValue   ' Display the value on a serial terminal in decimal and hex
    Next                                        ' Close the loop

On the serial terminal, it will show:

1,01 : 1,01
2,02 : 2,02
3,03 : 3,03
4,04 : 4,04
5,05 : 5,05
6,06 : 6,06
7,07 : 7,07
8,08 : 8,08
9,09 : 9,09
10,0A : 10,0A


The values are the same in decimal and hex from the decimal and hexadecimal notation data tables.

If you press the F2 button and view the assembler code, it can be seen that the data tables contain exactly the same values:
;---------------------------------------------
; USER. FLASH MEMORY TABLE DATA
Hex_Table
    db 1,2,3,4
    db 5,6,7,8
    db 9,10
Dec_Table
    db 1,2,3,4
    db 5,6,7,8
    db 9,10

See_Mos

Thanks Les

Of course I know to use $A1 etc.

I don't know where I went wrong yesterday or why the code worked when I changed HEX data to decimal.  This morning I remmed out the decimal tables and unremmed the HEX ones and it worked as expected, very strange!