ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 8323
Скачиваний: 1
© 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-
© MCS Electronics, 1995-2007
An alternative for the buffer would be to setup a temp buffer and free it once finished. This gives more code overhead.
In older version of BASCOM the start of the frame was used for the buffer but that gave conflicts when variables were printed from an ISR.
See also
DBG
$DEFAULT
Action
Set the default for data types dimensioning to the specified type.
Syntax
$DEFAULT = var
Remarks
Var |
SRAM, XRAM, ERAM |
Each variable that is dimensioned will be stored into SRAM, the internal memory of the chip. You can override it by specifying the data type.
Dim B As XRAM Byte , will store the data into external memory.
When you want all your variables to be stored in XRAM for example, you can use the statement : $DEFAULT XRAM
Each Dim statement will place the variable in XRAM in that case.
To switch back to the default behavior, use $END$DEFAULT
See also
NONE
ASM
NONE
Example
$regfile = "m48def.dat" $crystal = 4000000 $baud = 19200
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
$default Xram
Dim A As Byte , B As Byte , C As Byte
'a,b and c will be stored into XRAM
$default Sram
Dim D As Byte
page -211-
© MCS Electronics, 1995-2007
'D will be stored in internal memory, SRAM
$EEPLEAVE
Action
Instructs the compiler not to recreate or erase the EEP file.
Syntax
$EEPLEAVE
Remarks
When you want to store data in the EEPROM, and you use an external tool to create the EEP file, you can use the $EEPLEAVE directive.
Normally the EEP file will be created or erased, but this directive will not touch any existing EEP file.
Otherwise you would erase an existing EEP file, created with another tool.
See also
$EEPROMHEX
Example
NONE
$EEPROM
Action
Instruct the compiler to store the data in the DATA lines following the $DATA directive in an EEP file.
Syntax
$EEPROM
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.
page -212-
© MCS Electronics, 1995-2007
$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 |
Dta: $eeprom
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 $data
End
$EEPROMHEX
Action
Instruct the compiler to store the data in the EEP file in Intel HEX format instead of binary format.
page -213-
© MCS Electronics, 1995-2007
Syntax
$EEPROMHEX
Remarks
The AVR has build in EEPROM. With the WRITEEEPROM and READEEPROM statements, you can write and read to 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. $EEPROM must be used to create a EEP file that holds the data.
The EEP file is by default a binary file. When you use the STK500 you need an Intel HEX file. Use $EEPROMHEX to create an Intel Hex EEP file.
$EEPROMHEX must be used together with $EEPROM.
See also
$EEPROMLEAVE
Example
$eeprom'the following DATA lines data will go to the EEP file Data 200 , 100,50
$data
This would create an EEP file of 3 bytes. With the values 200,100 and 50. Add $eepromhex in order to create an Intel Hex file.
This is how the EEP filecontent looks when using $eepromhex
:0A00000001020304050A141E283251
:00000001FF
$EXTERNAL
Action
Instruct the compiler to include ASM routines from a library.
Syntax
$EXTERNAL Myroutine [, myroutine2]
Remarks
You can place ASM routines in a library file. With the $EXTERNAL directive you tell the compiler which routines must be included in your program.
See also
page -214-