Page 150 of 229 Start Back Next End ZBasic Language Reference 140 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. If your downloader application does not accept device names like ATmega644P (e.g. it may require using m644P instead), 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 port’s 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 won’t work. In particular, if a PC serial channel doesn’t support DTR or doesn’t 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 command mode (either automatically, or by way of the ZBasic System Library subroutine ZXCmdMode). Once in command mode, the downloader can optionally send a command to instruct the device to switch to 115.2K baud for the download; otherwise the downloading is done at the prevailing baud rate. Finally, once the download has completed, the downloader sends a command telling the device to reset thus commencing execution of the downloaded program. The ATN character is set in the ZBasic IDE using the dialog invoked by choosing the Serial Port Options entry on the Options menu. In the “Download Options” groupbox, you’ll find a checkbox captioned “Use ATN character”. When that checkbox is checked, two more controls become enabled. The first is an edit box with an accompanying spin control that allows you to specify the desired ATN character (the range for which is 1 to 31 decimal). Below the enabling checkbox, another checkbox captioned “Change speed for download” allows you to control whether the download is done at the prevailing speed (unchecked) or