ZBasic Language Reference
146
ZBasic Microcontrollers
There are several aspects of this example command that are useful to discuss. Firstly, note the use of
the macro $(target_device). Before executing the command, this macro is replaced with the actual
target name. For example, if the selected target were the mega644p, the macro would be replaced with
ATmega644P. Additionally, the macro $(project.base) will be replaced by the full path of the project
file but with the extension removed. This makes it simple, in most cases, to refer to the code and
EEPROM image files in a way that should work with any project.
An example of a device-specific download command is shown below. This example illustrates how you
can define a "macro", in this case named atprogram, that can be used as the downloader command.
This is particularly useful if you have several devices for which you want to use the same downloader
command.
atprogram=atprogram.exe -t avrispmk2 -i isp -cl 1MHz -d $(target_device)
erase program -fl --verify -f $(project.base).hex --format hex program -ee -f
$(project.base).eep --format hex
command.project.ATmega1284P.go=$(atprogram)
Some downloader applications do not accept device names like ATmega644P, e.g. it may require using
m644P instead. In such a case you can can provide lines in the User Options file to map the device
names to alternate names. For example, consider a fictitious Super Downloader application that
requires names like m644P, m1284P, etc. For this case we can create mappings of the device names as
shown below and then use a nested macro name to yield the mapped device names. In this particular
case, the prefix sd. was chosen to distinguish mappings for the Super Downloader application from
mappings for other downloading applications. The actual prefix to use is unimportant as long as it is
unique.
sd.ATmega644P=m644P
sd.ATmega1284P=m1284P
command.project.avr.go=superDownloader.exe com1 -d$(sd.$(target_device)) -
f$(project.base).hex
Before executing the command line, macros in it, if any, are recursively expanded. On the first pass,
$(target_device) is replaced with the current target (say, ATmega644P). Then, on the second pass
the macro $(sd.ATmega644P) is replaced by m644P.
9.8 Downloading Without Using DTR Signaling
Normally, the process of downloading a compiled program to a ZBasic device (one containing a ZBasic-
compatible bootloader or a VM) begins with the downloader toggling the serial ports DTR line in a
particular fashion, causing the ZBasic device to enter a special command mode. When the device enters
command mode in this fashion, it sets the baud rate of the Com1 serial channel to 115.2K baud and waits
for commands from the host. Meanwhile, the downloader changes the baud rate of the PC serial port to
match the 115.2K baud rate and then begins sending the device a series of commands to effect the
downloading of the compiled program. Finally, when the download has completed the downloader
toggles DTR again causing the device to reset and begin running the downloaded program.
The downloading procedure described above works in most situations but there are some cases where it
wont work. In particular, if a PC serial channel doesnt support DTR or doesnt support toggling DTR
quickly enough to be recognized as the go to command mode signal, then the procedure above cannot
be used. Additionally, if the baud rate of the serial channel cannot be changed dynamically (for example
when using a radio link like BlueTooth or XBee), the procedure above cannot be used because of the
required baud rate changes.
In cases where the normal DTR-triggered downloading procedure cannot be used, an alternate procedure
can be used to effect a download. The alternate procedure requires a special configuration of the
downloader and a matching special configuration of the ZX device. Instead of toggling DTR, the alternate
procedure initiates the download procedure by sending a pre-determined character (known as the ATN
character) to the device. The ZBasic device responds to the receipt of the ATN character by entering
|