Interface LCD with SAM L22 MCU Tutorial


A segmented Liquid Crystal Display (LCD) is made up of segments which can be made visible or invisible by applying a voltage across the liquid crystal. The SAM L22 microcontroller has a Segment LCD (SLCD) controller which is used to drive segmented LCD displays.

This tutorial shows you how to use the SAM L22's SLCD controller to drive an LCD display. You will use the SAM L22 Xplained Pro Evaluation Kit and Segment LCD1 Xplained Pro extension board (sold separately).

Two Ways to Use This Tutorial

  1. Create the project from scratch
    • Use the provided source files and follow the step-by-step instructions given below.
  2. Use the solution project as an example
    • Just build the solution project and download it to the SAM L22 Xplained Pro Evaluation Kit to observe the expected behavior.

Lab Objectives

  1. Create an Atmel Studio project from scratch for the SAM L22 microcontroller.
  2. Use the Advanced Software Framework (ASF) Wizard to select the ASF modules (driver(s)/component(s)/service(s)) to be used by the application.
  3. Setup the board and clock configuration.
  4. Add code to configure the SLCD controller.
  5. Add code to use the features of the SLCD like ASCII character mapping, software contrast control, hardware blinking, SLCD waking up from standby sleep mode, SLCD lower power consumption and scrolling on the segmented LCD display.
  6. Observe how your code affects the Segment LCD1 Xplained Pro board mounted on SAM L22 Xplained Pro Evaluation Kit, and monitor power consumption using the Atmel Studio Data Visualizer.


Hardware Tools

Tool About Purchase
SAM L22 Xplained Pro
Evaluation Kit

The Xplained Pro series evaluation kits include an onboard Embedded Debugger (EDBG). No external tools are necessary to program or debug the ATSAML22N18A. The EDBG connects to the host PC through the USB micro-B connector on the SAM L22 Xplained Pro Evaluation Kit for programming/debugging.

Figure: Hardware Setup

Hardware Connection Setup

  • Connect the SEGMENT LCD1 Xplained Pro extension board on the slot EXT5 - SEGMENT LCD in the SAM L22 Xplained Pro board.
  • Set the I/O current measurement jumper to BYPASS option (to disable I/O consumption information), as highlighted in the Hardware Setup figure.
  • Set the MCU current measurement jumper to MEASURE option, as highlighted in the Hardware Setup figure. This is during current consumption measurement since we are interested only in MCU consumption using the Data Visualizer.
  • Connect a USB cable to the DEBUG USB port for programming.

Software Tools

This project has been verified to work with the following versions of software tools:
Atmel Studio 7 (Version: 7.0.1645), ARM/GNU C Compiler :6.3.1, ASF v3.35.1 and Atmel Studio Data Visualizer extension version 2.15.713 or later.

Because we regularly update our tools, occasionally, you may discover an issue while using newer versions. If you suspect that to be the case, we recommend that you double-check using the same versions that the project was tested with.

Archived versions of our tools can be found on the following Microchip websites:
Atmel Studio 7

Note that you don't need to separately install the IDE, ARM GCC Compiler, ASF, and Data Visualizer. Installing Atmel Studio will install them all.

Tool About Installers
Windows Linux Mac OSX
Atmel® Studio
Integrated Development Environment
Advanced Software Framework v3 (ASF3)
Integrated Software Framework
Included with Atmel® Studio7 IDE

Segment Liquid Crystal Display (SLCD) Controller

The segments in a segmented LCD display have two electrodes with liquid crystal between them. These electrodes are called the common terminal (COM pin) and the segment terminal (SEG pin). When a voltage above a threshold voltage is applied across the liquid crystal, the segment becomes visible.

The SAM L22 SLCD controller is intended for a monochrome passive liquid crystal display with up to eight common terminals and up to 44 segment terminals (maximum of 320 segments). Features such as character mapping, automated characters string display, and autonomous animation are implemented to reduce CPU load and power consumption.

Figure: LCD Controller Segments


  • Display capacity up to 44 segments lines and up to eight common lines (up to 320 segments)
  • Selection of maximum 48 segments/common lines from 52 LCD pins
  • Support from static up to 1/8 duty
  • Support static, 1/2, 1/3 and 1/4 bias
  • Shadow display memory for full freedom in segment update
  • LCD pins as segment terminal, common terminal or general purpose I/O
  • Blink mode and frequency configuration (up to 16 segments)
  • Regular and low power waveform
  • Software contrast adjustment control
  • On-chip LCD power supply
  • Character mapping
  • Automated characters string scrolling
  • Automated characters string display
  • Automated segments display
  • Autonomous animation (up to 16 segments)
  • Three frame counters for timing schedule
  • Interrupt request and event output for display update
  • DMA Support
  • SleepWalking Support
Figure: Block Diagram of SLCD controller


This lab shows you how to use the SAM L22's SLCD controller to drive the Segment LCD1 Xplained Pro display on the SAM L22 Xplained Pro Evaluation Kit. It also helps you understand and use the following features: ASCII character mapping, software contrast control, hardware blinking, SLCD waking up from standby sleep mode, SLCD lower power consumption, and scrolling characters on the LCD display.

Figure 1.1 Application Flow Sequence
  • Configure Clock and Board: The function system_init initializes the SAM L22 system clock and board configurations.
  • Configure SLCD: The function lcd_configure configures the SLCD hardware pin's, enables the back light and initializes the SLCD module.
  • Add code for implementing SLCD Features
    • The following functions will be used to implement features:
      • lcd_display_string adds code for character mapping.
      • lcd_sleep_mode_display displays string and moves the device back to sleep mode.
      • lcd_sleep_mode_standby_conf configures SLCD to operate on low power mode.
      • lcd_display_moving_string enables scrolling on the SLCD.
    • Setup the following macros:
      • CONF_LCD_CONTRAST for specifying the software SLCD contrast control.
      • CONF_LCD_FRAME_DELAY for specifying the frame delay to demonstrate the hardware blinking feature.
  • Observe output on Segment LCD1 Xplained Pro board mounted on SAM L22 Xplained Pro Evaluation Kit's external connector(EXT5) and Data Visualizer.
Figure 1.1 shows the flow sequence of the application task.
Click image to enlarge.

Lab Source Files and Solutions:

This ZIP file contains the completed solution project for this lab. It also contains the source files needed to perform the lab as per the following step-by-step instructions (see the "Procedure" section on this page).

The contents of this ZIP file can be placed in a folder of your choice, preferably in a top level folder of a drive.

Extracting the ZIP file will create the following folders:

  • saml22_slcd contains the lab folder saml22_slcd_lab.
  • saml22_slcd_lab contains the complete lab solution (saml22_slcd_lab.atsln and related files under sub folder saml22_slcd_lab) and source files to create the lab from scratch.
  • dev_files contains application source files and other support files (if any) required to perform the lab from scratch (see the "Procedure" section below).
  • saml22_slcd_lab.atsln is the completed lab solution project. It can be directly built and downloaded on the hardware to observe expected behaviour.


All steps must be completed before you will be ready to build, download, and run the application.

Lab Index

Step 1: Create a Project for the SAM L22 Microcontroller

  • Step 1.1 – Create an ASF Project Using Atmel Studio IDE

Step 2: Use the ASF Wizard to Select the ASF Driver(s)/Component(s)/Service(s)

  • Step 2.1 - Add SLCD, RTC and DMA Drivers
  • Step 2.2 - Add Delay Routine Services
  • Step 2.3 - Verify that the Board Specific Modules are Added Automatically
  • Step 2.4 - Verify the Added Modules

Step 3: Add SLCD Library Files and Initialize the SLCD Controller

  • Step 3.1 - Create slcd_library Folder and Add its Related Files
  • Step 3.2 - Replace conf_slcd.h with conf_slcd.h Provided in the dev_files Folder
  • Step 3.3 - Initialize the Segment LCD Controller

Step 4: Add Code to Control and Drive the LCD Display

  • Step 4.1 - Implement ASCII Character Mapping and Software Contrast Control
  • Step 4.2 - Implement Hardware Blinking
  • Step 4.3 - Implement Waking up from Standby Sleep Mode and Lower Power Consumption
  • Step 4.4 - Implement Scrolling
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.