Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
BASCOM AVR, help reference (2007).PDF
Скачиваний:
286
Добавлен:
12.08.2013
Размер:
17.02 Mб
Скачать

© MCS Electronics, 1995-2007

Wait 2

Cls Text ' clear the text

End

'This label holds the mage data Plaatje:

'$BGF will put the bitmap into the program at this location $bgf "mcs.bgf"

'You could insert other picture data here

$BOOT

Action

Instruct the compiler to include boot loader support.

Syntax

$BOOT = address

Remarks

address The boot loader address.

Some new AVR chips have a special boot section in the upper memory of the flash. By setting some fuse bits you can select the code size of the boot section.

The code size also determines the address of the boot loader.

With the boot loader you can reprogram the chip when a certain condition occurs. The sample checks a pin to see if a new program must be loaded.

When the pin is low there is a jump to the boot address.

The boot code must always be located at the end of your program.

It must be written in ASM since the boot loader may not access the application flash rom. This because otherwise you could overwrite your running code!

The example is written for the M163. You can use the Upload file option of the terminal emulator to upload a new hex file. The terminal emulator must have the same baud rate as the chip. Under Options, Monitor, set the right upload speed and set a monitor delay of 20. Writing the flash take time so after every line a delay must be added while uploading a new file.

The $BOOT directive is replaced by $LOADER. $LOADER works much simpler. $BOOT is however still supported.

See also

$LOADER

Example

See BOOT.BAS from the samples dir. But better look at the $LOADERdirective.

page -206-

© MCS Electronics, 1995-2007

$CRYSTAL

Action

Instruct the compiler to override the crystal frequency options setting.

Syntax

$CRYSTAL = var

Remarks

var

A numeric constant with the Frequency of the crystal.

 

 

The frequency is selectable from the Compiler Settings. It is stored in a configuration file. The $CRYSTAL directive overrides this setting.

It is best to use the $CRYSTAL directive as the used crystal frequency is visible in your program that way.

The $CRYSTAL directive only informs the compiler about the used frequency. It does not set any fuse bit. The frequency must be know by the compiler for a number of reasons. First when you use serial communications, and you specify $BAUD, the compiler can calculate the proper settings for the UBR register. And second there are a number of routines like WAITMS, that use the execution time of a loop to generate a delay. When you specify $CRYSTAL = 1000000 (1 MHz) but in reality, connect a 4 MHz XTAL, you will see that everything will work 4 times as quick.

Most new AVR chips have an internal oscillator that is enabled by default. Checkthe data sheet for the default value.

See also

$BAUD , BAUD , CONFIG CLOCKDIV

Example

$regfile = "m48def.dat" $crystal = 4000000 $baud = 19200

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Print "Hello world"

End

$DATA

Action

Instruct the compiler to store the data in the DATA lines following the $DATA directive, in code memory.

page -207-

© MCS Electronics, 1995-2007

Syntax

$DATA

Remarks

The AVR has built-in EEPROM. With the WRITEEEPROM and READEEPROM statements, you can write to and read from the EEPROM.

To store information in the EEPROM, you can add DATA lines to your programthat hold the data that must be stored in the EEPROM.

A separate file is generated with the EEP extension. This file can be used to programthe EEPROM.

The compiler must know which DATA must go into the code memory and which into the EEPROM memory and therefore two compiler directives were added.

$EEPROM and $DATA.

$EEPROM tells the compiler that the DATA lines following the compiler directive must be stored in the EEP file.

To switch back to the default behavior of the DATA lines, you must use the $DATA directive.

The READ statement that is used to read the DATA info may only be used with normal DATA lines. It does not work with DATA stored in EEPROM.

Do not confuse $DATA directive with the DATA statement.

So while normal DATA lines will store the specified data into the code memory of the micro which is called the flash memory, the $EEPROM and $DATA will cause the data to be stored into the EEPROM. The EEP file is a binary file.

See also

$EEPROM , READEEPROM , WRITEEEPROM , DATA

ASM

NONE

Example

'-----------------------------------------------------------------------------

 

--

: (c) 1995-2005, MCS Electronics

'copyright

'micro

: AT90S2313

'suited for demo

: yes

'commercial addon needed

: no

'purpose

: demonstrates $DATA directive

'-----------------------------------------------------------------------------

 

--

 

$regfile = "2313def.dat"

 

$baud = 19200

' 4 MHz crystal

$crystal = 4000000

Dim B As Byte

'now B will be 1

Readeeprom B , 0

End

 

page -208-

© MCS Electronics, 1995-2007

Dta: $eeprom

Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 $data

End

$DBG

Action

Enables debugging output to the hardware UART.

Syntax

$DBG

Remarks

Calculating the hardware, software and frame space can be a difficult task. With $DBG the compiler will insert characters for the various spaces.

To the Frame space 'F' will be written. When you have a frame size of 4, FFFF will be written.

To the Hardware space 'H' will be written. If you have a hardware stackspace of 8, HHHHHHHH will be written to this space.

To the software space 'S' will be written. If you have a software stack space of 6, SSSSSS will be written.

The idea is that when a character is overwritten, it is being used. So by watching these spaces you can determine if the space is used or not.

With the DBG statement a record is written to the HW UART. The record must be logged to a file so it can be analyzed by the stack analyzer.

Make the following steps to determine the proper values:

Make the frame space 40, the softstack 20 and the HW stack 50

Add $DBG to the top of your program

Add a DBG statement to every Subroutine or Function

Open the terminal emulator and open a new log file. By default it will have the name of your current program with the .log extension

Run your program and notice that it will dump information to the terminal emulator

When your program has executed all sub modules or options you have build in, turn off the file logging and turn off the program

Choose the Tools Stack analyzer option

A window will be shown with the data from the log file

Press the Advise button that will determine the needed space. Make sure that there is at least one H, S and F in the data. Otherwise it means that all the data is overwritten and that you need to increase the size.

Press the Use button to use the advised settings.

As an alternative you can watch the space in the simulator and determine if the characters are overwritten or not.

page -209-

© MCS Electronics, 1995-2007

The DBG statement will assign an internal variable named ___SUBROUTINE Because the name of a SUB or Function may be 32 long, this variable uses 33 bytes!

___SUBROUTINE will be assigned with the name of the current SUB or FUNCTION.

When you first run a SUB named Test1234 it will be assigned with Test1234

When the next DBG statement is in a SUB named Test, it will be assigned with Test. The 234 will still be there so it will be shown in the log file.

Every DBG record will be shown as a row.

The columns are:

Column

Description

Sub

Name of the sub or function from where the DBG was used

FS

Used frame space

SS

Used software stack space

HS

Used hardware stack space

Frame space

Frame space

Soft stack

Soft stack space

HW stack

Hardware stack space

 

 

The Frame space is used to store temp and local variables.

It also stores the variables that are passed to subs/functions by value.

Because PRINT , INPUT and the FP num<>String conversion routines require a buffer, the compiler always is using 24 bytes of frame space.

When the advise is to use 2 bytes of frame space, the setting will be 24+2=26.

For example when you use : print var, var need to be converted into a string before it can be printed or shown with LCD.

page -210-