Intermediate
30 min

Upgrade your data presentation with SMA-B500LE and PIC18F97J94

Data insights, one segment at a time!

BarGraph 3 Click with CLICKER 4 for PIC18F

Published Feb 12, 2024

Click board™

BarGraph 3 Click

Development board

CLICKER 4 for PIC18F

Compiler

NECTO Studio

MCU

PIC18F97J94

Our 5-segment red bar graph display is designed to provide a straightforward and precise way to visualize data, making it ideal for various applications where simplicity and clarity are essential

A

A

Hardware Overview

How does it work?

BarGraph 3 Click is equipped with a five-segment LED bar graph display, notable for its strong and uniform illumination of the segments. When it comes to driving an array of LED segments, using so-called shift-register ICs is almost unavoidable. This Click board™ uses a single 74HC595 IC, a tri-state, serial-in, parallel-out, 8-bit shift-register with output latch, from Texas Instruments. It is used to drive the SMA-B500LE a monochrome (red) 5 segment bar graph array, from American Opto Plus LED corporation. The 74HC595 ICs is comprised of a D-type internal storage register, and a serial-to-parallel shift register, both 8 bits wide. Each of these registers has its own clock line, making it possible to clock in the desired data in, and then clock it out to the parallel output pins when needed. The SMA-B500LE bar graph LED array has 5 red LED segments. Each segment contains three LEDs, with their cathodes connected in a single point and routed out as the single common cathode pin. This results with a bar graph display that has only six pins, even though it uses 15 LED elements in total. Similarly, all the anodes of the LED segments are routed to a single pin, which is connected to the drain of the P channel MOSFET, while its source is connected to the VCC. Driving the gate of the MOSFET using the PWM pin of the mikroBUS™ allows dimming of the LED bar graph display, by changing the pulse

width of the applied PWM signal. The Click board™ communicates with the host MCU over the SPI interface, routed to the mikroBUS™ MOSI and SCK pins, labeled as SDI and SCK on this Click board™, respectively. Five bits of information are pushed through the serial data input pin (DS) of the 74HC595 IC, routed to the SDI pin. The construction of the SPI interface is such that it operates with 8-bit long words, so the whole data word needs to be clocked in before it is latched on the output. However, the values of the bits that correspond to the non-connected pins of the 74HC595 IC will be disregarded. The Output Enable pin (#OE) is routed to the AN pin of the mikroBUS™, and it is labeled as OE. If this pin is at the HIGH logic level, the outputs Q0 to Q7S of the 74HC595 IC will be set at HIGH-Z (high impedance mode) meaning that they will become disconnected. Regardless of the logic state on other pins, the outputs will not change from this state, until #OE is brought down to a LOW logic level. Memory content and the logic states at the output pins will be unaffected, meaning that the OE can be used to turn the segments of the bar graph on or off without affecting their states (like a simple SPST switch in series with the LED segment of the bar graph). After the data word has been clocked in, the master SPI clock should be stopped, and the CS pin should be driven

to a HIGH logic level. The CS pin of the mikroBUS™ is routed to the STCP pin of the 74HC595 IC. A rising edge on the STCP input pin of the 74HC595 IC will latch the data from the internal storage register to the output pins, changing the states of its parallel output pins (Q0 to Q7). If a specific bit in the internal storage is 0, the state on the appropriate pin of the 74HC595 IC will become LOW. With their anodes connected to the positive voltage level already (provided that the P-type MOSFET is open), the segment will be lit. This means that the logical 0 lights up a segment, while 1 turns it off. The #MR pin is used to clear the data in the internal storage register of the 74HC595 IC. The LOW logic level on this pin will clear the content of this storage register, but it will not turn off the outputs which are already activated. The #MR pin is routed to the RST pin of the mikroBUS™ and it is pulled to a HIGH logic level by the onboard resistor. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

BarGraph 3 Click top side image
BarGraph 3 Click bottom side image

Features overview

Development board

Clicker 4 for PIC18F is a compact development board designed as a complete solution to build your own gadgets with unique functionalities quickly. It features a PIC18F97J94MCU, four mikroBUS™ sockets for Click boards™ connectivity, power management, and more, and it is a perfect solution for the rapid development of many different types of applications. At its core is an 8-bit PIC18F97J94 MCU, a powerful microcontroller produced by Microchip, based on the high-performance CPU with two external clock modes, up to 64MHz. It

provides sufficient processing power for the most demanding tasks, allowing Clicker 4 to adapt to any specific application requirements. Besides two 1x20 pin headers, four improved mikroBUS™ sockets represent the most distinctive connectivity feature, allowing access to a huge base of Click boards™, growing on a daily basis. Each section of Clicker 4 is clearly marked, offering an intuitive and clean interface. This makes working with the development board much simpler and, thus, faster. The usability of Clicker 4 doesn’t end with its ability

to accelerate the prototyping and application development stages: it is designed as a complete solution that can be implemented directly into any project, with no additional hardware modifications required. Four mounting holes [4.2mm/0.165”] at all four corners allow simple installation by using mounting screws. For most applications, a nice, stylish casing is all that is needed to turn the Clicker 4 development board into a fully functional, custom design.

Clicker 4 for PIC18F double image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

3862

Used MCU Pins

mikroBUS™ mapper

Output Enable
PA5
AN
Data Clear
PJ4
RST
SPI Chip Select
PL1
CS
SPI Clock
PD6
SCK
NC
NC
MISO
SPI Data IN
PD4
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
PWM Dimming Control
PG4
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

BarGraph 3 Click Schematic schematic

Step by step

Project assembly

Clicker 4 for STM32F4 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the CLICKER 4 for PIC18F as your development board.

Clicker 4 for STM32F4 front image hardware assembly
Rotary O 2 Click front image hardware assembly
Clicker 4 STM32F4 MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for BarGraph 3 Click driver.

Key functions:

  • bargraph3_display - This function control the display

  • bargraph3_set_pwm - This function set PWM

  • bargraph3_enable - Functions for enable the chip.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * \file 
 * \brief BarGraph3 Click example
 * 
 * # Description
 * This application used to create various types of VU meters, 
 * status indicators, different types of counters and similar devices.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initialization driver init, enable device and set PWM
 * 
 * ## Application Task  
 * Counter passes through the loop and logs the value of the 
 * counter on the bargraph display.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "bargraph3.h"

// ------------------------------------------------------------------ VARIABLES

static bargraph3_t bargraph3;
static log_t logger;


void application_init ( void )
{
    log_cfg_t log_cfg;
    bargraph3_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    bargraph3_cfg_setup( &cfg );
    BARGRAPH3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    bargraph3_init( &bargraph3, &cfg );
    
    bargraph3_enable( &bargraph3, BARGRAPH3_DEVICE_ENABLE );
    bargraph3_set_pwm( &bargraph3, BARGRAPH3_DEVICE_ENABLE );
    Delay_ms( 500 );
}

void application_task ( void )
{
   uint8_t bargraph_cnt;
    
    for ( bargraph_cnt = 0; bargraph_cnt <= 5; bargraph_cnt++ )
    {
        bargraph3_display( &bargraph3, BARGRAPH3_INCREASE_LED,  
                           BARGRAPH3_DIRECTION_BOTTOM_TO_TOP, 
                           bargraph_cnt );
        Delay_ms( 1000 );
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}


// ------------------------------------------------------------------------ END

Additional Support

Resources