ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 12.06.2025

Просмотров: 8338

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

© MCS Electronics, 1995-2007

Restore Dta4

'long type

Read L : Print L

'demonstration of readlabel

' location is used

Dim W As Iram Word At 8 Overlay

by restore pointer

'note that W does not use any RAM it is an overlayed pointer to the data

pointer

' loadlabel

W = Loadlabel(dta1)

expects the labelname

Read B1

Print B1

End

Dta1:

Data &B10 , &HFF , 10

Dta2:

Data 1000% , -1%

Dta3:

Data "Hello" , "World"

'Note that integer values (>255 or <0) must end with the %-sign 'also note that the data type must match the variable type that is 'used for the READ statement

Dta4:

Data 123456789&

'Note that LONG values must end with the &-sign

'Also note that the data type must match the variable type that is used 'for the READ statement

RETURN

Action

Return from a subroutine.

Syntax

RETURN

Remarks

Subroutines must be ended with a related RETURN statement.

Interrupt subroutines must also be terminated with the Return statement.

See also

GOSUB

Example

'-----------------------------------------------------------------------------

------------

: gosub.bas

'name

page -616-


© MCS Electronics, 1995-2007

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo: GOTO, GOSUB and RETURN

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

'-----------------------------------------------------------------------------

------------

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 4000000

frequency

' use baud rate

$baud = 19200

$hwstack = 32

' default use 32

for the hardware stack

' default use 10

$swstack = 10

for the SW stack

' default use 40

$framesize = 40

for the frame space

Goto Continue

Print "This code will not be executed"

Continue:

'end a label with

a colon

Print "We will start execution here"

Gosub Routine

Print "Back from Routine"

End

Routine:

'start a

subroutine

Print "This will be executed"

'return from

Return

subroutine

RIGHT

Action

Return a specified number of rightmost characters in a string.

Syntax

var = RIGHT(var1 ,n )

Remarks

var

The string that is assigned.

Var1

The source string.

st

The number of bytes to copy from the right of the string.

See also

LEFT , MID

page -617-


© MCS Electronics, 1995-2007

Example

Dim S As String * 15 , Z As String * 15

S ="ABCDEFG"

Z = Left(s , 5)

'ABCDE

Print Z

Z = Right(s , 3) : Print Z

Z = Mid(s , 2 , 3) : Print Z

End

RND

Action

Returns a random number.

Syntax

var = RND( limit )

Remarks

Limit

Word that limits the returned random number.

Var

The variable that is assigned with the random number.

The RND() function returns an Integer/Word and needs an internal storage of 2 bytes. (___RSEED). Each new call to Rnd() will give a new positive randomnumber.

Notice that it is a software based generated number. And each time you will restart your program the same sequence will be created.

You can use a different SEED value by dimensioning and assigning ___RSEED yourself: Dim ___rseed as word : ___rseed = 10234

Dim I as word : I = rnd(10)

When your application uses a timer you can assign ___RSEED with the timer value. This wil give a better random number.

See also

NONE

Example

'-----------------------------------------------------------------------------

------------

: rnd.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo : RND() function

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

'-----------------------------------------------------------------------------

------------

page -618-


© MCS Electronics, 1995-2007

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 4000000

frequency

' use baud rate

$baud = 19200

$hwstack = 32

' default use 32

for the hardware stack

' default use 10

$swstack = 10

for the SW stack

' default use 40

$framesize = 40

for the frame space

Dim I As Word

' dim variable

Do

'get random number

I = Rnd(40)

(0-39)

'print the value

Print I

Wait 1

'wait 1 second

Loop

'for ever

End

ROTATE

Action

Rotate all bits one place to the left or right.

Syntax

ROTATE var , LEFT/RIGHT[ , shifts]

Remarks

Var

Byte, Integer/Word or Long variable.

Shifts

The number of shifts to perform.

The ROTATE statement rotates all the bits in the variable to the left or right. All bits are preserved so no bits will be shifted out of the variable.

This means that after rotating a byte variable with a value of 1, eight times the variable will be unchanged.

When you want to shift out the MS bit or LS bit, use the SHIFT statement.

See also

SHIFT , SHIFTIN , SHIFTOUT

Example

'-----------------------------------------------------------------------------

------------

: rotate.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: example for ROTATE and SHIFT statement

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

'-----------------------------------------------------------------------------

page -619-