ON VALUE/de

From MCS Wiki AVR
< ON VALUE(Difference between revisions)
Jump to: navigation, search
((**COPIED FROM ENGLISH PAGE**) =)
(Beispiel)
 
(5 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="515" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;"
 
{| width="515" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;"
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
 
| valign="top" width="21%" style="width: 105px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="21%" style="width: 105px; border: 1px solid rgb(0, 0, 0);" |  
Var
+
var
  
 
| valign="top" width="98%" style="width: 401px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="98%" style="width: 401px; border: 1px solid rgb(0, 0, 0);" |  
The numeric variable to test.
+
Die zu prüfende numerische Variable.
  
This can also be a SFR such as PORTB.
+
Kann auch ein SFR wie zum Beispiel PORTB sein.
  
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
Line 32: Line 32:
  
 
| valign="top" width="98%" style="width: 401px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="98%" style="width: 401px; border: 1px solid rgb(0, 0, 0);" |  
The labels to jump to depending on the value of var.
+
Label (Sprungmarken) zu denen je nach Wert der Variablen gesprungen werden soll.
  
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
Line 39: Line 39:
  
 
| valign="top" width="98%" style="width: 401px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="98%" style="width: 401px; border: 1px solid rgb(0, 0, 0);" |  
An optional check for the number of provided labels.
+
Optionale Prüfung der Anzahl der Sprungmarken.
  
 
|}
 
|}
Line 45: Line 45:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
Note that the value is zero based. So when var is 0, the first specified label is jumped/branched.
+
Die Verzweigung erfolg nullbasiert. Wenn der Wert also Null ist dann wird zur ersten angegebenen Sprungmarke verzweigt.
  
It is important that each possible value has an associated label.
+
Es ist wichtig, dass es zu jedem möglichen Wert eine zugehörige Sprungmarke gibt.
  
When there are not enough labels, the stack will get corrupted. For example&nbsp;:
+
Wenn nicht genügend Sprungmarken vorhanden sind dann läuft der Stack über.
 +
Beispiel:
  
 
ON value label1, label2
 
ON value label1, label2
Line 55: Line 56:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
And value = 2, there is no associated label.
+
Wenn value = 2 dann gibt es keine zugehörige Sprungmarke.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
You can use the optional CHECK so the compiler will check the value against the number of provided labels. When there are not enough labels for the value, there will be no GOTO or GOSUB and the next line will be executed.
+
Wenn man den optionalen CHECK Parameter benutzt dann wird geprüft ob genügend viele Sprungmarken vorhanden sind und wenn das nicht der Fall ist dann wird kein GOTO oder GOSUB ausgeführt sondern die nächste Zeile wird ausgeführt.
 +
 
  
 
<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> =
  
 
[[ON INTERRUPT|ON INTERRUPT]]
 
[[ON INTERRUPT|ON INTERRUPT]]
Line 71: Line 73:
 
<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> =
  
 
The following code will be generated for a non-MEGA micro with ON value GOTO.
 
The following code will be generated for a non-MEGA micro with ON value GOTO.
Line 167: Line 169:
 
<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 179: Line 181:
 
'-----------------------------------------------------------------------------------------
 
'-----------------------------------------------------------------------------------------
 
   
 
   
$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
Line 187: Line 189:
 
   
 
   
 
Dim A As Byte
 
Dim A As Byte
Input "Enter value 0-2 " , A 'ask for input
+
Input "Enter value 0-2 " , A 'Nach Eingabe fragen
Rem Note That The Starting Value Begins With 0
+
Rem Zu beachten: Der Startwert beginnt mit Null
 
On A Gosub L0 , L1 , L2
 
On A Gosub L0 , L1 , L2
Print "Returned"
+
Print "Zurück aus GOSUB"
 
   
 
   
If Portb < 2 Then 'you can also use the portvalue
+
If Portb < 2 Then 'Man kann auch den Port-Wert benutzen
 
On Portb Goto G0 , G1
 
On Portb Goto G0 , G1
 
End If
 
End If
Line 200: Line 202:
 
   
 
   
 
L0:
 
L0:
Print "0 entered"
+
Print "0 eingegeben"
 
Return
 
Return
 
   
 
   
 
L1:
 
L1:
Print "1 entered"
+
Print "1 eingegeben"
 
Return
 
Return
 
   
 
   
 
L2:
 
L2:
Print "2 entered"
+
Print "2 eingegeben"
 
Return
 
Return
 
   
 
   

Latest revision as of 22:58, 17 March 2013

Contents

Funktion

Verzweigung zu einem von mehreren angegebenen Labels in Abhängigkeit des Wertes einer Variablen.

 

 

Syntax

ON var [GOTO] [GOSUB] label1 [, label2 ] [,CHECK]

 

 

Anmerkungen

var

Die zu prüfende numerische Variable.

Kann auch ein SFR wie zum Beispiel PORTB sein.

label1, label2

Label (Sprungmarken) zu denen je nach Wert der Variablen gesprungen werden soll.

CHECK

Optionale Prüfung der Anzahl der Sprungmarken.

 

Die Verzweigung erfolg nullbasiert. Wenn der Wert also Null ist dann wird zur ersten angegebenen Sprungmarke verzweigt.

Es ist wichtig, dass es zu jedem möglichen Wert eine zugehörige Sprungmarke gibt.

Wenn nicht genügend Sprungmarken vorhanden sind dann läuft der Stack über. Beispiel:

ON value label1, label2

 

Wenn value = 2 dann gibt es keine zugehörige Sprungmarke.

 

Wenn man den optionalen CHECK Parameter benutzt dann wird geprüft ob genügend viele Sprungmarken vorhanden sind und wenn das nicht der Fall ist dann wird kein GOTO oder GOSUB ausgeführt sondern die nächste Zeile wird ausgeführt.


 

Siehe auch

ON INTERRUPT

 

 

Assembler

The following code will be generated for a non-MEGA micro with ON value GOTO.

Ldi R26,$60       ; load address of variable

Ldi R27,$00 ; load constant in register

Ld R24,X

Clr R25

 

Ldi R30, Low(ON_1_ * 1)     ; load Z with address of the label

Ldi R31, High(ON_1_ * 1)

 

Add zl,r24       ; add value to Z

Adc zh,r25

 

Ijmp        ; jump to address stored in Z

 

ON_1_:

 

Rjmp lbl1       ; jump table

Rjmp lbl2

Rjmp lbl3

 

 

The following code will be generated for a non-MEGA micro with ON value GOSUB.

 

;##### On X Gosub L1 , L2

Ldi R30,Low(ON_1_EXIT * 1)

Ldi R31,High(ON_1_EXIT * 1)

Push R30 ;push return address

Push R31

Ldi R30,Low(ON_1_ * 1)      ;load table address

Ldi R31,High(ON_1_ * 1)

Ldi R26,$60

Ld R24,X

Clr R25

 

Add zl,r24 ; add to address of jump table

Adc zh,r25

Ijmp        ; jump !!!

 

ON_1_:

Rjmp L1

Rjmp L2

ON_1_EXIT:

 

 

As you can see a jump is used to call the routine. Therefore the return address is first saved on the stack.

 

 

Beispiel


'-----------------------------------------------------------------------------------------
'name : ongosub.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demo : ON .. GOSUB/GOTO
'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
 
Dim A As Byte
Input "Enter value 0-2 " , A 'Nach Eingabe fragen
Rem Zu beachten: Der Startwert beginnt mit Null
On A Gosub L0 , L1 , L2
Print "Zurück aus GOSUB"
 
If Portb < 2 Then 'Man kann auch den Port-Wert benutzen
On Portb Goto G0 , G1
End If
End_prog:
End
 
 
L0:
Print "0 eingegeben"
Return
 
L1:
Print "1 eingegeben"
Return
 
L2:
Print "2 eingegeben"
Return
 
G0:
Print "P1 = 0"
Goto End_prog
 
G1:
Print "P1 = 1"
Goto End_prog

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