READEEPROM/de

From MCS Wiki AVR
Jump to: navigation, search

Contents

Funktion

Liest einen Wert aus dem EEPROM-Speicher und speichert ihn in einer Variablen.

 

 

Syntax

READEEPROM var , address

 

 

Remarks

Var

The name of the variable that must be stored

Address

The address in the EEPROM where the data must be read from.

 

This statement is provided for backwards compatibility with BASCOM-8051.

You can also use the ERAM variable instead of READEEPROM :

 

Dim V as Eram Byte 'store in EEPROM

Dim B As Byte  'normal variable

B = 10

V = B   'store variable in EEPROM

B = V   'read from EEPROM

 

When you use the assignment version, the data types must be equal!

According to a data sheet from ATMEL, the first location in the EEPROM with address 0, can be overwritten during a reset so don't use it.

 

You may also use ERAM variables as indexes. Like :

Dim ar(10) as Eram Byte

 

When you omit the address label in consecutive reads, you must use a new READEEPROM statement. It will not work in a loop:

 

Readeeprom B , Label1

Print B

 

Do

Readeeprom B

Print B Loop

Until B = 5

 

This will not work since there is no pointer maintained. The way it will work :

 

ReadEEprom B , Label1 ' specify label

ReadEEPROM B ' read next address in EEPROM

ReadEEPROM B ' read next address in EEPROM

 

OR

 

Dim Next_Read as Integer

Dim In_byte as Byte

Dim Eerom_position as Integer

 

Eerom_position = 20                                  ' Set the start read point in eerom

For Next_Read = 1 To 5 Step 1                   ' Set up the bytes to be read from eeprom

Readeeprom In_byte , eeprom_position         ' Use a variable as the pointer to eeprom location

Call another_sub_routine                            '

Incr Chr_pos_font                                    ' Now set pointer for next eeprom data byte

Next


 

 

In the XMEGA, you need to set the mode to mapped : CONFIG EEPROM = MAPPED.

 

 

Siehe auch

WRITEEEPROM , $EEPROM

 

 

Assembler

NONE

 

 

Beispiel


'-----------------------------------------------------------------------------------------
'name : eeprom2.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : shows how to use labels with READEEPROM
'micro : Mega48
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
 
$regfile = "m48def.dat" ' Mikrocontroller
$crystal = 4000000 ' Taktfrequenz
$baud = 19200 ' BAudrate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
 
'Zunächst einmal Variablen dimensionieren:
Dim B As Byte
Dim Yes As String * 1
 
'Benutzung von readeeprom und writeeprom :
'readeeprom var, address
 
'Eine neue Option ist, ein Label für die Adresse zu benutzen.
'Da die Daten in einer externen Datei sind und nicht im Programm sollten die EEPROM Daten
'als erstes spezifiziert werden. Dies steht im Gegensatz zu den normalen DATA Zeilen welche
'am Endes des Programms spezifiziert werden!!
 
'Zunächst dem Compiler mitteilen, dass wir das EEPROM nutzen wollen um die Daten zu speichern:
$eeprom
 
'Die erzeugte EEP-Datei ist eine Binär-Datei.
'Benutzen Sie $EEPROMHEX um eine Intel Hex-Datei für die Benutzung mit AVR Studio zu erzeugen.
'$eepromhex
 
'LAbel festlegen:
Label1:
Data 1 , 2 , 3 , 4 , 5
Label2:
Data 10 , 20 , 30 , 40 , 50
 
'Zurückschalten zu normalen DATA-Zeilen für den Fall, dass solche verwendet werden:
$data
 
'Der Code oben erzeugt keinen richtigen Object-Code.does not generate real object code
 
'Benutzung der neuen Label Option
Readeeprom B , Label1
Print B 'Ausgabe einer 1
'Nachfolgende Reads lesen die nächsten Werte
'Beim ersten Mal muss das Label angegeben werden damit die Startadresse bekannt ist.
Readeeprom B
Print B 'Ausgabe einer 2
 
Readeeprom B , Label2
Print B 'Ausgabe: 10
Readeeprom B
Print B 'Ausgabe: 20
 
'Funktioniert auch beim Schreiben:
'aber weil es Überschneidungen mit dem Programm geben kann fügen wir hier ein Stop ein.
Input "Ready?" , Yes
B = 100
Writeeeprom B , Label1
B = 101
Writeeeprom B
 
'read it back
Readeeprom B , Label1
Print B 'Ausgabe: 100
'Nachfolgende Reads nächsten den nächsten Wert
'Beim ersten Mal muss das Label angegeben werden damit die Startadresse bekannt ist.
Readeeprom B
Print B 'Ausgabe: 101
End

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language