Start Back Next End
  
ZBasic Language Reference
120
ZBasic Microcontrollers
Chapter 5 - Compiling for Generic Target Devices
5.1 Overview
Later versions of the ZBasic compiler support compiling ZBasic code for generic target devices, i.e.
microcontrollers that are not ZX devices.  This capability requires a special license (available from Elba
Corp.).  A complete list of the supported generic target devices is given in Appendix B.
A generic target device requires some external circuitry similar to that required for the 40-pin and 44-pin
ZX devices.  See Appendix M for information about the external circuitry that may be required.
If you are familiar with writing applications for ZX devices, there are some minor differences that need to
be considered when making the change to using generic target devices.  The biggest difference is that
the serial console (typically serial channel 1) is not open by default on a generic target device as it is with
a ZX device.  This change was made for two reasons: not all generic target devices have a hardware
UART (e.g. most ATtiny devices) and, secondly, many target devices have a rather small complement of
Flash memory and omitting the code to open the serial channel by default reduces the size of the
executable image.  If you want to use the console serial channel in an application for a generic target
device you can either add code to explicitly open it or, alternately, use the Option ConsoleSpeed directive
to specify the default console baud rate.
A second difference between ZX and generic target applications relates to the RTC.  If your generic target
application includes the RTC, the several ZBasic System Library routines that rely on the presence of the
RTC will behave in accordance with the RTC parameters you've specified.  One example of this is the
ZBasic System Library routine Sleep().  With an RTC present, the units of sleep interval are related to the
period of the RTC that you specify.  If no RTC is included, the units of sleep interval are 1 millisecond. 
Some ZBasic System Library routines, and multi-tasking generally, require the presence of the RTC; if
you refer to them in an application that does not include the RTC the compiler will issue error messages.
5.2 Loading Application Code onto the Target Device
When using a generic target device, there are three possible scenarios for getting the application code
programmed into the device.  The most straightforward scenario is to use a specialized device
programmer (e.g. the Atmel AVRISP) to write the application code to the target.  When compiling code for
this scenario the ZBasic compiler will produce an Intel Hex Format file containing the program image and
(possibly) a second Intel Hex format file containing the data to be written to the device’s EEPROM.  Once
you have these files you can use the command line or GUI utility to use the programming device to write
the program and/or EEPROM data to the device.  Note, also, that the ZBasic IDE provides a means to
specify a command line to execute to facilitate downloading code to a generic device.
The two remaining scenarios are useful only for target devices that support having a bootloader.  In this
case, you would initially program the bootloader into the device using the same type of specialized device
programmer referred to in the previous paragraph.  After the bootloader is installed, the code and
EEPROM images can be programmed into the device by interacting with the bootloader, typically over a
serial or USB link.  If the installed bootloader is a standard ZBasic bootloader (source code for which is
provided with the compiler), the ZBasic IDE can download the application code to the target device in
much the same manner as it does for ZX devices.  Otherwise, if the bootloader is not compatible with the
ZBasic bootloader, the IDE can download the code to the device only if you provide the IDE with a
command line to do so.  If you do not have access to a command line utility for downloading via the
bootloader you’ll have to user whatever application is provided for downloading via that bootloader
outside of the IDE.
5.3 Target Device Parameters
In contrast to ZX devices, where operating parameters such as main clock frequency, RTC frequency,
etc. are all predefined, with a generic target device you must specify several operating parameters to
allow the ZBasic compiler to generate correct code.  The parameters for generic target devices are
specified using the –-device-parameter command line option or the Option DeviceParameter
Previous page Top Next page