Facebook Pixel

AN-00057 Designer or ViSi GPIO Pins Picaso

Description This application note shows how to configure and use the GPIO pins of a Picaso display module.
Supported Processor PICASO
Supported Environment Designer, ViSi
Difficulty Easy

 

File Downloads
Files

  Description

This application note shows how to configure and use the GPIO pins of a Picaso display module. 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.

 

Before getting started, the following are required:

and other superseded modules which support the Designer and/or ViSi environments.

 

for non-gen4 displays(uLCD-xxx)

for gen4 displays (gen4-uLCD-xxx)

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 Designer environment enables the user to write 4DGL code in its natural form to program the display module. 4DGL is a graphics oriented language allowing rapid application development, and the syntax structure was designed using elements of popular languages such as C, Basic, Pascal and others. Programmers familiar with these languages will feel right at home with 4DGL.

The purpose of this application note is, besides showing the user how to configure and use the GPIO pins, to introduce the basics of 4DGL through examples.

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 GPIO Pins

Picaso display modules have thirteen general purpose input/output (GPIO) pins available to the user. These are grouped as IO1 to IO5 and BUS0 to BUS7. The five I/O pins (IO1 to IO5) provide flexibility of individual bit operations while the 8 pins (BUS0 to BUS7), known as GPIO BUS, serve collectively for byte wise operations. The IO4 and IO5 pins also act as strobing signals to control the GPIO Bus. The GPIO Bus can be read or written to by strobing IO4/BUS_RD or IO5/BUS_WR (respectively) a low pulse (with a 50 nsec duration or greater). The figure below shows the backside of a uLCD-32PTU and the location of the GPIO pins (IO1 to IO5 and BUS0 to BUS7) in the expansion header. Refer to the datasheet of your display module for the physical pin configuration.

 

 

The following text describes the pins of the uLCD-32PTU and their purpose/s.  Refer to your display module’s datasheet for the appropriate pin description.

 

IO1-IO5 pins:

General purpose I/O pins. Each pin can be individually set as an INPUT or OUTPUT.

 

IO1 pin (Frame Mark pin):

The IO1 pin has two functions. It can be used as a GPIO pin, and it can also be used to detect the start of a Frame. When used as a GPIO pin, simply connect an Input/Output to the IO1 pin of the H1 header. When using IO1 for Frame Mark, simply leave the IO1 pin of the H1 header disconnected, and read the status of IO1 as an Input. Note: frame mark function is not available in uLCD-43P/PT/PCT modules. IO1 is used as a GPIO pin only.

 

IO2 pin (Lithium Battery Status pin):

The IO2 pin has two functions. It can be used as a GPIO pin, and it can also be used to tell when the Lithium battery has reached a low level (3.7V) and needs to be charged. When used as a GPIO pin, simply connect an Input/Output to the IO2 pin on the H1 header. When using IO2 for Battery Status, simply leave the IO2 pin on the H1 header disconnected, and read the status of IO2 as an Input. Note: battery status detection function is not available in uLCD-43P/PT/PCT modules. IO2 is used as a GPIO pin only.

 

IO3 pin (Peripheral Supply pin):

IO3 is controllable via the processor, or via the H2 Interface pin driven by an external circuit. If IO3 is set as OUTPUT and driven HIGH the μSD and Display are enabled, and disabled when driven LO. Set as INPUT to use an external circuit to drive this pin. Note: peripheral supply function is not available in uLCD-43P/PT/PCT modules. IO3 is used as a GPIO pin only.

 

IO4/BUS_RD pin (GPIO IO4 or BUS_RD pin):

General Purpose IO4 pin. Also used for BUS_RD signal to read and latch the data in to the parallel GPIO BUS0 to BUS7.

 

IO5/BUS_WR pin (GPIO IO5 or BUS_WR pin):

General Purpose IO5 pin. Also used for BUS_WR signal to write and latch the data to the parallel GPIO BUS0 to BUS7.

 

BUS0-BUS7 pins (GPIO 8-Bit Bus):

8-bit parallel General purpose I/O Bus.

Note: All GPIO pins are 5.0V tolerant.

 

The GPIO Pin Functions

The following sections will discuss how to configure the GPIO pins either as input or output, how to control the logic level of a pin (when set as an output), and how to read the logic level of a pin (when set as an input). Again, the 5 I/O pins (IO1 to IO5) provide flexibility of individual bit operations while the 8 pins (BUS0 to BUS7), known as GPIO bus, serve collectively for byte wise operations.  The term bus here, therefore, is used to collectively refer to the pins BUS0 to BUS7, while the term pin refers to any GPIO pin.

 

A GPIO function, when prepended with pin_, is used for configuring, setting, or reading logic states from a pin. On the other hand, a GPIO function prepended with bus_ is used for configuring, controlling, or reading logic levels from a group of pins - in this case the GPIO bus.

Bus Mode

Bus mode defines how the bus will be used – as an input or as an output. To set the GPIO bus mode, use the function

 

The lower 8 bits of arg1 are placed in the BUS direction register. The upper 8 bits of arg1 are ignored.

 

Example:

 

In binary, 0xAA (hexadecimal) is equal to 10101010.

 

To set all of the bus pins as inputs:

 

To set all of the bus pins as outputs:

 

Pin Mode

To individually set the mode of any of the IO1 to IO5 pins use the function:

 

For instance, to set IO1 as an output:

 

To set I03 as an input:

 

Control the GPIO Bus

After having configured the bus as an output, the pins can now be set to high or low using the function

 

The lower byte of arg1 is placed on the 8-bit-wide bus. The upper byte is ignored. Note that any bus pin set as an input is not affected.

To illustrate:

 

In binary, 0x15 is equal to 00010101.

Control the GPIO Pins

The pins can also be set to high or low individually, without affecting the state of the other pins, using the function

 

This function outputs a high level (logic 1) on the specified pin previously set as an output. If the pin is not already set as an output, it is automatically set as such. Possible values for pin are shown below:

 

Example:

 

To individually set the bus pins to low, use the function

 

This function outputs a low level (logic 0) on the specified pin previously set as an output. If the pin is not already set as an output, it is automatically set as such. Possible values for pin are shown below:

 

Example:

 

Read the State of a Bus

After having configured the bus as an input, its state can be read with the function:

 

The function returns the state of the bus as an eight bit value and assigns it to the lower byte of the assigned variable.

Example:

 

The lower byte of var1 will get loaded with the state of the bus.

 

Read the State of a Pin

After having configured a pin as an input, its state can be read with the function:

 

This function reads the logic state of the pin. It returns a logic 0 (0x0000) or a logic 1 (0x0001).

Example:

 

The variable var1 will have a value of either 0x0000 or 0x0001, depending on the logic state of IO1.

 

A Simple Project – IO1 as an Input

Description

This simple project reads the logic state of the IO1 pin which was configured as an input and connected to a tact switch (see schematic in Figure 17). If the logic state of IO1 is 1, the screen displays a dark reddish circle. If the logic state of IO1 is 0, the screen displays a red circle. The screen (uLCD-32PTU, portrait orientation in this example) will look like as shown below.

 

 

 

Program Code

Below is a code for the project. Comments are added to guide the user.

 

Attached is a zipped file of the code in Figure 19. A brief explanation now follows. Lines previously explained are bypassed.

 

Lines 10 to 19 make up the repeat…forever loop. It begins with

 

and ends with

 

Instructions in between these lines are executed forever.

The if-else-endif Statement

Lines 11 to 18 now make up the if-else-endif statement. The program makes use of the if-else-endif statement to make a decision. Below is the syntax or format:

 

First the program tests a condition. If the condition is found to be true, the program executes a set of instructions. If not (else), the program executes another set of instructions. In Figure 19, the condition being tested is the logic state of IO1_PIN. If it is at logic 0

The program prints “ON” and draws a red solid circle on the screen.

 

Else, if IO1_PIN is at logic 1 or for any other condition,

 

the program prints “OFF” and draws a dark red solid circle on the screen.

 

The if-else-endif statement ends with the line

 

Now play with the tact switch and the colour of the circle should change accordingly. To learn more about the if-else-endif statement and loops, consult the 4DGL Programmers Reference Manual .

Share: