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

© MCS Electronics, 1995-2007

FOURTHLINE

Action

Set LCD cursor to the start of the fourth line.

Syntax

FOURTHLINE

Remarks

Only valid for LCD displays with 4 lines.

See also

HOME , UPPERLINE , LOWERLINE , THIRDLINE, LOCATE

Example

Thirdline

 

Lcd "Line 3"

 

Fourthline

 

Lcd "Line 4"

'goto home on line

Home Third

three

 

Home Fourth

 

Home F

'first letter also works

FRAC

Action

Returns the fraction of a single.

Syntax

var = FRAC( single )

Remarks

var

A numeric single variable that is assigned with the fraction of

 

variable single.

single

The single variable to get the fraction of.

 

 

The fraction is the right side after the decimal point of a single.

See Also

INT

page -494-

 

© MCS Electronics, 1995-2007

Example

 

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

 

--

: (c) 1995-2005, MCS Electronics

'copyright

'micro

: Mega48

'suited for demo

: yes

'commercial addon needed

: no

'purpose

: demonstrates FRAC function

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

--

$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 = 40

for the SW stack

' default use 40

$framesize = 40

for the frame space

 

Dim X As Single

 

X = 1.123456

 

Print X

 

Print Frac(x)

 

End

 

FREEFILE

Action

Returns a free Filenumber.

Syntax

bFileNumber = FREEFILE()

Remarks

bFileNumber A byte variable , which can be used for opening next file

This function gives you a free file number, which can be used for file – opening statements. In contrast to VB this file numbers start with 128 and goes up to 255. Use range 1 to 127 for user defined file numbers to avoid file number conflicts with the system numbers from FreeFile()

This function is implemented for compatility with VB.

See also

INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FILEATTR , SEEK , BSAVE , BLOAD , KILL , DISKFREE , DISKSIZE , GET , PUT , FILEDATE , FILETIME ,

page -495-

© MCS Electronics, 1995-2007

FILEDATETIME , DIR , FILELEN , WRITE , INPUT

ASM

Calls

_GetFreeFileNumber

 

Input

none

 

Output

r24: Filenumber

r25: Errorcode

 

C-Flag: Set on Error

 

 

 

 

Partial Example

Ff =Freefile() ' get file handle

Open"test.txt" For Input As #ff ' we can use a constant for the file too Print Lof(#ff);" length of file"

Print Fileattr(#ff);" file mode" ' should be 1 for input Do

LineInput #ff , S ' read a line

' line input is used to read a line of text from a file Print S ' print on terminal emulator

Loop UntilEof(ff)<> 0

'The EOF() function returns a non-zero number when the end of the file is reached 'This way we know that there is no more data we can read

Close #ff

FUSING

Action

FUSING returns a formatted string of a single value.

Syntax

target = FUSING(source, "mask")

Remarks

target

The string that is assigned with the formatted string.

source

The source variable of the type SINGLE that will be converted

mask

The mask for formatting the string.

 

The mask is a string constant that always must start with #.

 

After the decimal point you can provide the number of digits you want

 

the string to have:

 

#.### will give a result like 123.456. Rounding is used when you use

 

the # sign. So 123.4567 will be converted into 123.457

 

When no rounding must be performed, you can use the & sign instead of

 

the # sign. But only after the DP.

 

#.&&& will result in 123.456 when the single has the value 123.4567

 

 

When the single is zero, 0.0 will be returned, no matter how the mask is set up.

page -496-

© MCS Electronics, 1995-2007

See also

FORMAT , STR

Example

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

 

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

: fusing.bas

'name

'copyright

: (c) 1995-2005, MCS Electronics

'purpose

: demo : FUSING

'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 S As Single , Z As String * 10

'now assign a value to the single S = 123.45678

'when using str() you can convert a numeric value into a string Z = Str(s)

Print Z 'prints 123.456779477

Z = Fusing(s , "#.##")

'now use some formatting with 2 digits behind the decimal point with rounding Print Fusing(s , "#.##") 'prints 123.46

'now use some formatting with 2 digits behind the decimal point without

rounding

'prints 123.45

Print Fusing(s , "#.&&")

'The mask must start with #.

 

'It must have at least one # or & after the point.

 

'You may not mix & and # after the point.

 

End

 

GET

Action

Reads a byte from the hardware or software UART.

Reads data from a file opened in BINARY mode.

page -497-

© MCS Electronics, 1995-2007

Syntax

GET #channel, var

GET #channel, var , [pos] [, length]

Remarks

GET in combination with the software/hardware UART reads one byte fromthe UART.

GET in combination with the AVR-DOS file system is very flexible and versatile. It works on files opened in BINARY mode and you can reads all data types.

#channel

A channel number, which identifies an opened file. This can be a hard coded

 

constant or a variable.

Var

The variable or variable array that will be assigned with the data fromthe

 

file

Pos

This is an optional parameter that may be used to specify the position where

 

the reading must start from. This must be a long variable.

Length

This is an optional parameter that may be used to specify how many bytes

 

must be read from the file.

 

 

By default you only need to provide the variable name. When the variable is a byte, 1 byte will be read. When the variable is a word or integer, 2 bytes will be read. When the variable is a long or single, 4 bytes will be read. When the variable is a string, the number of bytes that will be read is equal to the dimensioned size of the string. DIM S as string * 10 , would read 10 bytes.

Note that when you specify the length for a string, the maximum length is 254. The maximum length for a non-string array is 65535.

Partial Example:

GET #1 , var ,,2 ' read 2 bytes, start at current position GET #1, var , PS ' start at position stored in long PS

GET #1, var , PS, 2 ' start at position stored in long PS and read 2 bytes

See also

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

ASM

current position

goto new position first

Byte:

 

_FileGetRange_1

_FileGetRange_1

Input:

Input:

r24: File number

r24: File number

X: Pointer to variable

X: Pointer to variable

T-Flag cleared

r16-19 (A): New position (1-based)

page -498-

© MCS Electronics, 1995-2007

Word/Integer: _FileGetRange_2

Input:

r24: File number

X: Pointer to variable

T-Flag cleared

Long/Single: _FileGetRange_4

Input:

r24: File number

X: Pointer to variable

T-Flag cleared

String (<= 255 Bytes) with fixed length _FileGetRange_Bytes

Input:

r24: File number r20: Count of Bytes X: Pointer to variable T-Flag cleared

Array (> 255 Bytes) with fixed length _FileGetRange

Input:

r24: File number r20/21: Count of Bytes X: Pointer to variable T-Flag cleared

Output from all kind of usage:

T-Flag Set

_FileGetRange_2 Input:

r24: File number

X: Pointer to variable

r16-19 (A): New position (1-based) T-Flag Set

_FileGetRange_4 Input:

r24: File number

X: Pointer to variable

r16-19 (A): New position (1-based) T-Flag Set

_FileGetRange_Bytes Input:

r24: File number r20: Count of bytes

X: Pointer to variable

r16-19 (A): New position (1-based) T-Flag Set

_FileGetRange Input:

r24: File number r20/21: Count of bytes X: Pointer to variable

r16-19 (A): New position (1-based) T-Flag Set

page -499-