Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BASCOM AVR, help reference (2007).PDF
Скачиваний:
281
Добавлен:
12.08.2013
Размер:
17.02 Mб
Скачать

 

 

© MCS Electronics, 1995-2007

 

 

 

 

Input

X: Pointer to string with

 

Z: Pointer to Long-variable, which holds the start

 

filename

 

position of SRAM

 

r20/r21: Count of bytes to be

 

 

written

 

 

Output

r25: Errorcode

 

C-Flag: Set on Error

 

 

 

 

Example

' THIS IS A CODE FRAGMENT, it needs AVR-DOS in order to work

'now the good old bsave and bload

 

Dim Ar(100)as Byte , I Asbyte

 

For I = 1 To 100

' fill the array

Ar(i) = I

Next

 

Wait 2

 

W = Varptr(ar(1))

 

Bsave"josef.img", W , 100

 

For I = 1 To 100

' reset the array

Ar(i) = 0

Next

 

Bload "josef.img" , W

' Josef you are

amazing !

 

For I = 1 To 10

 

Print Ar(i) ; " ";

 

Next

 

Print

 

BUFSPACE

Action

Returns the amount of free space of a serial buffer.

Syntax

Var = BufSpace(n)

Remarks

Var

A word or integer variable that is assigned with the free buffer space.

N

A constant in the range from 0-3.

 

A value of 0 : output buffer first UART

 

A value of 1 : input buffer first UART

 

A value of 2

: output buffer second UART

 

A value of 3

: input buffer second UART

 

 

 

While serial buffers are great because you do not have to wait/blockthe processor, the buffer can become full when the micro has no time to empty the buffer. With the bufspace() function you can determine if there is still room in the buffer.

page -293-

© MCS Electronics, 1995-2007

See Also

CONFIG SERIAL , CLEAAR

Example

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

NONE

BYVAL

Action

Specifies that a variable will be passed by value.

Syntax

Sub Test(BYVAL var)

Remarks

Var Variable name

The default for passing variables to SUBS and FUNCTIONS, is by reference(BYREF). When you pass a variable by reference, the address is passed to the SUB or FUNCTION. When you pass a variable by Value, a temp variable is created on the frame and the address of the copy is passed.

When you pass by reference, changes to the variable will be made to the calling variable. When you pass by value, changes to the variable will be made to the copy so the original value will not be changed.

By default passing by reference is used.

Note that calling by reference will generate less code.

See also

CALL , DECLARE , SUB , FUNCTION

ASM

NONE

Example

Declare Sub Test(Byval X As Byte, Byref Y As Byte, Z As Byte)

CALL

Action

Call and execute a subroutine.

page -294-

© MCS Electronics, 1995-2007

Syntax

CALL Test [ (var1, var-n) ]

Remarks

Var1

Any BASCOM variable or constant.

Var-n

Any BASCOM variable or constant.

Test

Name of the subroutine. In this case Test.

 

 

You can call sub routines with or without passing parameters.

It is important that the SUB routine is DECLARED before you make the CALL to the subroutine. Of course the number of declared parameters must match the number of passed parameters.

It is also important that when you pass constants to a SUB routine, you must DECLARE these parameters with the BYVAL argument.

With the CALL statement, you can call a procedure or subroutine.

For example: Call Test2

The call statement enables you to implement your own statements.

You don't have to use the CALL statement:

Test2 will also call subroutine test2

When you don't supply the CALL statement, you must leave out the parenthesis. So Call Routine(x,y,z) must be written as Routine x,y,x

Unlike normal SUB programs called with the GOSUB statement, the CALL statement enables you to pass variables to a SUB routine that may be local to the SUB.

See also

DECLARE , SUB , EXIT , FUNCTION , LOCAL

Example

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 8000000

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

 

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits

= 8 , Clockpol = 0

 

Dim A As Byte , B As Byte

'dimension some

page -295-

© MCS Electronics, 1995-2007

variables

'declare the SUB

Declare Sub Test(b1 As Byte , Byval B2 As Byte)

program

'assign a value to

A = 65

variable A

 

Call Test(a , 5)'call test with parameter A and constant

'alternative call

Test A , 5

Print A

'now print the new

value

 

End

 

Sub Test(b1 As Byte , Byval B2 As Byte)

'use the same

variable names as 'the declared one

'print it

Print B1

Print Bcd(b2)

'reassign the

B1 = 10

variable

'reassign the

B2 = 15

variable

 

End Sub

 

One important thing to notice is that you can change b2 but that the change wil not be reflected to the calling program!

Variable A is changed however.

This is the difference between the BYVAL and BYREF argument in the DECLARE ration of the SUB program.

When you use BYVAL, this means that you will pass the argument by its value. A copy of the variable is made and passed to the SUB program. So the SUB program can use the value and modify it, but the change will not be reflected to the calling parameter. It would be impossible too when you pass a numeric constant for example.

If you do not specify BYVAL, BYREF will be used by default and you willpass the address of the variable. So when you reassign B1 in the above example, you are actually changing parameter A.

CHECKSUM

Action

Returns a checksum of a string.

Syntax

PRINT Checksum(var)

b = Checksum(var)

Remarks

Var

A string variable.

BA numeric variable that is assigned with the checksum.

page -296-

© MCS Electronics, 1995-2007

The checksum is computed by counting all the bytes of the string variable. Checksums are often used with serial communication.

The checksum is a byte checksum. The following VB code is equivalent :

Dim Check as Byte

Check = 255

For x = 1 To Len(s$)

Check = check – ASC(mid$(s$,x,1))

Next

See also

CRC8 , CRC16 , CRC32

Example

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 8000000

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

 

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits

= 8 , Clockpol = 0

 

Dim S As String * 10

'dim variable

S = "test"

'assign variable

Print Checksum(s)

'print value (192)

End

 

CHR

Action

Convert a numeric variable or a constant to a string with a length of 1 character. The character represents the ASCII value of the numeric value.

Syntax

PRINT CHR(var)

s = CHR(var)

Remarks

Var

Numeric variable or numeric constant.

S

A string variable.

 

 

When you want to print a character to the screen or the LCDdisplay, you must convert it with the CHR() function.

page -297-