ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 12.06.2025

Просмотров: 8287

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

© 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-


© MCS Electronics, 1995-2007

r25: Error Code C-Flag on Error X: requested info

Partial Example

'for the binary file demo we need some variables of different types

Dim B As Byte , W As Word , L As Long , Sn As Single , Ltemp As Long Dim Stxt As String * 10

B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt = "test"

'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

' get the position

Ltemp = Loc(#2) + 1

of the next byte

' store the

Print Ltemp ; " LOC"

location of the file pointer

Print Seek(#2) ; " = LOC+1"

Print Lof(#2) ; " length of file"

' should be 32 for

Print Fileattr(#2) ; " file mode"

binary

' write a single

Put #2 , Sn

Put #2 , Stxt

' write a string

Flush #2

' flush to disk

Close #2

'now open the file again and write only the single

Open "test.bin" For Binary As #2

L = 1 'specify the file position

' reset is the

B = Seek(#2 , L)

same as using SEEK #2,L

Get#2 , B ' get the byte

Get#2 , W ' get the word

Get#2 , L ' get the long

Get#2 , Sn ' get the single

Get#2 , Stxt ' get the string

Close #2

GETADC

Action

Retrieves the analog value from channel 0-7.

Syntax

var = GETADC(channel [,offset])

Remarks

Var

The variable that is assigned with the A/D value

Channel

The channel to measure. Might be higher then 7 on some chips.

page -500-