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

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

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

Добавлен: 12.06.2025

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

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

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

© MCS Electronics, 1995-2007

strings must be passed by the compiler

'the empty () indicated that an array will be passed

Declare Sub Teststr(b As Byte , Dl() As String)

Dim Bb As Byte , I As Integer , W As Word , L As Long , S As String * 10

'dim used variables

Dim Ar(10) As Byte

'strng array

Dim Sar(10) As String * 8

For Bb = 1 To 10

'fill the array

Sar(bb) = Str(bb)

Next

Bb = 1

'now call the sub and notice that we always must pass the first address with index 1

Call Teststr(bb , Sar(1))

Call Test2

'call sub

Test2

'or use without

CALL

'Note that when calling a sub without the statement CALL, the enclosing

parentheses must be left out

Bb = 1

'call sub with

Call Test(1 , Bb)

parameters

'print value that

Print Bb

is changed

'now test all the variable types

Call Testvar(bb , I , W , L , S )

Print Bb ; I ; W ; L ; S

'now pass an array

'note that it must be passed by reference

Testarray 2 , Ar(1)

Print "ar(1) = " ; Ar(1)

Print "ar(3) = " ; Ar(3)

$notypecheck

' turn off type

checking

Testvar Bb , I , I , I , S

'you can turn off type checking when you want to pass a block of memory

$typecheck

'turn it back on

End

'End your code with the subprograms

'Note that the same variables and names must be used as the declared ones

Sub Test(byval A As Byte , B1 As Byte)

'start sub

Print A ; " " ; B1

'print passed

variables

'change value

B1 = 3

'You can change A, but since a copy is passed to the SUB,

'the change will not reflect to the calling variable

End Sub

Sub Test2

'sub without

parameters

Print "No parameters"

End Sub

Sub Testvar(b As Byte , I As Integer , W As Word , L As Long , S As String)

page -451-


© MCS Electronics, 1995-2007

Local X As Byte

X

=

5

'assign local

B

=

X

I

=

-1

W

=

40000

L

=

20000

S = "test"

End Sub

Sub Testarray(byval A As Byte , B1 As Byte)

'start sub

Print A ; " " ; B1

'print passed

variables

'change value of

B1 = 3

element with index 1

'specify the index

B1(1) = 3

which does the same as the line above

'modify other

B1(3) = 3

element of array

'You can change A, but since a copy is passed to the SUB, 'the change will not reflect to the calling variable

End Sub

'notice the empty() to indicate that a string array is passed

Sub Teststr(b As Byte , Dl() As String) Dl(b) = Dl(b) + "add"

End Sub

DEFxxx

Action

Declares all variables that are not dimensioned of the DefXXX type.

Syntax

DEFBIT b

Define BIT

DEFBYTE c

Define BYTE

DEFINT I

Define INTEGER

DEFWORD x

Define WORD

DEFLNG l

Define LONG

DEFSNG s

Define SINGLE

DEFDBL z

Define DOUBLE

Remarks

While you can DIM each individual variable you use, you can also let the compiler handle it for you.

All variables that start with a certain letter will then be dimmed as the specified type.

Example

Defbit b : DefInt c 'default type for bit and integers

Set b1

'set bit to 1

page -452-


© MCS Electronics, 1995-2007

c = 10

'let c = 10

DEFLCDCHAR

Action

Define a custom LCD character.

Syntax

DEFLCDCHAR char,r1,r2,r3,r4,r5,r6,r7,r8

Remarks

char

Constant representing the character (0-7).

r1-r8

The row values for the character.

You can use the LCD designer to build the characters.

It is important that a CLS follows the DEFLCDCHAR statement(s).

So make sure you use the DEFLCDCHAR before your CLS statement.

Special characters can be printed with the Chr() function.

LCD Text displays have a 64 byte memory that can be used to show your own custom characters. Each character uses 8 bytes as the character is an array from8x8 pixels. You can create a maximum of 8 characters this way. Or better said : you can show a maximum of 8 custom characters at the same time. You can redefine characters in your programbut with the previous mentioned restriction.

A custom character can be used to show characters that are not available in the LCDfont table. For example a Û.

You can also use custom characters to create a bar graph or a music note.

See also

Tools LCD designer

Partial Example

Deflcdchar 1 , 225 , 227 , 226 , 226 , 226 , 242 , 234 , 228

' replace ?

with number (0-7)

' replace ?

Deflcdchar 0 , 240 , 224 , 224 , 255 , 254 , 252 , 248 , 240

with number (0-7)

'select data RAM

Cls

Rem it is important that a CLS is following the deflcdchar statements because

it will set the controller back in datamode

'print the special

Lcd Chr(0) ; Chr(1)

character

DEG2RAD

Action

Converts an angle in to radians.

page -453-


© MCS Electronics, 1995-2007

Syntax

var = DEG2RAD( Source )

Remarks

Var

A numeric variable that is assigned with the degrees of variable

Source.

Source

The single or double variable to get the degrees of.

All trig functions work with radians. Use deg2rad and rad2deg to convert between radians and angles.

See Also

RAD2DEG

Example

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

--

: (c) 1995-2005, MCS Electronics

'copyright

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

'purpose

: demonstrates DEG2RAD function

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

--

Dim S As Single

S = 90

S = Deg2Rad(s)

Print S

S = Rad2deg(s)

Print S

End

DELAY

Action

Delay program execution for a short time.

Syntax

DELAY

Remarks

Use DELAY to wait for a short time.

The delay time is ca. 1000 microseconds.

Interrupts that occur frequently and/or take a long time to process, will let the delay

page -454-