Facebook Pixel

AN-00198 Designer or ViSi 4DGL Strings Print Formats – the Long Binary Format Specifier

Description This application note discusses how the long binary format specifier is used with the str_Printf(…) function. This application note is intended for use in the Workshop 4 – Designer environment. The 4DGL code of the Designer project can be copied and pasted to an empty ViSi project and it will compile normally. The code can also be integrated to that of an existing ViSi project.
Supported Processor PICASO, DIABLO16
Supported Environment Designer, ViSi
Difficulty Medium

File Downloads
Files

  Description

There are two binary format specifiers:

 

This application note discusses how the long binary format specifier is used with the str_Printf(…) function. This application note is intended for use in the Workshop 4 – Designer environment. The 4DGL code of the Designer project can be copied and pasted to an empty ViSi project and it will compile normally. The code can also be integrated to that of an existing ViSi project.

This application note requires:

and other superseded modules which support the ViSi Genie environment

 

Visit www.4dsystems.com.au/products to see the latest display module products that use the Diablo16 processor. The display module used in this application note is the uLCD-32PTU, which is a Picaso display. This application note is applicable to Diablo16 display modules as well.

for non-gen4 displays(uLCD-xxx)

for gen4 displays (gen4-uLCD-xxx)

  • micro-SD (µSD) memory card
  • Workshop 4 IDE (installed according to the installation document)
  • Any Arduino board with a UART serial port
  • 4D Arduino Adaptor Shield (optional) or connecting wires
  • Arduino IDE

When downloading an application note, a list of recommended application notes is shown. It is assumed that the user has read or has a working knowledge of the topics presented in these recommended application notes.

  Application Overview

The application note Designer or ViSi Strings and Character Arrays explains how 4DGL strings and character arrays are stored in and accessed from memory. It also differentiates between word-aligned and byte-aligned pointers. Furthermore, it introduces the use of the function str_Printf(…).

 

The application note Designer or ViSi 4DGL Strings Print Formats – the String and Character Format Specifiers shows how the string and character format specifiers (“%s” and “%c”, respectively) are used. Also, it covers the topics “Automatic Advancing of the Pointer” and “Dynamic Construction of the Format Specifier”.

 

This application note now further explains the use of the str_Printf(…) function together with the long binary format specifier.

 

  Setup Procedure

For instructions on how to launch Workshop 4, how to open a Designer project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note

Designer Getting Started - First Project

For instructions on how to launch Workshop 4, how to open a ViSi project, and how to change the target display, kindly refer to the section “Setup Procedure” of the application note

ViSi Getting Started - First Project for Picaso and Diablo16

 

  Create a New Project

For instructions on how to create a new Designer project, please refer to the section “Create a New Project” of the application note

Designer Getting Started - First Project

For instructions on how to create a new ViSi project, please refer to the section “Create a New Project” of the application note

ViSi Getting Started - First Project for Picaso and Diablo16

 

  Design the Project

The Format Specifier “%lb”

The format specifier “%lb” is used for displaying long binary numbers. A long binary in 4DGL is a 32-bit (or 4-byte) value, the range of which is from 0x0000 0000 to 0xFFFF FFFF (0  to 232-1) or, in binary, from 0b00000000 00000000 00000000 00000000 to 0b11111111 11111111 11111111 11111111. Consider the code snippet shown below.

 

The output of the above code is:

 

The function umul_1616(…) performs an unsigned multiplication of two 16-bit values, placing the 32-bit result in a two-word array. In this example, the two 16-bit values are 500 and 2000. When multiplied together the product of these is 1000000 in decimal, 0xF4240 in hexadecimal, or 0b11110100001001000000 in binary. If we print the contents of the word array val32 in hexadecimal format,

 

we get,

 

We analyse the contents of the word array val32.

 

 

Note also that the pointer was advanced by four bytes after the long binary value was printed.

 

Therefore, the long binary format specifier, “%lb”, causes the str_Printf(…) function to get four bytes from the address starting at that pointed to by the byte-aligned pointer. str_Printf(…) then treats these four bytes as a 32-bit value and prints it in binary.

 

The 32-bit data found starting at address 16, in this example, is “0b11110100001001000000” or “0x000F 4240”, the decimal equivalent of which is “1000000”.

 

The Width and Zero Flag Sub-specifiers

The Width Sub-specifier

Consider the output below.

 

The code for the first line is

 

The code for the second line is

 

Note that in the second line, the number has twelve spaces preceding it. This is because the width specifier was used in the str_Printf(…) function.

 

Here the width specifier value is 32, so the field width of the printed figure is thirty-two bits, and since the number is only 20 binary bits wide, it is preceded by 12 space characters.

 

The Zero Flag Sub-specifier

Suppose we want the number to be preceded with zeros rather than spaces, we would write,

Here the width sub-specifier is preceded by the zero flag sub-specifier, which would cause the number to be left-padded with zeros instead of spaces. To illustrate,

Therefore, without the zero flag sub-specifier, the default character with which a number, printed with a certain field width, is to be left-padded is the space character.  The width and zero flag sub-specifiers can be used with other format specifiers besides the long binary format specifier.

The Designer project for the discussions on the long binary format specifier and the width and zero flag sub-speficiers is “stringsBasics9.4dg” (attached).

Dynamic Construction of the Format Specifier

As was shown in the application note Designer or ViSi 4DGL Strings Print Formats – the String and Character Format Specifiers, the format specifier argument of the str_Printf(…) function can also be a word-aligned string pointer, allowing dynamic construction of the printing format. We will now use dynamically constructed format specifiers to come up with the formatted display output shown below, which is similar to that in the last example.

The code snippet for the above output can be implemented using dynamically constructed format specifiers, as shown below.

Where format is a word array declared at the start of the code.

The Designer project for the remaining part of this application note is “stringsBasics9b.4dg” (attached). Although the examples are simple, the ability to construct a format specifier dynamically can be a powerful tool.

  Run the Program

For instructions on how to save a Designer project, how to connect the target display to the PC, how to select the program destination, and how to compile and download a program, please refer to the section “Run the Program” of the application note

Designer Getting Started - First Project

For instructions on how to save a ViSi project, how to connect the target display to the PC, how to select the program destination, and how to compile and download a program, please refer to the section “Run the Program” of the application note

ViSi Getting Started - First Project for Picaso and Diablo16

The uLCD-32PTU and uLCD-35DT display modules are commonly used as examples, but the procedure is the same for other displays.

Share: