Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20642

BASCOM-AVR : ERAM - default values : REPLY

$
0
0
Hi Or maybe create a checksum that you also save in the eeprom. And just compare the checksum to the data read. Something like:- [code:1:4a776f80c8]'--The following parameters are written to the eeprom-------------------------- Dim Zeropoint(2) As Word 'Raw zero 4bytes Dim Scale_factor(2) As Single '1pascal=RAW units 8bytes Dim Min_pressure_seal As Integer 'Min seal pressure allowed 2bytes Dim Seal_inflate_timeout As Word 'Timeout to reach it 2bytes Dim Alarm_pressure_seal As Integer 'Alarm limit for seal 2bytes Dim Eeprom_checksum As Byte 'EEPROM CHECKSUM 1bytes '--END OF EEPROM LIST------------------------------------------------------- Dim Eeprom_parameters(20) As Byte At Zeropoint(1) Overlay 'OVERLAY for EEPROM Dim Spare As Word 'Reserve for EEPROM params Dim Eeprom_checksum_calc As Byte 'EEPROM OK FLAG call Setup_defaults() end '------------------------------------------------------------------------------------------- Sub Setup_defaults() 'Function : Read parameters saved in eeprom. If the checksum is incorrect ' load default values and set an alarm bit 'Author : Ian Dobson 'Inputs : None. 'Outputs : None 'Limitations : None : 'Date : 29.1.2013 'Function:- Gosub Loadfromeeprom If Eeprom_checksum <> Eeprom_checksum_calc Then 'AE=OK Print #1 , "Default params" Restore Defaults 'Get ready to read Read Zeropoint(1) 'get default values Read Zeropoint(2) Read Scale_factor(1) Read Scale_factor(2) Read Min_pressure_seal Read Seal_inflate_timeout Read Alarm_pressure_seal Gosub Save2eeprom Else Print #1 , "Load Params" End If '----------------------------------------------------------------------------- ' Load/save parameters to/from eeprom ' These routines rely on the fact that all parameters are overlayed in the ' Eeprom_parameters array ' If new parameters are defined that array/code needs to be modified '----------------------------------------------------------------------------- ' Save2eeprom: '-- save to eeprom Dim Eeprom_address As Byte Dim Ep As Byte: Eeprom_address = 10 'EEPROM start address Eeprom_checksum_calc = &HAA 'Starting point for checksum For Ep = 1 To 18 'Loop though parameters Eeprom_checksum_calc = Eeprom_checksum_calc + Eeprom_parameters(ep) Writeeeprom Eeprom_parameters(ep) , Eeprom_address 'save to eeprom Incr Eeprom_address 'next address Next Ep Writeeeprom Eeprom_checksum_calc , Eeprom_address 'save checksum Return Loadfromeeprom: '-- load from eeprom Eeprom_address = 10 'EEPROM start address Eeprom_checksum_calc = &HAA 'Starting point for checksum For Ep = 1 To 18 'Loop though parameters Readeeprom Eeprom_parameters(ep) , Eeprom_address 'read from eeprom Eeprom_checksum_calc = Eeprom_checksum_calc + Eeprom_parameters(ep) Incr Eeprom_address Next Ep Readeeprom Eeprom_parameters(ep) , Eeprom_address 'Read eeprom checksum Return[/code:1:4a776f80c8] Note the variables to be loaded/saved are overlayed with a byte array that the Loadfromeeprom & Save2eeprom use copy read/write the eeprom. If the checksum is incorrect the default values are read from the data structure Defaults (not included in the code). The variables are saved to the eeprom in exactly the same order as they in ram. Hope this helps abit. The code might be abit tricky to understand but I'm using it on my new project and it's working like a dream. Regards Ian Dobson

Viewing all articles
Browse latest Browse all 20642

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>