Facebook Pixel

AN-00050 Designer or ViSi Loop Back Testing with a PIC MCU

Description This document is about basic asynchronous serial interfacing of the 4D display module with the PIC18F45K20. It contains a simple but helpful information on how to test the data information being sent by the PICASO serial port to a host controller in particular the MICROCHIP PIC18F34K20. The system is arranged such that the information data is sent by the PICASO display. This information is then received by the PIC18F45K20 and sends it back for the screen to display.
Supported Processor PICASO
Supported Environment Designer, ViSi
Difficulty Medium

 

 

File Downloads
Documentation
Files

Description

This Application Note is intended to demonstrating and teaching the user how to test the interface between the 4D PICASO display modules with the MICROCHIP PIC microcontrollers. This application is intended for use in the 4D Workshop 4 – Designer environment. The tools needed includes the following;

Before getting started, the following are required:

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

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

This document is about basic asynchronous serial interfacing of the 4D display module with the PIC18F45K20.  It contains a simple but helpful information on how to test the data information being sent by the PICASO serial port to a host controller in particular the MICROCHIP PIC18F34K20. The system is arranged such that the information data is sent by the PICASO display. This information is then received by the PIC18F45K20 and sends it back for the screen to display.

 

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

To create a simple program that will be able activate and initialize the PICASO serial ports, we will need to use some commands enlisted in the PICASO 4DGL Internal Functions.

In particular, we will be using the Serial (UART) Communications Functions. The PICASO serial communications is relatively easy to use. Since the PICASO display module only uses the Transmit(TX), Receive(RX) and ground pins of the standard serial communication port, it is relative easy to use. Before going further it is good to remember that the PICASO display module has two serial communications port which can be simultaneously used to communicate with other serial capable controllers or devices.

There are several important settings of a serial communications that are very important to have an effective and correct data communications. First thing to consider is the BAUD RATE, the baud rate is simply the rate of transfer from and to the device. If there exist a mismatch in the baud rate of two serially coupled devices – the serial communication will be erroneous.

Secondly, it is also good to consider the number of bytes that shall be transferred at the instance of communication. This is important so that we display device will be programmed to have a particular buffer which is capable to save a series of bytes continuously. This size of the temporary data storage, which is termed as a buffer, will determine the size of the data that can be stored.

 

Below is a program that will initialize and set-up the serial communication port of the 4D display module.

From the program above it is clearly seen that during the start of the program main(), the serial communications port 0 is being setup to communicate with the PIC host controller. It is set to transmit and receive at a baud rate of 9600.

 

In this program, see the statement com_SetBaud(COM0, 960). Notice that with this function the serial communication port 0 is set with a baud rate of 9600. In this 4DGL function the actual desired baud rate is written but with the real baud /10.

Moving to the next part of the program, notice how simple the initialization of the serial com port is done. The initialization statement com_Init() includes a variable array buf, buffer size and a qualifier. The qualifier is the part of the initialization that if specified, the PICASO serial communication will not start unless the qualifier is received. If the qualifier is set to ‘0’, this implies that no start bit qualifier is specified.

 

Next, we have the while loop. The while generates the data that is to be sent to the serial lines.

 

The variable n is incremented starting from zero until it reaches the limit of 0xFF hex limit. Each time the value of n is incremented starting from zero, this are sent to the serial communication port zero TX. The sending of data is done with the serout(n) function in line number 13.

 

After sending this value of n, it is also displayed in the screen to show what value is currently being sent over the serial TX. Following the sending routine is the receiving of data bytes coming from the host controller. With the aid of the serin() function we are able to get the buffered RX data. This is being read and displayed into the screen.

An if-else routine is used to determine if there are real data being received. If the PICASO display module serial RX is left hanging, it results to a -1 value which means that there are no data at the moment. If the serin() results to a value of -1 – the program displays a message indicating that there are no data in the serial RX line.

 

On the other hand if a data is receive then this data is printed in the display with a message “Data Received” preceding it.

 

After compiling and download of the program, the PICASO display module will show the following output. If the MICROCHIP host controller is not connected during test:

 

This means that the PIC18F is not connected and that the serial connections are left hanging or disconnected. On the other hand, if we connect the PIC18F to the display module, we will have a result in the display similar to the one below.

 

During the process of communication the delay caused by the pause(500) results to a lag in the retransmitted value. This is also caused by the operation manner of running a program in microcontrollers wherein the statements of a program is run one step at a time. Although there is a lag in data it does not mean that it is incorrect. The series of data are being buffered by the display module and are being displayed on the screen. On the other hand the PIC18F controller continuously receive and re-transmits all data being received from the display module.

 

The PIC 18F45K20 Loopback program

The 18F45k20 host controller loopback program starts with the declaration of its configuration files. The following configurations were used:

 

The main body of the PIC18F45K20 loopback program is relatively easy to understand since it only uses the custom-defined function sendbyte() to transmit a single byte data and the receive() function which continuously receives the input data to the PIC18F45k20. The port D of the demo board was used to display the received value and as an indicator of data reception.

 

A header file is written to initialize the host controller’s serial communication port. This initialization configuration is included in the UART.h header file. This header has the definition for the functions sendbyte () and receive ().

Referring to the UART.h contents on the opposite column. We could see a function uart(). This function can be called in the main program to configure the serial communication port.

The routines to receive the data from the display is already included in the header file. This receive routine readily accepts data from the display module and return this as a value ‘data‘. Furthermore, the sendbyte() function is able to send a single byte at every function call.

 

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 (this option is not available for Goldelox displays), 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 display module is commonly used as the example, but the procedure is the same for other displays.

 

PICASO Serial interface with the Microchip PIC18F45K20 Block Diagram

The flow of data in this setup begins with the PICASO display. The PICASO display generates a counting number that begins at zero and passes this to the PIC microcontroller. As the controller receives this stream of data is also sends it back to the display thereby creating a LOOPBACK of data. It will be noticeable during the test that there a significant delay in the data streaming since both of the controllers operate in its own time-base set by the oscillator. Although the microcontrollers have different sets of oscillator frequency they can be set to a particular baud rate that enable them to have correct data transmitted and received.

Share: