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

© MCS Electronics, 1995-2007

Action

Returns the index of a series of data.

Syntax

var = LOOKDOWN( value, label, entries)

Remarks

Var

The returned index value

Value

The value to search for

Label

The label where the data starts

entries

The number of entries that must be searched

 

 

When you want to look in BYTE series the VALUE variable must be dimensioned as a BYTE. When you want to look in INTEGER or WORD series the VALUE variable must be dimensioned as an INTEGER.

The LookDown function is the counterpart of the LookUp function.

Lookdown will search the data for a value and will return the index when the value is found. It will return –1 when the data is not found.

See also

LOOKUPSTR , LOOKUP

Example

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

 

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

: lookdown.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo : LOOKDOWN

'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

 

Dim Idx As Integer , Search As Byte , Entries As Byte

 

'we want to search for the value 3

 

Search = 3

 

'there are 5 entries in the table

 

Entries = 5

 

page -563-

© MCS Electronics, 1995-2007

'lookup and return the index

Idx = Lookdown(search , Label , Entries)

Print Idx

Search = 1

Idx = Lookdown(search , Label , Entries)

Print Idx

Search = 100

 

Idx = Lookdown(search , Label , Entries)

' return -1 if not

Print Idx

found

 

'looking for integer or word data requires that the search variable is

'of the type integer !

 

Dim Isearch As Integer

 

Isearch = 400

 

Idx = Lookdown(isearch , Label2 , Entries)

' return 3

Print Idx

End

Label:

Data 1 , 2 , 3 , 4 , 5

Label2:

Data 1000% , 200% , 400% , 300%

LOOKUP

Action

Returns a value from a table.

Syntax

var = LOOKUP( value, label)

Remarks

Var

The returned value

Value

A value with the index of the table

Label

The label where the data starts

 

 

The value can be up to 65535. 0 will return the first entry.

See also

LOOKUPSTR

Example

$regfile = "m48def.dat" ' specify the used

page -564-

© MCS Electronics, 1995-2007

 

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 B1 As Byte , I As Integer

 

B1 = Lookup(2 , Dta)

' Prints 3 (zero

Print B1

based)

 

I = Lookup(0 , Dta2)

' print 1000

Print I

 

End

 

Dta:

 

Data 1 , 2 , 3 , 4 , 5

 

Dta2:

 

Data 1000% , 2000%

 

LOOKUPSTR

Action

Returns a string from a table.

Syntax

var = LOOKUPSTR( value, label )

Remarks

Var

The string returned

Value

A value with the index of the table. The index is zero-based. That is, 0 will

 

return the first element of the table.

Label

The label where the data starts

 

 

The index value can have a maximum value of 255.

See also

LOOKUP , LOOKDOWN

Example

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 4000000

frequency

' use baud rate

$baud = 19200

$hwstack = 32

' default use 32

 

page -565-

© MCS Electronics, 1995-2007

 

for the hardware stack

' default use 10

$swstack = 10

for the SW stack

' default use 40

$framesize = 40

for the frame space

 

Dim S As String * 4 , Idx As Byte

 

Idx = 0 : S = Lookupstr(idx , Sdata)

'will print 'This'

Print S

End

 

Sdata:

 

Data "This" , "is" , "a test"

 

LOW

Action

Retrieves the least significant byte of a variable.

Syntax

var = LOW( s )

Remarks

Var

The variable that is assigned with the LSB of var S.

S

The source variable to get the LSB from.

 

 

You can also assign a byte to retrieve the LSB of a Word or Long.

For example :

B = L , where B is a byte and L is a Long.

See also

HIGH , HIGHW

Example

$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 Integer , Z As Byte

 

I = &H1001

' is 1

Z = Low(i)

End

 

page -566-