MicroController Pros Home Page My Account  Cart Contents  Checkout  

****Note: We no longer process and ship international orders. Only orders from USA and Canada are now accepted.****
You can place international orders for our products on E-Bay. Just copy the item's title description from our website and paste it into the search box on E-Bay and place your order there.

  Store » EEDT6.0 Tutorial 3 My Account  |  Cart Contents  |  Checkout   
Quick Find
 
Enter keywords to find the product you are looking for in the Quick Find field above

or use
Advanced Search
Categories
Accessory Boards->
8051->
ADI Blackfin
Arduino->
ARM->
Atmel AVR->
Cypress PSoC
Freescale->
FTDI->
Locktronics
Microchip PIC->
MIPS
Parallax->
Renesas
Silicon Labs
ST Microelectronics->
Texas Instruments->
Tibbo->
Books->
Displays->
E-Blocks->
EEPROM/EPROM/FLASH
Embedded Ethernet->
Embedded Software->
I/O Modules->
Parts & Components->
Pick & Place Tools
Programmable Logic (PLD)
Prototype PCBs->
Robotics
ROM/Flash Emulators
Test & Measurement->
Tutorial Software
Universal Programmers->
Wireless->
Information
Intro to Embedded Tools
Embedded News Digest
Useful Resources
Shipping & Returns
Warranty & Liability
Privacy Notice
Conditions of Use
Contact Us
Controlling Multiplexed 7-Segment LED Display with LPC2138

This is a tutorial for owners of the EEDT6.0 development board.

Recommended tools include the Keil MDK-ARM IDE and the included EM-P-NXP programmer with Flash Magic programming software. Usage of these was covered in the first tutorial.


Setup Connections

Control lines of the 7-Segment Display section should be connected to P0.4 through P0.7.

Data lines of the 7-Segment Display section should be connected to P1.24 through P1.31.

Refer to the following image:

Below, you will find the main.c file with full source code. You also can view a video of the program in action.


Sample Program

/******************************************************************************/


#include <lpc21xx.h> /* LPC21xx definitions */

//Control lines connected to P0.4, P0.5, P0.6, P0.7

#define CTRL 0x000000f0
#define CTRL_SET IOSET0
#define CTRL_CLR IOCLR0

//Data lines connected to P1.24 to P1.31
#define DATA 0xFF000000
#define DATA_SET IOSET1
#define DATA_CLR IOCLR1

//Advance declaration for all functions
void DisplayCtrl(int displayID, int status); //Status 0 = off, 1 = On
void DisplayData(int value, int displayID);
void SetupPorts(void);
void msDelay(int d);
void PrintNumber(int number);
void DisplayDigit(int value);

//Display Control
int SegArray[4]={0x00000010, 0x00000020, 0x00000040, 0x00000080};

//Digits value
int DigitArray[10]={0x3F000000, 0x06000000, 0x5B000000, 0x4F000000,0x66000000,0x6D000000,0x7d000000,0x07000000,0x7F000000,0x6F000000};
//Make sure above DigitArray is a single-line statement.

int main(void)
{
int x,h;

SetupPorts();

while(1)
{
for(x=0;x<=9999;x++)
{
for(h=0;h<40;h++)
{
PrintNumber(x);
}
}
}
}

void PrintNumber(int number)
{
int i,j ;
int digit[4], top = 3;

digit[0]=0;
digit[1]=0;
digit[2]=0;
digit[3]=0;


while( number > 0 )
{
i = number % 10;
digit[top--] = i;
number = number / 10;
}
for(j=0;j<4;j++)
{
DisplayData(digit[j],j);
}
}


void DisplayData(int value, int displayID)
{
DisplayCtrl(displayID,1);
DisplayDigit(value);
msDelay(100);
}


void DisplayCtrl(int displayID, int status) //Status 0 = off, 1 = On
{
CTRL_SET=CTRL;

if(status==0)
{
CTRL_SET=~SegArray[displayID];
}

if(status==1)
{
CTRL_CLR=SegArray[displayID];;
}
}

void DisplayDigit(int value)
{
DATA_SET=DATA;
DATA_CLR=DigitArray[value];

}

void SetupPorts(void)
{
//Ctrl P0.4, P0.5, P0.6, P0.7 - Output
//Data P1.24 to P1.31 Data - Output
IODIR0=CTRL;
IODIR1=DATA;

DATA_SET=DATA; //All segments Off
CTRL_SET=CTRL; //All displays Off
}

void msDelay(int d)
{
int i;
for(i=0;i< (d*100);i++)
{
}


Shopping Cart more
0 items
What's New? more
SAMD21 Dev Breakout, Arduino-M0 Compatible, Battery Connector
SAMD21 Dev Breakout, Arduino-M0 Compatible, Battery Connector
US$15.95
Bestsellers
01. 2x5 (10-pin) 0.05" pitch IDC Connector Flat Ribbon Cable, 20cm
02. 2x5 (10-pin) 0.05" pitch IDC Connector Flat Ribbon Cable, 12cm
03. 5-pin Press-Fit Header Strip, Breakaway Pins, 2.54mm Pitch
04. Parallel to USB Adapter: Connect USB printer to LPT port
05. 2x10 (20-pin) 0.1" pitch IDC Connector Flat Ribbon Cable, 15cm
06. 8-pin Press-Fit Header Strip, Breakaway Pins, 2.54mm Pitch
07. USB Universal In-Circuit Programmer PIC AVR ARM MSP 8051 EEPROM
08. 2x5 (10-pin) 0.1" pitch IDC Connector Flat Ribbon Cable, 15cm
09. ARM JTAG Debugger & Programmer, parallel port
10. Power Supply 3-12V DC, U.S. plug, 6 connection tips
Reviews more
This is .8mm spacing, so be aware of that when ordering. ..
4 of 5 Stars!
  Thursday 28 March, 2024   List of all our Products

Copyright © 2003-2017 MicroController Pros LLC
Powered by osCommerce