WRITEEEPROM/de

From MCS Wiki AVR
< WRITEEEPROM(Difference between revisions)
Jump to: navigation, search
((**COPIED FROM ENGLISH PAGE**) =)
(Beispiel)
 
(4 intermediate revisions by one user not shown)
Line 15: Line 15:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
= <span class="f_Header">Remarks</span> =
+
= <span class="f_Header">Anmerkungen</span> =
 
<div style="padding: 0px; margin: 0px 0px 0px 4px;">
 
<div style="padding: 0px; margin: 0px 0px 0px 4px;">
 
{| width="604" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;"
 
{| width="604" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;"
Line 23: Line 23:
  
 
| valign="top" width="100%" style="width: 514px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 514px; border: 1px solid rgb(0, 0, 0);" |  
The name of the variable that must be stored
+
Name der Variablen die gespeichert werden soll.
  
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
Line 30: Line 30:
  
 
| valign="top" width="100%" style="width: 514px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 514px; border: 1px solid rgb(0, 0, 0);" |  
The address in the EEPROM where the variable must be stored.
+
EEPROM-Adresse an der die Variable gespeichert werden soll.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
A new option is that you can provide a label name for the address. See example 2.
+
Eine neue Option ist, dass man einen Label-Namen als Adresse verwenden kann. Siehe Beispiel 2.
  
 
|}
 
|}
Line 40: Line 40:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
This statement is provided for compatibility with BASCOM-8051.
+
Diesen Befehl gibt es aus Kompatibilitätsgründen mit BASCOM-8051.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
You can also use&nbsp;:
+
Man kann auch schreiben&nbsp;:
  
Dim V as Eram Byte &nbsp;'store in EEPROM
+
Dim V as Eram Byte &nbsp;'Im EEPROM speichern
  
Dim B As Byte &nbsp;'normal variable
+
Dim B As Byte &nbsp;'normale Variable
  
 
B = 10
 
B = 10
  
V = B &nbsp; &nbsp;'store variable in EEPROM
+
V = B &nbsp; &nbsp;'Variable im EEPROM speichern
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
When you use the assignment version, the data types must be the same!
+
Wenn man die Zuweisungs-Version benutzt dann müssen die Datentypen gleich sein!
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
According to a data sheet from ATMEL, the first location in the EEPROM with address 0, can be overwritten during a reset. It is advised not to use this location.
+
Laut ATMEL-Datenblatt kann die erste EEPROM-Speicherzelle mit der Adresse 0 bei einem Reset überschrieben werden. Es wird deshalb empfohlen, diese Adresse NICHT zu benutzen.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
For security, register R23 is set to a magic value before the data is written to the EEPROM.
+
Aus Sicherheitgründen wird Register R23 auf einen 'magic value' gesetzt bevor Daten in den EEPROM-Speicher geschrieben werden.
  
All interrupts are disabled while the EEPROM data is written. Interrupts are enabled automatic when the data is written.
+
Alle Interrupts werden disabled während in den EEPROM-Speicher geschrieben wird. Interrupts werden automatisch wieder enabled wenn die Daten geschrieben sind.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
It is advised to use the Brownout circuit that is available on most AVR processors. This will prevent that data is written to the EEPROM when the voltage drops under the specified level.
+
Es ist ratsam, die Brownout-Einheit zu verwenden, die es bei den meistens AVR-Mikrocontrollern gibt. Dadurch wird verhindert, dass Daten in den EEPROM-Speicher geschrieben werden obwohl die Spannung unter den angegebenen Wert sinkt.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
 
When data is written to the EEPROM, all interrupts are disabled, and after the EEPROM has been written, the interrupts are re-enabled.
 
  
 
&nbsp;
 
&nbsp;
  
In the XMEGA, you need to set the mode to mapped&nbsp;:&nbsp;[[CONFIG EEPROM|CONFIG EEPROM]]&nbsp;= MAPPED.
+
Beim XMEGA muss man den Mode auf mapped setzen&nbsp;:&nbsp;[[CONFIG EEPROM|CONFIG EEPROM]]&nbsp;= MAPPED.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
Line 84: Line 82:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
= <span class="f_Header">See also</span> =
+
= <span class="f_Header">Siehe auch</span> =
  
 
[[READEEPROM]]
 
[[READEEPROM]]
Line 92: Line 90:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
= <span class="f_Header">ASM</span> =
+
= <span class="f_Header">Assembler</span> =
  
 
NONE
 
NONE
Line 100: Line 98:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
= <span class="f_Header">Example</span> =
+
= <span class="f_Header">Beispiel</span> =
  
 
<br/><source lang="bascomavr">
 
<br/><source lang="bascomavr">
Line 112: Line 110:
 
'-----------------------------------------------------------------------------------------
 
'-----------------------------------------------------------------------------------------
 
   
 
   
$regfile = "m48def.dat" ' specify the used micro
+
$regfile = "m48def.dat" ' Mikrocontroller
$crystal = 4000000 ' used crystal frequency
+
$crystal = 4000000 ' Taktfrequenz
$baud = 19200 ' use baud rate
+
$baud = 19200 ' BAudrate
 
$hwstack = 32 ' default use 32 for the hardware stack
 
$hwstack = 32 ' default use 32 for the hardware stack
 
$swstack = 10 ' default use 10 for the SW stack
 
$swstack = 10 ' default use 10 for the SW stack
 
$framesize = 40 ' default use 40 for the frame space
 
$framesize = 40 ' default use 40 for the frame space
 
   
 
   
'first dimension a variable
+
'Zunächst einmal Variablen dimensionieren:
 
Dim B As Byte
 
Dim B As Byte
 
Dim Yes As String * 1
 
Dim Yes As String * 1
 
   
 
   
'Usage for readeeprom and writeeprom :
+
'Benutzung von readeeprom und writeeprom :
 
'readeeprom var, address
 
'readeeprom var, address
 
   
 
   
'A new option is to use a label for the address of the data
+
'Eine neue Option ist, ein Label für die Adresse zu benutzen.
'Since this data is in an external file and not in the code the eeprom data
+
'Da die Daten in einer externen Datei sind und nicht im Programm sollten die EEPROM Daten
'should be specified first. This in contrast with the normal DATA lines which must
+
'als erstes spezifiziert werden. Dies steht im Gegensatz zu den normalen DATA Zeilen welche
'be placed at the end of your program!!
+
'am Endes des Programms spezifiziert werden!!
 
   
 
   
'first tell the compiler that we are using EEPROM to store the DATA
+
'Zunächst dem Compiler mitteilen, dass wir das EEPROM nutzen wollen um die Daten zu speichern:
 
$eeprom
 
$eeprom
 
   
 
   
'the generated EEP file is a binary file.
+
'Die erzeugte EEP-Datei ist eine Binär-Datei.
'Use $EEPROMHEX to create an Intel Hex file usable with AVR Studio.
+
'Benutzen Sie $EEPROMHEX um eine Intel Hex-Datei für die Benutzung mit AVR Studio zu erzeugen.
 
'$eepromhex
 
'$eepromhex
 
   
 
   
'specify a label
+
'Label festlegen:
 
Label1:
 
Label1:
 
Data 1 , 2 , 3 , 4 , 5
 
Data 1 , 2 , 3 , 4 , 5
Line 144: Line 142:
 
Data 10 , 20 , 30 , 40 , 50
 
Data 10 , 20 , 30 , 40 , 50
 
   
 
   
'Switch back to normal data lines in case they are used
+
'Zurückschalten zu normalen DATA-Zeilen für den Fall, dass solche verwendet werden:
 
$data
 
$data
 
   
 
   
'All the code above does not generate real object code
+
'Der Code oben erzeugt keinen richtigen Object-Code.does not generate real object code
'It only creates a file with the EEP extension
+
 
   
 
   
'Use the new label option
+
'Benutzung der neuen Label Option
 
Readeeprom B , Label1
 
Readeeprom B , Label1
Print B 'prints 1
+
Print B 'Ausgabe einer 1
'Succesive reads will read the next value
+
'Nachfolgende Reads lesen die nächsten Werte
'But the first time the label must be specified so the start is known
+
'Beim ersten Mal muss das Label angegeben werden damit die Startadresse bekannt ist.
 
Readeeprom B
 
Readeeprom B
Print B 'prints 2
+
Print B 'Ausgabe einer 2
 
   
 
   
 
Readeeprom B , Label2
 
Readeeprom B , Label2
Print B 'prints 10
+
Print B 'Ausgabe: 10
 
Readeeprom B
 
Readeeprom B
Print B 'prints 20
+
Print B 'Ausgabe: 20
 
   
 
   
'And it works for writing too :
+
'Funktioniert auch beim Schreiben:
'but since the programming can interfere we add a stop here
+
'aber weil es Überschneidungen mit dem Programm geben kann fügen wir hier ein Stop ein.
 
Input "Ready?" , Yes
 
Input "Ready?" , Yes
 
B = 100
 
B = 100
Line 173: Line 170:
 
'read it back
 
'read it back
 
Readeeprom B , Label1
 
Readeeprom B , Label1
Print B 'prints 100
+
Print B 'Ausgabe: 100
'Succesive reads will read the next value
+
'Nachfolgende Reads nächsten den nächsten Wert
'But the first time the label must be specified so the start is known
+
'Beim ersten Mal muss das Label angegeben werden damit die Startadresse bekannt ist.
 
Readeeprom B
 
Readeeprom B
Print B 'prints 101
+
Print B 'Ausgabe: 101
 
End
 
End
 
   
 
   

Latest revision as of 01:18, 9 March 2013

Contents

Funktion

Schreibt den Variableninhalt in den EEPROM-Speicher.

 

 

Syntax

WRITEEEPROM var , address

 

 

Anmerkungen

var

Name der Variablen die gespeichert werden soll.

address

EEPROM-Adresse an der die Variable gespeichert werden soll.

 

Eine neue Option ist, dass man einen Label-Namen als Adresse verwenden kann. Siehe Beispiel 2.

 

Diesen Befehl gibt es aus Kompatibilitätsgründen mit BASCOM-8051.

 

Man kann auch schreiben :

Dim V as Eram Byte  'Im EEPROM speichern

Dim B As Byte  'normale Variable

B = 10

V = B    'Variable im EEPROM speichern

 

Wenn man die Zuweisungs-Version benutzt dann müssen die Datentypen gleich sein!

 

Laut ATMEL-Datenblatt kann die erste EEPROM-Speicherzelle mit der Adresse 0 bei einem Reset überschrieben werden. Es wird deshalb empfohlen, diese Adresse NICHT zu benutzen.

 

Aus Sicherheitgründen wird Register R23 auf einen 'magic value' gesetzt bevor Daten in den EEPROM-Speicher geschrieben werden.

Alle Interrupts werden disabled während in den EEPROM-Speicher geschrieben wird. Interrupts werden automatisch wieder enabled wenn die Daten geschrieben sind.

 

Es ist ratsam, die Brownout-Einheit zu verwenden, die es bei den meistens AVR-Mikrocontrollern gibt. Dadurch wird verhindert, dass Daten in den EEPROM-Speicher geschrieben werden obwohl die Spannung unter den angegebenen Wert sinkt.

 

 

Beim XMEGA muss man den Mode auf mapped setzen : CONFIG EEPROM = MAPPED.

 

 

Siehe auch

READEEPROM

 

 

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