Файл: Fast AVR. Basic compiller for AVR. User manual (2004).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 1439
Скачиваний: 1
FastAVR Basic compiler Manual
6.110. Sound
Description:
Makes a sound.
Syntax:
Sound var1, var2
var1 * 10 is half of perion in us, f = 1/(10 * var1 * 2) (frequency in Hz) var2 * 10 is number of periods in sound (duration)
Example:
Sound 50, 100 '1 kHz beep, 1 sec in duration
Sound 25, 100 '2 kHz beep, 0.5 sec in duration
Related topics: $Sound
6.111. SpiIn
Description:
Receives a value from the SPI-bus in SLAVE mode.
Syntax:
var = SpiIn
var variable to receive data from the SPI bus
Remarks:
SS pin is input and must be driven by MASTER!
Example: n=SpiIn
Related topics:
SPIOut
6.112. SpiOut
Description:
Sends the value of a variable to the SPI-bus in MASTER mode.
Syntax:
SpiOut var
SpiOut var1; var2;....,wait
SpiOut var1, n, wait
var, var1, var2 variables to be shifted out
n number of bytes from SRAM to send via SPI bus, starting with var1
139
FastAVR Basic compiler Manual
Remarks:
SS pin is set to OutPut (user can use this pin to select SLAVE)!
Example:
SpiOut |
i |
'ShiftOut |
i (9) |
SpiOut |
n; 10, Wait |
'ShiftOut |
the whole array |
Related topics:
SPIIn
6.113. Sqr
Description:
Calculates Float Square of its argument.
Syntax:
var=Sqr(numeric expression)
Remarks:
var Float, receives a Square of numeric expression numeric expression
Example:
Dim f1 As Float
Dim f2 As Float
f1=12.345
f2=Sqr(f1) ' f2=f1*f1=152.399
Related topics:
Pow
Sqrt
6.114. Sqrt
Description:
Calculates Square root.
Syntax:
var=Sqr(numeric expression)
Remarks:
var receives a Square root of numeric expression numeric expression must be positive
Example:
Dim n As Byte
Dim w As Word
140
FastAVR Basic compiler Manual
w=12345
n=Sqrt(w) 'n=111
6.115. Start
Description:
Starts or enables one of the specified devices.
Syntax:
Start device
Start Adc [, Vref=Ext|Int|Vcc]
Remarks: device can be:
Adc supply for AD converter (default is stopped), user can specify type of used Vref! Ac supply for analog comparator (default is started)
WatchDog
Timer0, Timer1, Timer2
Example:
Start Ac |
' |
switch supply to |
Ac |
Start Adc, Vref=Int ' |
switch supply to |
Adc, Internal (2.56V) Vref is used |
|
Start WatchDog |
' |
enables WatchDog |
|
Start Timer1 |
' |
start Timer1 |
|
Related topics:
Stop
6.116. Stop
Description:
Stops or disables one of the specified devices.
Syntax:
Stop device
Remarks: device can be:
Adc supply for AD converter (default is stopped) Ac supply for analog comparator (default is started)
WatchDog
Timer0, Timer1, Timer2
Example:
141
FastAVR Basic compiler Manual
Stop Ac |
' switch supply from Ac |
|
Stop Adc |
' switch supply from Adc |
|
Stop WatchDog |
' |
disables WatchDog |
Stop Timer1 |
' |
stops Timer1 |
Related topics:
Start
6.117. Str
Description:
Converts a number to a string.
Syntax:
var=Str(numeric expression)
Remarks:
var string variable
If $LeadChar is defined then result will be right justified with Leading Char as defined. Also, if Format() is defined then optional decimal point will be inserted!
Example:
Dim n As Byte
Dim s As String*5
n=123
s=Str(n) 's="123"
Related topics:
Val
6.118. Sub
Description:
Defines a subroutine procedure.
Syntax:
Sub NameOfSub(parameters list)
Remarks:
NameOfSub is the name of the subroutine
parameters list is the name and type of parameters, comma delimited (can not be Bit)
Sub must first be declared using the Declare keyword (names of passing parameters must be the same as later in Sub).
Example:
142
FastAVR Basic compiler Manual
Declare Sub Test(a As Byte, b As Byte) 'declares a Sub Test
Test(2, 6) |
'22 will be Printed |
End
'/////////////////////////////////////////////////////
Sub Test(a As Byte, b As Byte)
Local d As Byte ' local var is declared
d=10
[Exit Sub] ' optionally exit from Sub
Print a*b+d |
|
End Sub |
' here is end of Sub |
Related topics:
Declare
Function
6.119. Swap
Description:
Swaps variable(s), depending on type of variable.
Syntax:
Swap(var)
Swap(var1, var2)
Remarks:
var if var is Byte then nibles will be swaped, if var is Word or Integer then bytes will be swaped. var1 this variable will be swaped with var2
Example:
Dim a As Byte, b As Byte
Dim w As Word
a=&h25 b=&h34
Swap(a) ' a=&h52
w=&h1234
Swap(w) |
' |
w=&h3412 |
|
Swap(a, |
b) |
' |
a=&h34, b=&h25 |
143
FastAVR Basic compiler Manual
6.120. Tan
Description:
Returns the trigonometric Tangent of its argument.
Syntax:
var=Tan(numeric expression)
Remarks:
var type Float receives a Tangent of numeric expression
numeric expression can be in Radians or Deegrees, depending on $Angles metastatement!
Example:
Dim n As Byte
Dim f1 As Float
n=30 ' assuming $Angles=Degrees f1=Tan(n) ' f1=0.5773503
Related topics:
Sin
Cos
Asin
Acos
Atan
6.121. Tanh
Description:
Returns the Tangent Hiperbolicus of its argument.
Syntax:
var=Tanh(numeric expression)
Remarks:
var type Float receives a Tanh of numeric expression numeric expression
Example:
Dim f1 As Float
f1=Tanh(5) 'f1=0.999909
Related topics:
Sinh
Cosh
144
FastAVR Basic compiler Manual
6.122. Toggle
Description:
Toggles the state of an AVR port pin.
Syntax:
Toggle PORT.pin
Remarks:
AVR port pin must first be configured as an output.
Example:
Toggle |
PORTB.2 |
'toggles |
PortB.2 |
Toggle |
Led |
'toggles |
Port.Pin named Led (defined using $Def) |
Related topics:
Set
Reset
6.123. UCase
Description:
Returns an all-uppercase version of its string argument.
Syntax: var=UCase(var1)
Remarks:
var uppercase string version of var1 var1 original string variable.
Example:
Dim Name As String*15
Dim Part As String*10
Name="Mona Lisa"
Part=UCase(Name) 'Part="MONA LISA"
Related topics:
LCase
6.124. Val
Description:
Returns the numeric equivalent of a string.
Syntax: var=Val(string)
145
FastAVR Basic compiler Manual
Remarks:
var variable to store the string value. string string variable
Example:
Dim s As String * 8
Dim n As Byte
s="123" 'init string n=Val(s) 'n=123
Related topics:
Str
6.125. VarPtr
Description:
Returns the SRAM or XRAM address of a variable (pointer).
Syntax: var1=VarPtr(var2)
Remarks:
var1 variable that will pointing to var2. var2 variable to retrieve the address from.
Var1 mast be declared as Word for devices with more than 256 bytes of SRAM!
Example: |
|
Dim n As Byte |
'global byte variable named a |
Dim w As Word |
'global word variable named w |
Dim f As Float |
'global word variable named w |
Dim db(10) As Byte |
'global array of ten bytes named n |
Dim s1 As String * 8 |
'global string variable named s1, length must be specified |
adr=VarPtr(n) |
'adr=&h60 |
adr=VarPtr(w) |
'adr=&h61 |
adr=VarPtr(f) |
'adr=&h63 |
adr=VarPtr(db) |
'adr=&h67 |
adr=VarPtr(s1) |
'adr=&h71 |
6.126. Wait, Waitms, Waitus
Description:
Waits seconds, milliseconds or microseconds*10.
Syntax: |
|
Wait var |
- waits var seconds |
WaitMs var |
- waits var milliseconds |
146