139 of 208
ZBasic Language Reference 131 ZX Microcontroller Family 7.5 Setting Device Options By default, the compiler generates code for the ZX-24 device. The target device may be changed either by adding a command line option to your project file or by adding a compiler directive to the first module to be compiled (usually the one containing the Main() routine). Alternatively, you may specify the target device by using the “Device Options…” entry on the Options menu. The resulting dialog contains a combobox with entries for the supported devices. This dialog can also be used to update the firmware in your device or, for some ZX models, to set configuration parameters like the Program Memory EEPROM characteristics or external RAM configuration. 7.6 Downloading Without Using DTR Signaling Normally, the process of downloading a compiled program to a ZX device begins with the downloader toggling the serial port’s DTR line in a designated fashion, causing the ZX device to enter a special command mode. When the ZX 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 ZX 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 ZX 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 ZX responds to the receipt of the ATN character by entering command mode (either automatically, or by way of the ZX 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 at 115.2K baud (checked). If you are using a serial channel that does not support dynamically changing the baud rate, you should uncheck the latter checkbox. On the ZX side, enabling downloading by way of the ATN character can be accomplished in one of two ways. The simplest way is to use the directive Option AtnChar in the first module of your program. Once your program is compiled and downloaded (which, by the way, must be initially accomplished using the traditional DTR-based method), when the device receives the designated ATN character it will automatically invoke the command mode. The second method, which should rarely be needed, is to add code to your application to detect the specified ATN character. When the ATN character is received, your code should invoke the ZX System Library subroutine ZXCmdMode() either with with no parameter or with a parameter value of False. It is important to note that the “Port Speed” setting in the “Execution Options” group box must be set to match the baud rate of the Com1 serial channel of the ZX device. The default Com1 speed is 19.2K baud