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

 

© MCS Electronics, 1995-2007

$framesize = 40

' default use 40

for the frame space

 

' These functions only works on BYTE and WORD arrays at the moment !!!!!

'Dim some variables

Dim Wb As Byte , B As Byte

Dim W(10) As Word ' or use a BYTE array

'fill the word array with values from 1 to 10

For B = 1 To 10 W(b) = B

Next

Print "Max number " ; Max(w(1))

Print "Min number " ; Min(w(1))

Dim Idx As Word , M1 As Word

Min(w(1) , M1 , Idx)

Print "Min number " ; M1 ; " index " ; Idx

Max(w(1) , M1 , Idx)

Print "Max number " ; M1 ; " index " ; Idx

End

MEMCOPY

Action

Copies a block of memory

Syntax

bts = MEMCOPY(source, target , bytes[ , option])

Remarks

bts

The total number of bytes copied. This must be a word or integer

source

The first address of the source variable that will be copied.

target

The first address of the target variable that will be copied to.

bytes

The number of bytes to copy from "source" to "target"

option

An optional numeric constant with one of the following values :

 

1 - only the source address will be increased after each copied byte

 

2 - only the target address will be increased after each copied byte

 

3 - both the source and target address will be copied after each copied byte

 

 

By default, option 3 is used as this will copy a block of memory from one memory location to another location. But it it also possible to fill an entire array of memory block with the value of 1 memory location. For example to clear a whole block or preset it with a value.

And with option 2, you can for example get a number of samples from a register like PINB and store it into an array.

See also

page -571-

© MCS Electronics, 1995-2007

NONE

ASM

NONE

Example

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

: MEMCOPY.BAS

'name

'copyright

: (c) 1995-2006, MCS Electronics

'purpose

: show memory copy function

'suited for demo

: yes

'commercial addon needed

: no

'use in simulator

: possible

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

' specify the used

$regfile = "m88def.dat"

micro

' used crystal

$crystal = 8000000

frequency

' use baud rate

$baud = 19200

$hwstack = 32

' default use 32

for the hardware stack

' default use 10

$swstack = 16

for the SW stack

 

$framesize = 40

 

Dim Ars(10) As Byte

'source bytes

Dim Art(10) As Byte

'target bytes

Dim J As Byte

'index

For J = 1 To 10

'fill array

Ars(j) = J

 

Next

 

J = Memcopy(ars(1) , Art(1) , 4)

'copy 4 bytes

Print J ; " bytes copied"

 

For J = 1 To 10

 

Print Art(j)

 

Next

 

J = Memcopy(ars(1) , Art(1) , 10 , 2)

'assign them all

with element 1

 

Print J ; " bytes copied"

 

For J = 1 To 10

 

Print Art(j)

 

Next

 

Dim W As Word , L As Long

 

W = 65511

'copy 2 bytes from

J = Memcopy(w , L , 2)

word to long

 

End

 

MIN

page -572-

© MCS Electronics, 1995-2007

Action

Returns the minimum value of a byte or word array.

Syntax

var1 = MIN(var2) MIN(ar(1), m , idx)

Remarks

var1

Variable that will be assigned with the minimum value.

var2

The first address of the array.

 

 

 

The MIN statement can return the index too

Ar(1)

Starting element to get the minimum value and index of

M

Returns the minimum value of the array

Idx

Return the index of the array that contains the minimum value. Returns 0 if

 

there is no minimum value.

 

 

The MIN() ans MAX() functions work on BYTE and WORD arrays only.

See also

MAX

Example

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

 

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

: minmax.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: show the MIN and MAX functions

'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

 

' These functions only works on BYTE and WORD arrays at the moment !!!!!

'Dim some variables

Dim Wb As Byte , B As Byte

Dim W(10) As Word ' or use a BYTE array

page -573-

© MCS Electronics, 1995-2007

'fill the word array with values from 1 to 10

For B = 1 To 10 W(b) = B

Next

Print "Max number " ; Max(w(1))

Print "Min number " ; Min(w(1))

Dim Idx As Word , M1 As Word

Min(w(1) , M1 , Idx)

Print "Min number " ; M1 ; " index " ; Idx

Max(w(1) , M1 , Idx)

Print "Max number " ; M1 ; " index " ; Idx

End

MID

Action

The MID function returns part of a string (a sub string).

The MID statement replaces part of a string variable with another string.

Syntax

var = MID(var1 ,st [, l] ) MID(var ,st [, l] ) = var1

Remarks

var

The string that is assigned.

Var1

The source string.

st

The starting position.

l

The number of characters to get/set.

 

 

See also

LEFT , RIGHT

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

 

NBITS

Action

page -574-

© MCS Electronics, 1995-2007

Set all except the specified bits to 1.

Syntax

Var = NBITS( b1 [,bn])

Remarks

Var

The BYTE/PORT variable that is assigned with the constant.

B1 , bn

A list of bit numbers that NOT must be set to 1.

 

 

While it is simple to assign a value to a byte, and there is special boolean notation &B for assigning bits, the Bits() and NBits() function makes it simple to assign a few bits.

B = &B01111101 : how many zero’s are there?

This would make it more readable: B = NBits(1, 7)

You can read from the code that bit 1 and bit 7 are NOT set to 1.

It does not save code space as the effect is the same.

The NBITS() function will set all bits to 1 except for the specified bits. It can only be used on bytes and port registers.

Valid bits are in range from 0 to 7.

See Also

BITS

Example

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

 

---

: bits-nbits.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo for Bits() AND Nbits()

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

'use in simulator

: possible

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

---

$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 B As Byte

 

'while you can use &B notation for setting bits, like B = &B1000_0111 'there is also an alternative by specifying the bits to set

B = Bits(0 , 1 , 2 , 7) 'set only bit 0,1,2 and 7

Print B

page -575-