Файл: Fast AVR. Basic compiller for AVR. User manual (2004).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 1424
Скачиваний: 0
FastAVR Basic compiler Manual
Many expressions are supported in FastAVR. From very basic assignments like: a=5
To more complex like: a=(b+12)*c-3*d
FastAVR Basic Compiler performs all math operations in full hierarchal order. This means there is precedence to the operators. Multiplication and division are performed before addition and subtractions. As an example, to ensure the operations are carried out in the order needed, use parentheses to group the operations.
Even calls to system and user functions can be factors in expressions: a=5*Test(15)+Adc8(3)
Where Test is your function called with parameter 15 and Adc8(3) is a system function that returns an 8bit value as a result of the analog measurement on channel 3.
List of mathematical operators:
+ plus sign
-minus sign
* asterisk (multiplication symbol) / slash (division symbol)
Mod modulus operator
List of relational operators:
= |
equality |
<> |
inequality |
<= |
less than or equal |
>= |
greater than or equal |
<less than
>greater than
List of logical operators:
And conjunction
Or disjunction
List of boolean operators:
And, & boolean conjunction, bitwise and
Or, |
| boolean disjunction, bitwise or |
Xor, |
^ boolean Xor |
Not |
boolean complement |
Other operators also have special meanings, such as:
" double quotation as string delimiters , comma as a parameter separator
. period for ports or variable bit delimiters
; semicolon is used when more than one parameter is used (i.e., Print a; b; c) ' single quotation mark starts a comment
Numeric constants can be in decimal format: a=33
in hexadecimal:
a=&h21 'dec 33
or even in bynary: a=&b00100001 'dec 33
28
FastAVR Basic compiler Manual
A Label can be used as a line identifier. Label is an alphanumeric combination ending with a colon.
If a=0 Then
Goto ExitLabel
End If |
|
Other statements |
|
ExitLabel: |
'this is a Label |
After the main loop we write all used and previously declared subs and functions, including interrupt subroutines.
The subroutine itself starts with the keyword Sub or Function, followed by the name and parameter list (if one exists)
Sub Test1(a As Byte, b As Word)
Function Test2(a As Byte, b As Byte) as Byte
Parameter list must be identical to the declaration of the sub!
With the keyword Local we can declare local variables.
Local var as Type
Bits, Strings and Arrays are always Global!
The use and lifetime of local variables are limited to this subroutine.
The rules for Type are the same as for the Dim.
The body of Sub or Function is a complete program needed to solve a particular problem. The Function can return a value using the keyword Return.
If you have serious trouble in programming, especially if in doubt about the compiled results, please email source files to the mailing list for support!
FastAVR HINTS!
All internal registers can be accessed direct from basic:
XDIV = &h05 |
'changing clock for Mega |
|
MCUCR = MCUCR or &h38 |
'enter powerdown mode |
|
Dim Str_0 As String*15 |
||
Dim Str_1 |
As String*15 |
|
Dim Str_2 |
As String*15 |
|
Dim Str_3 |
As String*15 |
|
Dim s As String*15 |
' working string |
|
Dim n As Byte |
||
MemCopy(16, Str_0+16*n, s) ' copies n-th string from Str_0 into string s (acts like Array of Strings!)
Str_2="FastAVR"
n=Str_2(4) ' n=65 Strings acts like Arrays - elements are accessable also by index
Happy programming!
29
FastAVR Basic compiler Manual
2.14.Interrupts
All AVR interrupts are supported by FastAVR!
Interrupt Ovf1(), Save All
Interrupt service routines are just like normal subroutines. Of course, instead of using the keyword Sub we will use Interrupt. The table of short names listed below may be used for Interrupt names!
Very important is the Save x directive. Save x determines how many registers will be saved before calling the interrupt. This depends on what variables are used in the routine.
Save 0, will save SREG only, could be omitted, Save 1, will save SREG, zl and zh only.
Save 2, as Save 0 plus r24 and r25 Save 3, as Save 1 plus r0, r1, xl and xh
Save 4, as Save 2 plus r0, r1, r20, r21, r22, r23, xl and xh
Save All will save SREG and all registers from r0 to r5 and r19 to r31
When the Interrupt routine is more complex, use Save 2, Save 3 or Save All.
'/////////////////////////////////////////////////////
Interrupt Ovf1() |
'simple routine, no save |
|
Timer1=&h7000 |
'reloads |
timer1 for 10ms |
Toggle PortB.2 |
'toggles |
portb.2 |
End Interrupt |
||
When user dont know about using Save, start with All and then try the minor versions!
Here is a list of available Interrupts
Int |
Int Type for 2313 |
INT0 |
External Interrupt0 |
INT1 |
External Interrupt1 |
ICP1 |
Input Capture1 Interrupt |
OC1 |
Output Compare1 Interrupt |
OVF1 |
Overflow1 Interrupt |
OVF0 |
Overflow0 Interrupt |
URXC |
UART Receive Complete Interrupt |
UDRE |
UART Data Register Empty Interrupt |
UTXC |
UART Transmit Complete Interrupt |
ACI |
Analog Comparator Interrupt |
Int |
Int Type for 4433 |
INT0 |
External Interrupt0 |
INT1 |
External Interrupt1 |
ICP1 |
Input Capture1 Interrupt |
OC1A |
Output Compare1A Interrupt |
OVF1 |
Overflow1 Interrupt |
OVF0 |
Overflow0 Interrupt |
SPI |
SPI Interrupt |
URXC |
UART Receive Complete Interrupt |
UDRE |
UART Data Register Empty Interrupt |
UTXC |
UART Transmit Complete Interrupt |
ADCC |
ADC Interrupt |
ERDY |
EEPROM Interrupt |
ACI |
Analog Comparator Interrupt |
Int |
Int Type for 8515 |
INT0 |
External Interrupt0 |
INT1 |
External Interrupt1 |
ICP1 |
Input Capture1 Interrupt |
30
FastAVR Basic compiler Manual
OC1A |
Output Compare1A Interrupt |
OC1B |
Output Compare1B Interrupt |
OVF1 |
Overflow1 Interrupt |
OVF0 |
Overflow0 Interrupt |
SPI |
SPI Interrupt |
URXC |
UART Receive Complete Interrupt |
UDRE |
UART Data Register Empty Interrupt |
UTXC |
UART Transmit Complete Interrupt |
ACI |
Analog Comparator Interrupt |
Int |
Int Type for 8535 |
INT0 |
External Interrupt0 |
INT1 |
External Interrupt1 |
OC2 |
Timer2 Compare Interrupt |
OVF2 |
Overflow2 Interrupt |
ICP1 |
Input Capture1 Interrupt |
OC1A |
Output Compare1A Interrupt |
OC1B |
Output Compare1B Interrupt |
OVF1 |
Overflow1 Interrupt |
OVF0 |
Overflow0 Interrupt |
SPI |
SPI Interrupt |
URXC |
UART Receive Complete Interrupt |
UDRE |
UART Data Register Empty Interrupt |
UTXC |
UART Transmit Complete Interrupt |
ADCC |
ADC Conversion Complete Handle |
ERDY |
EEPROM Write Complete Handle |
ACI |
Analog Comparator Interrupt |
Int |
Int Type for ATmega103 |
INT0 |
External Interrupt0 |
INT1 |
External Interrupt1 |
INT2 |
External Interrupt2 |
INT3 |
External Interrupt3 |
INT4 |
External Interrupt4 |
INT5 |
External Interrupt5 |
INT6 |
External Interrupt6 |
INT7 |
External Interrupt7 |
OC2 |
Output Compare2 Interrupt |
OVF2 |
Overflow2 Interrupt |
ICP1 |
Input Capture1 Interrupt |
OC1A |
Output Compare1A Interrupt |
OC1B |
Output Compare1B Interrupt |
OVF1 |
Overflow1 Interrupt |
OC0 |
Output Compare0 Interrupt |
OVF0 |
Overflow0 Interrupt |
SPI |
SPI Interrupt |
URXC |
UART Receive Complete Interrupt |
UDRE |
UART Data Register Empty Interrupt |
UTXC |
UART Transmit Complete Interrupt |
ADCC |
ADC Conversion Complete Handle |
EEWR |
EEPROM Write Complete Handle |
ACI |
Analog Comparator Interrupt |
Int |
Int Type for ATmega8 |
INT0 |
External Interrupt0 |
INT1 |
External Interrupt1 |
OC2 |
Output Compare2 Interrupt |
OVF2 |
Overflow2 Interrupt |
ICP1 |
Input Capture1 Interrupt |
OC1A |
Output Compare1A Interrupt |
OC1B |
Output Compare1B Interrupt |
OVF1 |
Overflow1 Interrupt |
OVF0 |
Overflow0 Interrupt |
SPI |
SPI Interrupt |
31