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 ConnectionsControl 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++) { }
|