Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Fast AVR. Basic compiller for AVR. User manual (2004)

.pdf
Источник:
Скачиваний:
288
Добавлен:
12.08.2013
Размер:
1.26 Mб
Скачать

FastAVR Basic compiler Manual

4.FastAVR Tools

4.1.AVR Studio

You can Debug or Simulate your program at assembler level using Atmel's free AVR Studio. For this purpose please load Obj file to AVR Studio!

When pressing the DEBUG button from the main toolbar for the first time you will be asked to locate the AVR Studio software!

Any further click of the Debug button will run AVR Studio!

AVRStudio3 can be downloaded for simulating and/or debugging the assembler output file!

4.2.LCD Character Generator

The alphanumeric LCD can define up to eight special characters numbered from 0 to 7.

First design your character by clicking on LCD pixel blocks (left clickset pixel, right clickreset pixel). By pressing OK, the LCD designer will insert a special code at the current cursor position in the active document window.

DefLcdChar 0, &h0A, &h04, &h0E, &h11, &h10, &h10, &h0F, &h00

Zero after DefLcdChar is the Character number and must be edited in subsequent character definitions!

40

FastAVR Basic compiler Manual

The new LCD character can be displayed on the LCD using the statement:

Lcd Chr(n)

'where n is the character number from 0 to 7

4.3.Terminal Emulator

When testing out the UART (hardware or software type), you may wish to monitor the output from your hardware. Terminal emulator will capture any ASCII output sent using the Print statement.

While typing in Terminal Emulator, all characters are sent to your hardware and can be captured using Input. ComPort must first be configured for the correct Port (Com1, Com2), speed (9600,....) and other parameters! The Terminal Emulator port must be opened by clicking on the RED circle!

41

FastAVR Basic compiler Manual

4.4.AVR Calculator

AVR calculator allows quick calculations for timer reload values based on the crystal used, needed time and prescale factor!

Calculated results are for Timer Overflow and for OutputCompare!

42

FastAVR Basic compiler Manual

4.5.Programmer

FastAVR runs Atmel's free ISP programming software installed on your PC (or any other programming software). Programming can be accomplished using a very simple programming dongle connected to your Parallel port. Here is the schematic to build one:

When pressing the PROGRAM button from the main tool bar the first time you will be asked to locate Your prefered programming software!

Any further click on the Program button will run the ISP programmer!

In addition, You can enter special Command line parameters if You are using such a Programmer!

You can download ISP Programmer from Atmels www !

43

FastAVR Basic compiler Manual

5.AVR fundaments

The best reading about AVR core is AVR data documents at

http://www.atmel.com/dyn/products/datasheets.asp?family_id=607.

44

FastAVR Basic compiler Manual

6.FastAVR KeyWords

6.1.Meta - Statements

Meta-statements direct the compiler. Most are to configure compiler options. Some cue the compiler about the intended program actions, such as interrupt handling. Thus, some directives cause code from predefined libraries to be included.

Meta-statement keywords begin with "$".

6.1.1.Compiler directives

6.1.1.1.$Angles

Description:

Defines how Angles will be threated in Trigonometric functions.

Syntax:

$Angles = Degrees|Radians

Remarks:

Default is Radians.

Example:

$Angles=Degrees

'Angles are in Deegrres

Dim f1 As Float

 

f1=Sin(30) 'f1=0.5000000

Related topics:

Sin

Cos

Tan

Asin

Acos

Atan

45

FastAVR Basic compiler Manual

6.1.1.2.$Asm

Description:

Starts an assembler program subroutine.

Syntax: $Asm

Remarks:

This allows to use inline assembly code.

Always use $Asm with $EndAsm at the end of a block.

Example: $Asm

ldi zl,0x65 st c,zl

$EndAsm

6.1.1.3.$Include

Description:

Instructs the compiler to include a Basic source file from disk at that position.

Syntax:

$Include "Path\BasDoc.bas"

Remarks:

The compiler continues with the next statement in the original source file when it encounters the end of the included file. The result is the same as if the contents of the included file were physically present in the original source file.

Example:

$Include "C:\FastAVR\Init.bas" $Include "C:\FastAVR\Font.bas"

6.1.1.4.$IncludeAsm

Description:

Instructs the compiler to include a ASM source file from disk at the position.

Syntax:

$IncludeAsm "Path\Utils.asm"

Remarks:

The compiler just add included file in to generated ASM output, so only Assembler will compile it.

Example:

$Include "C:\FastAVR\Init.asm"

46

FastAVR Basic compiler Manual

6.1.1.5.$Source

Description:

Tells the compiler to add Basic statements as comments in the ASM file for easy debugging.

Syntax: $Source=ON|OFF

Could be omitted, default is ON.

6.1.2.Processor Configuration

6.1.2.1.$Baud

Description:

Defines the UART (or second UART) baud rate and optional setings. It is similar to bits per second, but includes other non-data bits (start, stop, mark) which add overhead.

Syntax:

$Baud = const [, Parity, DataBits, StopBits]

$Baud2 = const [, Parity, DataBits, StopBits] ' for second UART

INPORTANT! If user will use UART in Default mode (No Parity, 8 data bits, 1 Stop bit) use short mode: $Baud = 9600

Specifying Parity, ...., will add extra routines for handling this extra features!

Remarks:

const is the baud rate number with standard values:

1200, 2400, 4800, 9600, 19200, 38400, 56600,76800,115200 Higher Baud rates are possible on new Mega devices!

Parity N, O, E, M or S

DataBits 5, 6, 7, 8 or 9

StopBits 1 or 2 (in case of 9 DataBits, must be only 1 StopBit)

See the AVR datasheets for valid UART settings for the target microprocessor

Example: $Baud = 9600 $Baud2 = 9600

Related topics:

Baud $Clock

47

FastAVR Basic compiler Manual

6.1.2.2.$Clock

Description:

Defines for the compiler's use the frequency of the microprocessor's crystal input. This is used to calculate compiler-generated constants in the output of a compilation. These constants are used at run time to set the serial port(s) baud rates and for built-in functions which delay by looping.

Syntax: $Clock=const

Remarks:

const is the frequency value of crystal used. (In MHz)

Check for max working frequency for specific microcontroler!

If the value given in the $Clock meta-statement is not the actually implemented microprocessor frequency, the serial port baud rate will be in error. The baud rate must be within a few percent in order for successful and reliable communications over time and temperature variations. Also, the software delay loops and hardware timers will be in error.

Example:

$Clock = 3.6864 'Our crystal is 3.6864MHz

Related topics: $Baud

Baud

6.1.2.3.$Device

Description:

Declares which microprocessor product is the target for the generated code.

Syntax:

$Device=type [, Xram, FirstAdr, XramLength]

Remarks:

type refers to a particular microprocessor product.

The other parameters are optional and define external RAM if present, for those chips which support such.

Example: $Device= 4433

$Device= 8515, Xram, 0, 32k

$Device= ATmega16 $Device= mega16 $Device= m16

$Device= tiny13

48

FastAVR Basic compiler Manual

6.1.2.4.$Stack

Description:

Defines the stack size needed for the program based on the program's design, the needs of the run-time libraries created by the compiler, and the interrupt arrangements. The stack space is created by initialization code generated by the compiler.

The stack must include space for the following:

The worst-case nesting of calls to SUBs and FUNCTIONS (return addresses)

The worst-case nesting of parameters passed to FUNCTIONS

oPassed parameters are stored on stack frames, based on their sizes

The worst-case nesting of the above with their local variables

oThat is, the DIMs inside SUB or FUNCTION or INTERRUPT

Plus space for interrupt procedures and saving of registers at interrupt

The necessary stack size is often underestimated by the programmer. This error causes all kinds and sorts of non-obvious run-time program failures under statistical probabilities of events. For microprocessors with small memories, estimating optimal stack size is a true challenge for the software engineer.

Syntax: $Stack=num

Remarks:

num is the number of memory bytes reserved for stack space.

Example:

$Stack = 32 'stack will be 32 bytes deep

6.1.3.I/O Configuration

6.1.3.1.$Def

Description:

Gives a symbolic name to a particular AVR I/O port and a bit position within that port. This enables user-defined names based on the purpose of the I/O pins of the microprocessor in any given application.

Syntax:

$Def name=PORT.n

Remarks:

name is a valid symbol name for the compiler.

PORT is one of the predefined names of the microprocessor I/O port such as PORTA or PORTB n one digit between 0 and 7 depicting the bit number in the port

Example:

$Def Led=PORT.1

.

.

Set Led

49