MicroController Pros Home Page My Account  Cart Contents  Checkout  
  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
Flowcode 7 for PIC, AVR, Arduino, ARM - Pro 2 User
Flowcode 7 for PIC, AVR, Arduino, ARM - Pro 2 User
US$400.00
Specials more
USB to RS232 Adapter Cable, 10cm
USB to RS232 Adapter Cable, 10cm
US$19.50
US$9.00
Bestsellers
01. LCD 4-mux, 7 digits x 14 segments, progress bar, arrows
02. LCD 4-mux, 7.1 digits x 7 segments, progress bar, arrows
03. PIC16F628A-I/P Microcontroller, 18 DIP, 20 MHz
04. Atmel ATtiny2313-20PU AVR Microcontroller, 20 DIP, 20 MHz
05. USB-to-Serial Cable: 3.3V TTL, Audio Plug Type, Reverse RX/TX
06. 2x5 (10-pin) 0.05" pitch IDC Connector Flat Ribbon Cable, 12cm
07. 2x10 (20-pin) 0.1" pitch IDC Connector Flat Ribbon Cable, 15cm
08. USB Universal In-Circuit Programmer PIC AVR ARM MSP 8051 EEPROM
09. ARM JTAG Debugger & Programmer, parallel port
10. Power Supply 3-12V DC, U.S. plug, 6 connection tips
Reviews more
Proto PCB for 64-100 pin QFP, 0.4mm Pitch
Fast PCB prototype:In 24 hours. Our philosophy: Fast, Accu ..
5 of 5 Stars!
  Sunday 16 December, 2018   List of all our Products

Copyright © 2003-2017 MicroController Pros LLC
Powered by osCommerce