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

© MCS Electronics, 1995-2007

LTRIM

Action

Returns a copy of a string with leading blanks removed

Syntax

var = LTRIM( org )

Remarks

Var

String that receives the result.

Org

The string to remove the leading spaces from

 

 

See also

RTRIM , TRIM

ASM

NONE

Partial Example

Dim S As String * 6

S =" AB "

Print Ltrim(s)

Print Rtrim(s)

Print Trim(s)

End

LOAD

Action

Load specified TIMER with a reload value.

Syntax

LOAD TIMER , value

Remarks

TIMER

TIMER0 , TIMER1 or TIMER2(or valid timer name)

Value

The variable or value to load.

 

 

The TIMER0 does not have a reload mode. But when you want the timer to generate an interrupt after 10 ticks for example, you can use the LOADstatement.

It will do the calculation : (256-value)

page -554-

© MCS Electronics, 1995-2007

So LOAD TIMER0, 10 will load the TIMER0 with a value of 246 so that it willoverflow after 10 ticks.

TIMER1 is a 16 bit counter so it will be loaded with the value of 65536-value.

See Also

NONE

Example

NONE

LOADADR

Action

Loads the address of a variable into a register pair.

Syntax

LOADADR var , reg

Remarks

var

A variable which address must be loaded into the register pair X, Y or

 

Z.

reg

The register X, Y or Z.

 

 

The LOADADR statement serves as an assembly helper routine.

Example

Dim S As String * 12

Dim A As Byte

$ASM

loadadr S , X ; load address into R26 and R27

ld _temp1, X ; load value of location R26/R27 into R24(_temp1) $END ASM

LOADLABEL

Action

Assigns a word variable with the address of a label.

Syntax

Var = LOADLABEL(label )

Remarks

var The variable that is assigned with the address of the label.

page -555-

© MCS Electronics, 1995-2007

lbl

The name of the label

In some cases you might need to know the address of a point in your program. To perform a Cpeek() for example.

You can place a label at that point and use LoadLabel to assign the address of the label to a variable.

LOADWORDADR

Action

Loads the Z-register and sets RAMPZ if available.

Syntax

LOADWORDADR label

Remarks

label

The name of the label which address will be loaded into R30-R31 which

 

form the Z-register.

 

 

The code that will be generated :

LDI R30,Low(label * 2)

LDI R31,High(label * 2)

LDI R24,1 or CLR R24

STS RAMPZ, R24

As the AVR uses a word address, to find a byte address we multiply the address with 2. RAMPZ forms together with pointer Z an address register. As the LS bit of Z is used to identify the lower or the upper BYTE of the address, it is extended with the RAMPZ to address more then 15 bits. For example the Mega128 has 128KB of space and needs the RAMPZ register set to the right value in order to address the upper or lower 64KB of space.

See also

LOADLABEL, LOADADR

Example

LOADWORDADR label

LOC

Action

Returns the position of last read or written Byte of the file

Syntax

lLastReadWritten = LOC (#bFileNumber)

page -556-

© MCS Electronics, 1995-2007

Remarks

bFileNumber

(Byte) Filenumber, which identifies an opened file

lLastReadWritten

(Long) Variable, assigned with the Position of last read or written

 

Byte (1-based)

 

 

This function returns the position of the last read or written Byte. If an error occurs, 0 is returned. Check DOS-Error in variable gbDOSError. If the file position pointer is changed with the command SEEK, this function can not be used till the next read/write operation.

This function differs from VB. In VB the byte position is divided by 128.

See also

INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOF , EOF , FREEFILE , FILEATTR , SEEK , BSAVE , BLOAD , KILL , DISKFREE , DISKSIZE , GET , PUT , FILEDATE , FILETIME , FILEDATETIME , DIR , FILELEN , WRITE , INPUT

ASM

Calls

_FileLoc

 

Input

r24: filenumber

X: Pointer to Long-variable, which gets th result

Output

r25: Errorcode

C-Flag: Set on Error

 

 

 

Example

'open the file in BINARY mode Open "test.biN" For Binary As #2 Put #2 , B ' write a byte

Put #2 , W ' write a word Put #2 , L ' write a long

Ltemp = Loc(#2)+ 1 ' get the position of the next byte Print Ltemp ;" LOC"' store the location of the file pointer Print Lof(#2);" length of file"

Print Fileattr(#2);" file mode"' should be 32 for binary Put #2 , Sn ' write a single

Put #2 , Stxt ' write a string

Flush #2 ' flush to disk

Close #2

LOF

Action

Returns the length of the File in Bytes

Syntax

lFileLength = LOF (#bFileNumber)

page -557-