element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Blog [FRDM-KL46Z - PE - CW] Tutorial: Display easily on a Segment LCD
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 10 Jul 2014 7:19 PM Date Created
  • Views 2818 views
  • Likes 3 likes
  • Comments 7 comments
  • freedom-board
  • freescale
  • kinetis-l
  • frdm-kl46z
  • kl46z
Related
Recommended

[FRDM-KL46Z - PE - CW] Tutorial: Display easily on a Segment LCD

bheemarao
bheemarao
10 Jul 2014

This tutorial brings you on getting working with 4-digit (4X8) segment LCD present in KL46Z freedom board.


We will use the Freescale Codewarrior for MCU toolchain, which integrates the Processor Expert code generator tool.
A free Codewarrior editions either Special (code size limited to 64KB) or Evaluation (30 days limited) are downloadable from Freescale website

www.freescale.com/cwmcu10

 
Launch Freescale Codewarrior for MCU and create a new project for KL46Z board following below procedure (refer to the blog link for “how to create project using processor expert” )

 

  • In the CodeWarrior, click File menu and select New > Bareboard Project in order to create a new project. The Project Wizard appears. Enter the name of the project "LCD seg-seg kl46" and click Next.

 

  • Now select the MCU available on our KL46 board which is the MKL46Z256

Kinetis L Series ⇒ KL4x Family ⇒ KL46Z(48 MHz) Family ⇒ MKL46Z256 then Click Next.

 

  • Select OpenSDA connection for debugging and programming, then click Next.

 

  • Keep the Language and Build Tools Options unchanged and click Next.

 

 

  Select Processor Expert option as we are creating the project using Processor Expert, then click Finish

 

A new project named "LCD seg-seg kl46" is created as shown below. The Component Inspector view for the CPU should be automatically opened with default settings (else double click on the CPU in the Components view):

 

image

 

First we need to define CPU parameter as below:


image

 

Under Clock settings (expand the Clock settings by clicking on the white arrow)

 

System Oscillator: Enabled

Clock Source: External Oscillator (default)

Clock Frequency: 8 MHz (default) (KL46 is connected to an external crystal oscillator on the FRDM-KL46Z)


Clock source settings ⇒ Clock source settings 0

 

MCG settings ⇒ MCG mode: FEI (FLL engaged internal)

 

FLL settings ⇒ FLL output [MHz]: 47.972352

 

MCG output[MHz] will automatically updates to 47.972352

 

Under Clock configurations ⇒ Clock configuration 0 ⇒ System clocks set

Core clock: 47.972352 MHz

Bus clock: 23.986176 MHz

 

All the other parameters previously highlighted in RED should be automatically updated and turned black/grey, which means that all the CPU settings are now correct. In the Components window a green tick will appear on the CPU symbol if everything went fine.


image
Since now our project skeleton is ready (i.e no component module peripherals has been added to our project), we need now to add the required peripheral component modules for our LCD project.

 

We will add first two component modules to blink the red and the green LEDs of the FRDM-KL46Z

 

Open the Components Library view and select the Categories tab


Expand the Logical Device Drivers ⇒ Port I/O and select the BitIO_LDD component

 

Right click and select Add to Project twice, since we need two LED components in our project (one per LED).


image

Rename the components (LED_RED, LED_Green) as shown below:

Right click on the corresponding module in the Components view and select Rename Component


image

According to the board schematics, Red LED is connected to Port PTE29 and Green LED is connected to Port PTD5 of the MKL46Z256VLL4 MCU.


image

 

Select the corresponding module in the Component view and switch to the Components Inspector view to make change the Pin for I/O as below:

 

LED_RED BitIO assigned to the output pin PTE29


Init. value must be set to 1


Auto initialization must be defined to yes


image

In the Methods tab, select NegVal Generate code


image

LED_Green BitIO assigned to the output pin PTD5


Init. value must be set to 1


Auto initialization must be defined to yes



image

In the Methods tab, select NegVal Generate code


image

Introduction to set up the Segment LCD controller


Segment LCD modules are simple and very low power LCD displays. They can have a large number of segments in the form of dots (pixels) or symbols (parts of 7 segment characters or special images) and a large number of pins to enable these segments to be controlled. SLCD controllers tend to have a high number of pins to handle large GLCD modules. These pins can be configured as back-plane or front-plane pins and generates the required multiplexing and waveforms needed to continuously refresh the SLCD.

 

Rather than have one connection for each segment, the segments are typically multiplexed so that less control lines are needed to control the same number of individual segments.


To illustrate this, the Lumex LCD-S401M16KR, as used on the Freescale FRDM-KL46Z is used as reference. The following is an excerpt from its data sheet showing its characteristics and how its 12 pins are connected to its elements:

 

Characteristics of Lumex LCD-S401M16KR are given below:

                                                image

Connection details of Luminex LCD-S401M16KR

                                                 image


And the display’s elements are illustrated below according to their references in the Connection table in the original data sheet:


                      image

                                                                 s401 segments layout

 

This display has 12 pins, which are all connected to a driving pin on the SLCD controller. There are 4 common pins and so the driving mode is ¼ duty cycle, since each of the common pins are driven for ¼ of the cycle period. Each of the common lines is connected to 8 LCD segments. Taking COM0 as an example the 8 segments that are controlled by it are show in the following diagram.

                                                   image

 

This means that when the COM0 line is being driven up to 8 segments can be turned on, depending on the state of the 8 segment pins. The 8 segment pins (5..12) thus control these 8 segments during this driving phase and can turn all on, all off, or an combination in between.

Since there are 4 phases (4 COM pins), each controlling 8 segments during that phase, a total of 32 segments can be controlled – this corresponds to the number of segments that the SLCD physically has. The other 3 COM drive combinations are not shown in a diagram here but can be easily read from the original data sheet table.

 

In order to configure the SLCD driver to match this display 4 of its LCD pins are configured as COM drive pins and 8 as segment drive pins. The COM drive pins are configured to drive in different phases (eg. COM0 in phase 1, COM1 in phase 2, COM2 in phase 3 and COM3 in phase 4, where each of the phases are repeated according to ¼ duty driving mode). The duty mode and any other specific configuration are also set in the SLCD controller.

 

Now we need to add a LCD component available in Processor Expert to operate the LCD screen embedded on the board.

FRDM-KL46Z is using a 4 digit display (LUMEX LCD-S401M16KR) 4x8 segments. Following table shows connection from KL46 board to s401 LCD display and same configuration need to be assigned to the port pins.

image


Select in the Components Library view the LCD module available in Component Library ⇒ Logical Device Driver ⇒ Display⇒ SegLCD_LDD

and add it to project by double clicking as shown below:

image


Select the SegLCD1:SegLCD_LDD in the Components view and switch to the Component Inspect view to enter the parameter (a red cross on the component module indicates that parameters are missing)


image

Base clock must be defined as 1.024kHz


Click on the

image

A new window will appear with Possible settings

Double click on the 1.024kHz and press OK to fill-in the field in the Component Inspector window.

 

LCD component has Backplane pins and Frontplane pins, as there are 4 Backplane pins, which are common pins connected to LCD com0, com1, com2, com3 pins.

 

Increase Backplane pins up to 4 by clicking on the +

  Expand the Backplane pins menu by clicking on the white arrow and assign corresponding port pins (refer to the KL46 LCD Pin

table mentioned earlier) to the Backplane pins:

 

 

Backplane pin0  / Backplane pin  ⇒ LCD_P40

Backplane pin 1 / Backplane pin  ⇒ LCD_P52

Backplane pin 2 / Backplane pin  ⇒ LCD_P19

Backplane pin 2 / Backplane pin  ⇒ LCD_P18

 


image

 

Increase Frontplane pins up to 8 by clicking on the +

 

Now similarly, expand the Frontplane pins menu by clicking on the white arrow to define the 8 segment pins corresponding to the Frontplane pins in Processor Expert with following assignments:

 

Frontplane pin0 / Frontplane pin  ⇒ LCD_P37

Frontplane pin1 / Frontplane pin  ⇒ LCD_P17

Frontplane pin2 / Frontplane pin  ⇒ LCD_P7

Frontplane pin3 / Frontplane pin  ⇒ LCD_P8

Frontplane pin4 / Frontplane pin  ⇒ LCD_P53

Frontplane pin5 / Frontplane pin  ⇒ LCD_P38

Frontplane pin6 / Frontplane pin  ⇒ LCD_P10

Frontplane pin7 / Frontplane pin  ⇒ LCD_P11


Auto initialization must be defined to yes


 

image

If you followed carefully the instructions above you should get a green tick on the SegLCD1:SegLCD_LDD component in the Components view of your project.

image

 

Now we have added one LCD module and two LED modules as required for this demonstration and shown below:

                                                                        image

Software drivers are required for communication between LCD controller and LCD screen and manage the display. You can write your own driver or use Freescale existing drivers.

 

To get the Freescale LCD drivers, simply download the Sample Code Package KL46Z_sc.exe from the FRDM-KL46Z product page in the download tab.

www.freescale.com/FRDM-KL46Z


You will find a LCD folder following the path kl46_sc_rev3\src\projects\FRDMKL46_Demo\ which contains *.C files and *.h files as shown below:

                                                            
image

Copy this LCD folder and paste in the Codewarrior Projects view in the Sources folder as shown below:

 

                                                  image                                              

 

Now our all the components and drivers are ready for the next step.

 

Click on Generate Processor Expert code radio button as shown below

                                                image

 

You can see the tool generates required code as shown below:

                                              image

 

 

All the required header files will get generated under ‘Generated_Code’

 

Next open the main.c file available in the Sources folder from the "LCD seg-seg kl46" Codewarrior Project view and write/paste the below lines of code:

 

/* Including needed modules to compile this module/procedure */

#include "Cpu.h"

#include "Events.h"

#include "SegLCD1.h"

#include "LED_GREEN.h"

#include "LED_RED.h"

#include "BitIoLdd1.h"

#include "BitIoLdd2.h"

/* Including shared modules, which are used for whole project */

#include "PE_Types.h"

#include "PE_Error.h"

#include "PE_Const.h"

#include "IO_Map.h"

#include "LCD.h"

#include "cstdio"

 

#define CW

/* variables */

LDD_TDeviceData *MySegLCDPtr, RED, Green;

 

 

char seg[]={7,8,10,11,17,37,38,53}; // seven segment connection

char col[]={0,1,2,3}; //column of lcd

 

char sLCDBuffer[16]; //temporal buffer for the sLCD,

int main_counter,i,j;

 

/* User includes (#include below this line is not maintained by Processor Expert) */

int main(void)

{

  /* Write your local variable definition here */ 

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

 

  MySegLCDPtr = SegLCD1_Init(NULL);  //initialize sLCD according to PEx

  RED = RED_Init(NULL); //initialize RED LED according to PEx

  Green = Green_Init(NULL); //initialize Green LED according to PEx

 

  for(;;)

   {

         for(j=0;j<=7;j++){

              for(i=0;i<=3;i++){

                     SymbolON(seg[j],i);

                     for (main_counter=1000000 ; main_counter>0 ;main_counter--){}; //delay

                     //SymbolOFF(seg[0],i);

              }

         }

 

         vfnLCD_All_Segments_OFF();  // all segments are turned-off

 

         for(i=0;i<=9999;i=i+1111){

              sprintf(sLCDBuffer,"%04i",i);

              vfnLCD_Write_Msg((uint8 *)sLCDBuffer);

              for (main_counter=1000000 ; main_counter>0 ;main_counter--){};

                Green_NegVal(Green);

                 RED_NegVal(RED);

         }

       

         vfnLCD_All_Segments_OFF();

    }

 

 

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/

  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/

  #ifdef PEX_RTOS_START

PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */

  #endif

  /*** End of RTOS startup code.  ***/

  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

  for(;;){}

  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

 

/* END ProcessorExpert */

/*!

** @}

*/

/*

**

###################################################################

 

In our demonstration program we are glowing each segment of LCD one by one (all the 32 segments) and display the numbers 0-9 on all the digits of LCD.

 

Explaination of code:

 

char seg[]={7,8,10,11,17,37,38,53}; // seven segment connection

char col[]={0,1,2,3}; //column of lcd

Here we have defined two char array one for segment and other for common pins of LCD

 

The array seg[] represents the assigned hardware connection in our LCD component configuration the segments of LCD to port pins.

 

Array Col[] represents the common pins of LCD

 

To turn on the particular segment we have the macro “SymbolON(LCDn,bit)” defined in “LCDConfig.h” file present in LCD driver folder

 

#define  SymbolON(LCDn,bit)     *((uint8 *)&LCD_WF_BASE + LCDn)  |= (1<<(bit))        

#define  SymbolOFF(LCDn,bit)    *((uint8 *)&LCD_WF_BASE + LCDn)  &= ~(1<<(bit))

So we are using this macro in our program to turn all the segments one-by-one

 

for(j=0;j<=7;j++){

     for(i=0;i<=3;i++){

         SymbolON(seg[j],i);  //Macro to turn on the segment of LCD

             for (main_counter=1000000 ; main_counter>0 ;main_counter--){}; //delay

       //SymbolOFF(seg[0],i); // Macro to turn off the segments of LCD

       }

    }

 

 

Now to display the numbers from 0-9 on all the digits simultaneously we have below lines of codes. also while displaying the digits the Red and Green LED's will toggle on every count.

 

for(i=0;i<=9999;i=i+1111){

       sprintf(sLCDBuffer,"%04i",i);

       vfnLCD_Write_Msg((uint8 *)sLCDBuffer); //

       for (main_counter=1000000 ; main_counter>0 ;main_counter--){};

       Green_NegVal(Green);

       RED_NegVal(RED);

      }


vfnLCD_Write_Msg((uint8 *)sLCDBuffer)writes the character to digits of LCD this function is defined in LCD.c file in driver.

 

sprintf(sLCDBuffer,"%04i",i)is writing the integer value ‘i’ into char buffer sLCDBuffer array and ‘%04i’ is limiting the buffer value display to 4-digits


for toggling the LED's below line of code corresponding to led components has been used:

LED_GREEN_NegVal(); //toogles the Green LED

LED_RED_NegVal(); //toogles the Red LED


We will now test the project on the FRDM-KL46Z board.

First save the project selecting File ⇒ Save All

Compile the project using Project ⇒Build All or clicking on the icon    available in the toolbar.image

 

Before launching the debug session, you need to setup your FRDM-KL46Z with the OpenSDA P&E Debug interface.


To ensure a proper detection, download the P&E Windows USB drivers available at www.pemicro.com/opensda and install it. At the same time download the P&E Firmware Apps package.


Keep the Reset button while connecting the USB cable to SDA Connector (bottom one below) to enter in Bootloader mode.


From your file explorer drag’n drop or copy-paste in the BOOTLOADER drive the configuration file MSD-DEBUG-FRDM-KL46Z48M_Pemicro_v114.SDA available in the P&E Firmware Apps package.


Unplug and replug the USB cable
Windows should detect new peripherals (PEMicro OpenSDA Debug Driver, FRDM-KL46Z Mass Storage drive, OpenSDA CDC Serial Port) and automaticaly install the right drivers.

 

Now you are ready to enter the debug session by selecting Run ⇒ Debug Configuration.

A new Debug Configuration window will appear. In the left panel select the LCD project and press the Debug button.


The debug window will open, click on the Resume button from the toolbar to launch the debug session.

 


image

You can now watch the LCD Segment of your FRDM-KL46Z activating each digit one by one.


or alternately you can "Run" the project directly by following below steps:


Save all the files then clean and Build the project as shown below::



image


The build progress is shown below:


image


Now connect the board to USB through OpenSDA port of the board and Run the project as shown below:


image


You can see Run progress bar as shown below:


image

After running the program you can see the project execution on the freedom board displaying all the segments one-by-one on the LCD.


The output snapshot is shown here:

image

image

 

A recording version of the board in action is available below


You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image


The project folder and LCD driver folder is enclosed here for quick reference.


Happy displaying LCD segments image.image image...


Attachments:
LCD.rar
You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image
LCD seg-seg kl46.rar
  • Sign in to reply
  • Marceli
    Marceli over 9 years ago in reply to bheemarao

    Hi Bheema,

     

    Windows 10 when use BOOTLOADER disk is erasing Application to Version 0.00 (see mine first record) from OpenSDA USB port, and user program also disappeared somehow. Therefore after uploading latest Application Version 1.18 ( done in Windows 7) but I can check installation in normal OpenSDA USB connection mode in Windows 10.

     

    Board Name is: FRDM-KL46Z48M
    MicroBoot Kernel Version is: 1.05
    Bootloader Version is: 1.09
    Installed Application: PEMicro FRDM-KL46Z48M Mass Storage/Debug App
    Application Version is: 1.18

     

    After installation LCD program is working well on the board.

     

    Here is problem with USB COMMUNICATION PORT detection in Windows 10.

    USB OpenSDA opening in Windows Explorer as normal USB disk FRDM-KL46Z (E:), then I can program board by drop binary file into.

     

    I have programmed Hello World F401RE-USBHostMSD_HelloWorld_KL46Z.bin (status LED ON) but Windows 10 still can not detect USB communication from MKL46Z256VLL4 micro.

     

    Regards,

    Marceli

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bheemarao
    bheemarao over 9 years ago in reply to bheemarao

    Hi Marceli,

     

    Hope your problem is resolved? kindly provide your feedback.

     

    Actually separate programming tool is not required for this. OpenSDA will do the job of dumping the hex code to the board: and Kinetis Design Studio is an software IDE required for writing or modifying the code: you can download from HERE

     

    If you are looking for  Universal Multilink FX  you can purchase from Here

    or

    Is this the cable you are looking for Universal Multilink FX?  https://www.adafruit.com/product/1675

    You can purchase this from our website: click HERE

     

    Best Regards

    Bheema Rao

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bheemarao
    bheemarao over 9 years ago in reply to Marceli

    Hi Marceli,

     

    Kindly refer to below thread from NXP community:

    https://community.nxp.com/thread/375521

     

    I have enclosed the recent bootloader available from PE Micro https://www.segger.com/downloads/jlinkopensda

    to load this driver file, you need to run the board in bootloader mode on Windows XP or Windows 7 PC and load the OpenSDA file to FRDM-KL46 board.

    then plug it on windows 10 machine.

     

    Note: i have not tested this at my end as i do not have Windows 10 machine.

     

    After performing this let me know whether this solved your problem.

     

    Best Regards

    Bheema Rao

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Marceli
    Marceli over 9 years ago

    Dear Cruz,

     

    I bought the board but in Windows 10 when plug into USB OpenSDA port is not available, not green LED ON. Only I can get is data from  BOOTLODAER disk as following:

    Board Name is: FRDM-KL46Z48M
    MicroBoot Kernel Version is: 1.05
    Bootloader Version is: 1.09
    Application Version is: 0.00
    DUID is: E3833938-B2A881A5-3744F80B-BA9AE678
    EUID is: DB21A239-3CC28727-1843DA18-A0A368D6
    TUID is: 74823938-473281C1-37689805-BBADE678
    TOA is: 86B6E505-BA734E97-FEB041DB-6DAED969
    TOA2 is: 86B6E505-14B38D1D-6F23F598-568F12C1
    SUID is: 86B6E505-8D48971F-37239804-8003EC65

     

    Board registered to Control Devices Pty Ltd.

     

    Bootloader is not allowing upgrade as well. It disappears after USB plug back. 

     

    Additionally to use Multilink Universal FX I need now buy half inch pitch male header socket 10 pins for J11, and cable with female plugs. Do you have?

    Maybe using Multilink I can put your program there, now is not any program there as original gone after first time trying to program the board.

     

    Regards,

    Marceli Firlej

    marceli@controldevices.net

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to bheemarao

    thank you

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube