DATA/de

(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
K (1 revision)
(Example)
Zeile 163: Zeile 163:
 
<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">
Zeile 175: Zeile 175:
 
'-----------------------------------------------------------------------------------------
 
'-----------------------------------------------------------------------------------------
 
   
 
   
$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
Zeile 185: Zeile 185:
 
Dim S As String * 15
 
Dim S As String * 15
 
Dim L As Long
 
Dim L As Long
Restore Dta1 'point to stored data
+
Restore Dta1 'Zeiger auf gespeicherte Daten setzen
For Count = 1 To 3 'for number of data items
+
For Count = 1 To 3 'Für jedes Datenelement
 
Read B1 : Print Count ; " " ; B1
 
Read B1 : Print Count ; " " ; B1
 
Next
 
Next
 
   
 
   
Restore Dta2 'point to stored data
+
Restore Dta2 'Zeiger aud Datentabelle setzen
For Count = 1 To 2 'for number of data items
+
For Count = 1 To 2 'Für jedes Datenelement
 
Read A : Print Count ; " " ; A
 
Read A : Print Count ; " " ; A
 
Next
 
Next
Zeile 220: Zeile 220:
 
Dta3:
 
Dta3:
 
Data "Hello" , "World"
 
Data "Hello" , "World"
'Note that integer values (>255 or <0) must end with the %-sign
+
'Zu beachten: Integer-Werte (>255 or <0) müssen mit einem %-Zeichen enden.
'also note that the data type must match the variable type that is
+
'Auch zu beachten: Der Datentyp muss dem Datentyp der Variablen im READ-Befehl entsprechen.
'used for the READ statement
+
 
   
 
   
 
Dta4:
 
Dta4:
 
Data 123456789&
 
Data 123456789&
'Note that LONG values must end with the &-sign
+
'Zu beachten: LONG-Werte müssen mit einem &-Zeichen enden.
'Also note that the data type must match the variable type that is used
+
'Auch zu beachten: Der Datentyp muss dem Datentyp der Variablen im READ-Befehl entsprechen.
'for the READ statement
+
 
</source><br/>{{Languages}}
 
</source><br/>{{Languages}}
  
 
[[Category:BASCOM Language Reference/de]]
 
[[Category:BASCOM Language Reference/de]]

Version vom 5. März 2013, 23:47 Uhr

Inhaltsverzeichnis

= (**COPIED FROM ENGLISH PAGE**) === Action

Specifies constant values to be read by subsequent READ statements.

 

 

Syntax

DATA var [, varn]

 

 

Remarks

Var

Numeric or string constant.

 

The DATA related statements use the internal registers pair R8 and R9 to store the data pointer.

 

To store a " sign on the data line, you can use :

DATA $34

 

The $-sign tells the compiler that the ASCII value will follow.

You can use this also to store special characters that can't be written by the editor such as chr(7)

 

Another way to include special ASCII characters in your string constant is to use {XXX}. You need to include exactly 3 digits representing the ASCII character. For example 65 is the ASCII number for the character A.

 

DATA "TEST{065}"

 

Will be read as TESTA.

 

 

While :

DATA "TEST{65}" will be read as :

 

TEST{65}. This because only 2 digits were included instead of 3.

 

{xxx} works only for string constants. It will also work in a normal string assignment :

 

s = "{065}" . This will assign A to the string s.

 

 

Because the DATA statements allow you to generate an EEP file to store in EEPROM, the $DATA and $EEPROM directives have been added. Read the description of these directives to learn more about the DATA statement.

 

The DATA statements must not be accessed by the flow of your program because the DATA statements are converted to the byte representation of the DATA.

 

When your program flow enters the DATA lines, unpredictable results will occur.

So as in QB, the DATA statement is best be placed at the end of your program or in a place that program flow will no enter.

 

For example this is fine:

 

Print "Hello"

Goto jump

DATA "test"

 

Jump:

'because we jump over the data lines there is no problem.

 

The following example will case some problems:

Dim S As String * 10

Print "Hello"

Restore lbl

Read S

 

DATA "test"

 

Print S

 

 

When the END statement is used it must be placed BEFORE the DATA lines.

 

 

 

Difference with QB

Integer and Word constants must end with the %-sign.

Long constants must end with the &-sign.

Single constants must end with the !-sign.

Double constants must end with the #-sign.

 

 

See also

READ , RESTORE , $DATA , $EEPROM , LOOKUPLOOKUPSTR , LOOKDOWN

 

 

Beispiel


'-----------------------------------------------------------------------------------------
'name : readdata.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demo : READ,RESTORE
'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 Integer , B1 As Byte , Count As Byte
Dim S As String * 15
Dim L As Long
Restore Dta1 'Zeiger auf gespeicherte Daten setzen
For Count = 1 To 3 'Für jedes Datenelement
Read B1 : Print Count ; " " ; B1
Next
 
Restore Dta2 'Zeiger aud Datentabelle setzen
For Count = 1 To 2 'Für jedes Datenelement
Read A : Print Count ; " " ; A
Next
 
Restore Dta3
Read S : Print S
Read S : Print S
 
 
Restore Dta4
Read L : Print L 'long type
 
 
'demonstration of readlabel
Dim W As Iram Word At 8 Overlay ' location is used by restore pointer
'note that W does not use any RAM it is an overlayed pointer to the data pointer
W = Loadlabel(dta1) ' loadlabel expects the labelname
Read B1
Print B1
End
 
 
Dta1:
Data &B10 , &HFF , 10
Dta2:
Data 1000% , -1%
 
Dta3:
Data "Hello" , "World"
'Zu beachten: Integer-Werte (>255 or <0) müssen mit einem %-Zeichen enden.
'Auch zu beachten: Der Datentyp muss dem Datentyp der Variablen im READ-Befehl entsprechen.
 
Dta4:
Data 123456789&
'Zu beachten: LONG-Werte müssen mit einem &-Zeichen enden.
'Auch zu beachten: Der Datentyp muss dem Datentyp der Variablen im READ-Befehl entsprechen.

Languages   English Deutsch  
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
In anderen Sprachen
Sprache