CONST/de

From MCS Wiki AVR
< CONST(Difference between revisions)
Jump to: navigation, search
((**COPIED FROM ENGLISH PAGE**) =)
(Beispiel)
 
(4 intermediate revisions by one user not shown)
Line 19: Line 19:
 
<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="567" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;"
 
{| width="567" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;"
Line 27: Line 27:
  
 
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" |  
The name of the symbol.
+
Der Name der Konstanten.
  
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
Line 34: Line 34:
  
 
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" |  
The numeric value to assign to the symbol.
+
Numerischer Wert für die Konstante.
  
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
Line 41: Line 41:
  
 
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" |  
The string to assign to the symbol
+
Zeichenketten-Wert für die Konstante.
  
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
Line 48: Line 48:
  
 
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" |  
An expression that returns a value to assign the constant
+
Ein Ausdruck (expression) der einen Wert für die Konstante ergibt.
  
 
|}
 
|}
Line 54: Line 54:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
Assigned constants consume no program memory because they only serve as a reference to the compiler.
+
Konstanten benötigen keinen Programmspeicher weil sie nur als Referenz beim Kompilieren dienen.
  
The compiler will replace all occurrences of the symbol with the assigned value.
+
Der Compiler ersetzt jedes Auftreten der Konstanten durch den entsprechenden Wert.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
You can use a constant to give a value a more meaningful name.
+
Man kann eine Konstante verwenden um einem Wert einen sinnvollen Namen zu geben.
  
For example&nbsp;: variable = 1
+
Beispiel: Zustand = 1
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const optHeaterOn = 1
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const HeizungAn = 1
  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;variable = optHeaterOn
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Zustand = HeizungAn
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
The source code is better to read when you assign a constant. Even better when the values change later, for example when HeaterOn becomes 2, you only need to replace 1 line of code.
+
Der Programmcode ist besser zu lesen wenn Konstanten verwendet werden.  
 +
 
 +
Darüberhinaus muss nur eine Zeile Programmcode geändert werden wenn später zum Beispiel HeizungAn 2 sein soll.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
Line 78: Line 80:
 
<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> =
  
 
[[ALIAS]]
 
[[ALIAS]]
Line 86: Line 88:
 
<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 99: Line 101:
 
   
 
   
 
$regfile = "m48def.dat" ' specify the used micro
 
$regfile = "m48def.dat" ' specify the used micro
$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
 
   
 
   
'dimension some variables
+
'Einige Variablen DIMensionieren
 
Dim Z As String * 10
 
Dim Z As String * 10
 
Dim B As Byte
 
Dim B As Byte
 
   
 
   
'assign some constants
+
'Einige Konstanten definieren
'constants dont use program memory
+
'Konstanten benötigen keinen Programmspeicher
 
Const S = "test"
 
Const S = "test"
Const A = 5 'declare a as a constant
+
Const A = 5 'A als Konstante mit dem Wert 5 deklarieren
 
Const B1 = &B1001
 
Const B1 = &B1001
 
   
 
   
'or use an expression to assign a constant
+
'Ausdrücke an Konstante zuweisen
 
Const X =(b1 * 3) + 2
 
Const X =(b1 * 3) + 2
 
Const Ssingle = Sin(1)
 
Const Ssingle = Sin(1)
Line 125: Line 127:
 
   
 
   
 
B = A
 
B = A
'the same as b = 5
+
'Das Gleiche wie B = 5
 
   
 
   
 
Z = S
 
Z = S
'the same as Z = "test"
+
'Das Gleiche wie Z = "test"
 
   
 
   
 
Print A
 
Print A
Line 135: Line 137:
 
   
 
   
 
   
 
   
'you can use constants with conditional compilation
+
'Man kann Konstante bei bedingter Kompilation verwenden
#if A = 5 ' note there is no then
+
#if A = 5 ' Beachte: Es gibt kein THEN
 
Print "constant a is 5"
 
Print "constant a is 5"
 
#if S = "test"
 
#if S = "test"
  Print "nested example"
+
  Print "verschachteltes Beispiel"
#else ' else is optional
+
#else ' ELSE ist optional
 
#endif
 
#endif
 
#else
 
#else

Latest revision as of 01:54, 27 February 2013

Contents

Funktion

Definiert eine symbolische Konstante.

 

 

Syntax

CONST symbol = numconst

CONST symbol = stringconst

CONST symbol = expression

 

 

Anmerkungen

Symbol

Der Name der Konstanten.

Numconst

Numerischer Wert für die Konstante.

Stringconst

Zeichenketten-Wert für die Konstante.

Expression

Ein Ausdruck (expression) der einen Wert für die Konstante ergibt.

 

Konstanten benötigen keinen Programmspeicher weil sie nur als Referenz beim Kompilieren dienen.

Der Compiler ersetzt jedes Auftreten der Konstanten durch den entsprechenden Wert.

 

Man kann eine Konstante verwenden um einem Wert einen sinnvollen Namen zu geben.

Beispiel: Zustand = 1

 

                 const HeizungAn = 1

                 Zustand = HeizungAn

 

Der Programmcode ist besser zu lesen wenn Konstanten verwendet werden.

Darüberhinaus muss nur eine Zeile Programmcode geändert werden wenn später zum Beispiel HeizungAn 2 sein soll.

 

 

Siehe auch

ALIAS

 

 

Beispiel


'-----------------------------------------------------------------------------------------
'name : const.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demo for constants
'micro : Mega48
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
 
$regfile = "m48def.dat" ' specify the used micro
$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
 
'Einige Variablen DIMensionieren
Dim Z As String * 10
Dim B As Byte
 
'Einige Konstanten definieren
'Konstanten benötigen keinen Programmspeicher
Const S = "test"
Const A = 5 'A als Konstante mit dem Wert 5 deklarieren
Const B1 = &B1001
 
'Ausdrücke an Konstante zuweisen
Const X =(b1 * 3) + 2
Const Ssingle = Sin(1)
 
 
Print X
Print Ssingle
 
 
B = A
'Das Gleiche wie B = 5
 
Z = S
'Das Gleiche wie Z = "test"
 
Print A
Print B1
Print S
 
 
'Man kann Konstante bei bedingter Kompilation verwenden
#if A = 5 ' Beachte: Es gibt kein THEN
Print "constant a is 5"
#if S = "test"
 Print "verschachteltes Beispiel"
#else ' ELSE ist optional
#endif
#else
#endif
End

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