Файл: Fast AVR. Basic compiller for AVR. User manual (2004).pdf

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

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

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

Добавлен: 13.06.2025

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

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

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

FastAVR Basic compiler Manual

6.47.FromBcd

Description:

Calculates value from BCD format.

Syntax: var1=FromBcd(var2)

Remarks:

var1 is the target variable.

var2 is the source BCD variable.

Example: m=FromBcd(n)

Related topics:

BCD

6.48.Function

Description:

Defines a Function procedure.

Syntax:

Function NameOfFunc(parameters list) As Type

Remarks:

NameOfFunc is the name of Function

parameters list is the name and type of parameters, comma delimited (can not be Bit) - MUST has the same names as is in theirs Declare statements!

As Type is type of returned value (Byte, Integer, Word, Long or Float)

Function must first be declared with Declare keyword.

Example:

Declare Function Mul(a As Byte, b As Byte) As Byte

Dim n As

Byte

n=Mul(5,

7)

'n=35

'/////////////////////////////////////////////////////

Function Mul(a As Byte, b As Byte) As Byte

Return a*b

[Exit Function]

' optionally exit from Function

End Function

' end of Function

Related topics:

Declare

Return

Sub

107

FastAVR Basic compiler Manual

6.49.GoTo

Description:

Transfers program execution to the statement identified by a specified label.

Syntax:

Goto label

Remarks:

label is a line identifier indicating where to jump

Example:

Point: 'a label must end with a colon

Goto Point

6.50.I2CRead

I2CStart

6.51.I2CStart

Description:

I2CStart starts the I2C transfers.

I2CStop stops the I2C transfers

I2CRead receives a single byte through I2C bus

I2CWrite sends a single byte through I2C bus

Syntax:

I2CStart adr

var1=I2CRead, Ack [, Nack] I2CWrite var2

I2CStop

Remarks:

adr The address of the I2C-device.

var1 The variable that receives the value from the I2C-device. var2 The variable or constant to write to the I2C-device

Ack - tells that there will be more Readings

Nack - this is last Reading (MUST be present)

Dont forget pulup resistors on SDA and SCL (4k7 - 10k)!

Notes about I2Cread: The first call to I2Cread will isue also device address for Read (last bit is automaticaly set), last I2Cread command MUST be used with Nack option!

Example1:

' reading time from Philips PCF85x3

I2cstart &ha0

'generate start

108


FastAVR Basic compiler Manual

I2cwrite 2

'select second register

s=I2cread,

Ack

m=I2cread,

Ack

h=I2cread,

Nack

I2cstop

'generate stop

Example2:

'/////////////////////////////////////////////////// Sub WritePage(Padr As Word)

Local i As Byte

I2Cstart &ha0

' 24C64 address

I2Cwrite Msb(Padr)

' write adr MSB

I2Cwrite Padr

' write adr LSB

For i=0 To 31

I2Cwrite buff(i)

' write data from array buff

Next

I2Cstop

WaitMs 6

' wait to write (10 max)

End Sub

Example3:

'/////////////////////////////////////////////////// Sub ReadPage(Padr As Word)

Local i As Byte, tmp As Byte

I2Cstart &ha0

' 24C64 address

I2Cwrite Msb(Padr)

' write adr MSB

I2Cwrite Padr

' write adr LSB

tmp=I2Cread, Ack

' first read deefers from others

For i=0 To 31

buff(i)=tmp

' we read into buff array

tmp=I2Cread, Ack

Next

tmp=I2Cread, Nack

' dummy read - we need Nack!

I2Cstop

End Sub

Related topics:

I2CStop

I2CWrite

I2CRead

109


FastAVR Basic compiler Manual

6.52.I2CStop

I2CStart

6.53.I2CWrite

I2CStart

6.54.If

Description:

Conditionally executes a group of statements, depending on the value of an expression(s).

Syntax:

If expression Then statement

or

If expression Then statements

ElseIf expression Then statements

.

.

Else

statements

End If

Remarks:

While testing bit variables of any kind (bit var, port.bit or var.bit) only "=1", "=0" or nothing can be used! Conditions and statements may be contained on one line or multiple lines.

Instead of using many ElseIfs, Select Case may be used!

Example:

If a>5 And a<10 Then

Print a; " a is Between 5 and 10"

ElseIf a=5 Then

Print a; " a is 5"

Else

Print b; " a has other value"

End If

If a Then 'If a>0 generates extra comact code

Print a

End If

If PINB.5 Then

Print a

End If

If a.3 Then

Print a

End If

110

FastAVR Basic compiler Manual

Related topics:

Select

6.55.Incr

Description:

Increments var by 1

Syntax:

Incr var

Remarks:

var variable to increment

Example:

Incr a ' a=a+1

Related topics:

Decr

6.56.InitLcd

Description:

Re initialize alphanumeric LCD.

Syntax:

InitLcd

Remarks:

If LCD was turned OFF because of entering in one of the PowerDown modes it needs to be ReInitialized after waken up.

Example:

InitLcd

Related topics: $Lcd

Lcd

111


FastAVR Basic compiler Manual

6.57.InitEE

Description:

Initialize EPROM data to be written during device programming.

Syntax:

InitEE = 11, 22, 33, 44, 55, 66, 77, 88

Remarks:

InitEE will produce a hex file named BasName.eep for EPROM programming starting at adr 0! Numeric constants are comma delimited and can be placed in more than one line.

Related topics:

ReadEE

WriteEE

6.58.Input

Description:

Returns the value or string from the RS-232 port.

Syntax:

Input ["prompt"], var1, var2, ....

Input2 ["prompt"], var1, var2, .... ' for second UART

Remarks:

prompt is an optional string constant printed before the prompt character. varX is/are the variable(s) to accept the input value or a string, not for Longs!

With the built-in terminal emulator this statement makes the PC keyboard an input device.

Example:

Input s

Input n, w

Input "n="; n; "w="; w

Input2 s

Related topics:

Print

PrintBin

InputBin

112

FastAVR Basic compiler Manual

6.59.InputBin

Description:

Returns a binary value(s) from the RS-232 port.

Syntax:

InputBin var1; var2;...

InputBin var, n

InputBin2 var1; var2;... ' for second UART

Remarks:

var, var1, var2 variables that receive a binary value from serial port n number of bytes to receive. Bytes will be stored from var up!

The number of bytes to read depends on the variable lenth You use, 1 for byte, 2 for integer or word.

Example:

InputBin a; w ' waits three bytes

InputBin a, 12 ' waits for 12 bytes (from a up)

InputBin2 a; w ' waits three bytes

Related topics:

PrintBin

6.60.Int

Description:

Returns Integer part of Float argument as Float.

Syntax:

var=Int(numeric expression)

Remarks:

var receives an Integer part of numeric expression numeric expression

Example:

Dim n As Float

n=Int(372.41855) 'n=372.0

Related topics:

Fract

113