ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 8228
Скачиваний: 1
© MCS Electronics, 1995-2007
Remarks
$NOINIT is only needed in rare situations. It will instruct the compiler not to add initialization code. But that means that you need to write your own code then.
$NOINIT was added in order to support boot loaders. But the new $LOADER directive can better be used as it does not require special ASM knowledge.
See also
$LOADER
Example
$NORAMCLEAR
Action
Instruct the compiler to not generate initial RAM clear code.
Syntax
$NORAMCLEAR
Remarks
Normally the SRAM is cleared in the initialization code. When you don't want the SRAM to be cleared(set to 0) you can use this directive.
Because all variables are automatically set to 0 or ""(strings) without the $NORAMCLEAR, using $NORAMCLEAR will set the variables to an unknown value. That is, the variables will probably set to FF but you cannot count on it.
When you have a battery back upped circuit, you do not want to clear the RAM at start up. So that would be a situation when you could use $NORAMCLEAR.
See also
$NOINIT
$PROG
Action
Directive to auto program the lock and fuse bits.
Syntax
$PROG LB, FB , FBH , FBX
page -238-
© MCS Electronics, 1995-2007
Remarks
While the lock and fuse bits make the AVR customizable, the settings for your project can give some problems.
The $PROG directive will create a file with the project name and the PRG extension.
Every time you program the chip, it will check the lock and fuse bit settings and willchange them if needed.
So in a new chip, the lock and fuse bits will be set automatically. A chip that has been programmed with the desired settings will not be changed.
The programmer has an option to create the PRG file from the current chip settings.
The LB, FH, FBH and FBX values are stored in hexadecimal format in the PRJ file. You may use any notation as long as it is a numeric constant.
Some chips might not have a setting for FBH or FBX, or you might not want to set all values. In that case, do NOT specify the value. For example:
$PROG &H20 ,,,
This will only write the Lockbit settings.
$PROG ,,&H30,
This will only write the FBH settings.
LB |
Lockbit settings |
FB |
Fusebit settings |
FBH |
Fusebit High settings |
FBX |
Extended Fusebit settings |
Sometimes the data sheet refers to the Fusebit as the Fusebit Low settings.
The $PROG setting is only supported by the AVRISP, STK200/300, Sample Electronics and Universal MCS Programmer Interface. The USB-ISP programmer also supports the $PROG directive.
When you select the wrong Fuse bit, you could lock your chip. For example when you choose the wrong oscillator option, it could mean that the micro expects an external crystal oscillator. But when you connect a simple crystal, it will not work.
In these cases where you can not communicate with the micro anymore, the advise is to apply a clock signal to X1 input of the micro.
You can then select the proper fusebits again.
When you set the Lockbits, you can not read the chip content anymore. Only after erasing the chip, it could be reprogrammed again.
Once the lockbits and fuse bits are set, it is best to remark the $PROG directive. This because it takes more time to read and compare the bits every time.
See also
Programmers , $PROG
page -239-
© MCS Electronics, 1995-2007
$PROGRAMMER
Action
Will set the programmer from the source code.
Syntax
$PROGRAMMER = number
Remarks
Number A numeric constant that identifies the programmer.
The $PROGRAMMER directive will set the programmer just before it starts programming. When you press F4 to program a chip, the selected programmer will be made active. This is convenient when you have different project open and use different programmers.
But it can also lead to frustration as you might think that you have the 'STK200' selected, and the directive will set it to USB-ISP.
The following values can be used :
Value |
Programmer |
||
0 |
AVR-ISP programmer(old AN 910) |
||
1 |
STK200/STK300 |
||
2 |
PG302 |
||
3 |
External programmer |
||
4 |
Sample Electronics |
||
5 |
Eddie Mc Mullen |
||
6 |
KITSRUS K122 |
||
7 |
STK500 |
||
8 |
Universal MCS Interface |
||
9 |
STK500 extended |
||
10 |
Lawicel Bootloader |
||
11 |
MCS USB |
||
12 |
USB-ISP I |
||
13 |
MCS Bootloader |
||
See also
$PROG
ASM
NONE
Example
page -240-
© MCS Electronics, 1995-2007
$REGFILE
$REGFILE
Action
Instruct the compiler to use the specified register file instead of the selected dat file.
Syntax
$REGFILE = "name"
Remarks
Name |
The name of the register file. The register files are stored in the |
BASCOM-AVR application directory and they all have the DAT extension. |
|
The register file holds information about the chip such as the internal |
|
registers and interrupt addresses. |
|
The register file info is derived from atmel defenition files. |
|
The $REGFILE statement overrides the setting from the Options, Compiler, Chip menu. The settings are stored in a <project>.CFG file.
The $REGFILE directive must be the first statement in your program. It may not be put into an included file since only the main source file is checked for the $REGFILE directive.
It is good practice to use the $REGFILE directive. It has the advantage that you can see at the source which chip it was written for.
The register files contain the hardware register names from the micro. They also contain the bit names. These are constants that you may use in your program. But the names can not be used to dim a variable for example.
Example :
DIM PORTA As Byte
This will not work as PORTA is a register constant.
See also
$SWSTACK , $HWSTACK , $FRAMESIZE
ASM
NONE
Example
$REGFILE = "8515DEF.DAT"
$ROMSTART
page -241-
© MCS Electronics, 1995-2007
Action
Instruct the compiler to generate a hex file that starts at the specified address.
Syntax
$ROMSTART = address
Remarks
Address |
The address where the code must start. By default the first address is 0. |
The bin file will still begin at address 0. |
|
The $ROMFILE could be used to locate code at a different address for example for a boot loader.
It is best to use the new $LOADER directive to add boot loader support.
See also
$LOADER
ASM
NONE
Example
$ROMSTART = &H4000
$SERIALINPUT
Action
Specifies that serial input must be redirected.
Syntax
$SERIALINPUT = label
Remarks
Label |
The name of the assembler routine that must be called when a character is |
needed by the INPUT routine. The character must be returned in R24. |
|
With the redirection of the INPUT command, you can use your own input routines.
This way you can use other devices as input devices.
Note that the INPUT statement is terminated when a RETURN code (13) is received.
By default when you use INPUT or INKEY(), the compiler will expect data from the COM port. When you want to use a keyboard or remote control as the input device you can write a custom routine that puts the data into register R24 once it needs this data.
page -242-
© MCS Electronics, 1995-2007
See also
$SERIALOUTPUT
Example
'----------------------------------------------------------------------------- |
|
--- |
: $serialinput.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrates $SERIALINPUT redirection of serial |
input |
: Mega48 |
'micro |
|
'suited for demo |
: yes |
'commercial addon needed |
: no |
'----------------------------------------------------------------------------- |
|
--- |
|
$regfile = "m48def.dat" |
|
'define used crystal |
|
$crystal = 4000000 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
'default use 10 |
$swstack = 10 |
|
for the SW stack |
'default use 40 |
$framesize = 40 |
|
for the frame space |
|
'dimension used variables |
|
Dim S As String * 10 |
|
Dim W As Long |
'inform the compiler which routine must be called to get serial characters $serialinput = Myinput
'make a never ending loop
Do
'ask for name Input "name " , S
Print S
'error is set on time out
Print "Error " ; Err
Loop
End
'custom character handling routine
'instead of saving and restoring only the used registers
'and write full ASM code, we use Pushall and PopAll to save and restore 'all registers so we can use all BASIC statements
'$SERIALINPUT requires that the character is passed back in R24 Myinput:
Pushall |
'save all |
registers |
'reset counter |
W = 0 |
|
Myinput1: |
'increase counter |
Incr W |
|
Sbis USR, 7 |
' Wait for |
character |
page -243-