A Guide to Interfacing a 7-Segment Display with the LPC2148 ARM7 Microcontroller
Introduction to the ARM7 LPC2148 Slicker Board
The ARM7 LPC2148 Slicker board is a development kit created to help students and developers master the fundamentals of embedded systems. It is designed for ease of use, allowing learners to access and utilize the microcontroller’s full range of features. A key feature of this board is its support for In-System Programming (ISP) via a standard serial port, which simplifies the process of uploading and testing code.
This kit, based on the NXP ARM7 (LPC2148), is intended to facilitate the development and debugging of various designs that require a high-speed 32-bit microcontroller.
Understanding the 7-Segment Display
A seven-segment display is a basic electronic component used to display numerical digits from 0 to 9. It consists of an array of eight LEDs arranged in a specific pattern resembling a figure ‘8’, where each LED forms a segment of the digit.
How to Interface a 7-Segment Display
A typical seven-segment display comes in a ten-pin package. Eight of these pins are used to control the individual LEDs, while the two middle pins are common and internally connected. These displays are available in two main types:
- Common Cathode (CC): All the negative terminals (cathodes) of the LEDs are connected to a common pin.
- Common Anode (CA): All the positive terminals (anodes) of the LEDs are connected to a common pin.
Connecting a 7-Segment Display to the LPC2148
This guide will demonstrate how to display a four-digit number on the LPC2148 Slicker Board using its onboard seven-segment displays.
On the LPC2148 Slicker Kit, 4 nos. of common anode seven-segment displays are controlled by dedicated seven-segment driver ICs. The microcontroller communicates with these drivers to display the desired digits.
Program to Seven Segment Display (LPC2148)
A seven-segment display is driven using multiplexing. Since all segments are connected to the same bus, the controller enables one digit at a time at a high frequency, creating the illusion that all four digits are lit simultaneously due to persistence of vision.
#include <LPC214x.h>
#include <stdio.h>
#include "7SEG.H"
unsigned int thou,hun,ten,single;
unsigned int x;
void main(void)
{
PINSEL0 = 0;
PINSEL1 = 0;
PINSEL2 &= 0x0000000C;
IODIR0 |= 0x0F << 10 ; // P0.10 - P0.13 Control Lines
IODIR1 |= 0xfF << 16; // P1.16 - P1.23 are Outputs while(1) { if(x == 300) { x=0; single++; if(single>9)
{
single=0;
ten++;
if(ten>9)
{
ten=0;
hun++;
if(hun>9)
{
hun=0;
thou++;
if(thou>9)
{
thou=0;
}
}
}
}
}
x++;
Segment_Disp(&IOPIN1, 16,thou, hun, ten, single);
}
}
void DelayMs(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
{
for(j=0;j<3000;j++);
}
}Detailed Explanation:
- Multiplexing & Control Lines:
IODIR0(bits 10-13) serves as the control bus to select which specific 7-segment digit is currently active, whileIODIR1(bits 16-23) pushes the segment data (A-G and Decimal point). - Counter Logic: The code implements a base-10 counter logic.
single,ten,hun, andthourepresent the digits. The variablexacts as a software timer/divider to control the speed of the incrementing count. - Segment_Disp Function: This abstracted function (defined in
7SEG.H) performs the actual multiplexing. It takes the current values, maps them to the correct segment pattern, and updates the I/O registers accordingly to drive the display.
Use Keil uVision to compile this code. Ensure 7SEG.H is included in your project directory. After compiling, use Flash Magic to upload the resulting HEX file to the LPC2148 via UART0. If the display is malfunctioning, first verify the segment driver IC and ensure the I2C/GPIO connections to the display are physically secure. You can also use the Keil debug environment to observe the port outputs if hardware testing is not initially yielding results.
