Saturday, December 16, 2017

9. Seven-segment LED interface

PartB
 9.Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate
delay in between.
Theory:
fig :common cathode display(to glow a particular segment pass logic 1)

Table: hexadecimal equivalent values for each digit to be displayed
fig:interfacing diagram of LPC1768 to seven segment dislay

Explanation:

code:
#include <LPC17xx.h>
unsigned int delay, count=0, Switchcount=0,j;

unsigned int Disp[16]={0x000003f0, 0x00000060,
                                       0x000005b0, 0x000004f0,
                                       0x00000660,0x000006d0,
                                       0x000007d0, 0x00000070,
                                       0x000007f0, 0x000006f0,
                                      0x00000770,0x000007c0,
                                      0x00000390, 0x000005e0,
                                      0x00000790, 0x00000710 };

#define ALLDISP  0x00180000 //Select all display
#define DATAPORT 0x00000ff0 //P0.4 to P0.11 : Data lines connected to drive Seven Segments

int main (void)
{
LPC_PINCON->PINSEL0 = 0x00000000;
LPC_PINCON->PINSEL1 = 0x00000000;
LPC_GPIO0->FIODIR = 0x00180ff0;

while(1)
{
LPC_GPIO0->FIOSET |= ALLDISP;
LPC_GPIO0->FIOCLR = 0x00000ff0; // clear the data lines to 7-segment displays
LPC_GPIO0->FIOSET = Disp[Switchcount];    // get the 7-segment display value from the array

for(j=0;j<3;j++)
for(delay=0;delay<30000;delay++); // 1s delay
                           
Switchcount++;
if(Switchcount == 0x10) // 0 to F has been displayed ? go back to 0
    {
   Switchcount = 0;
   LPC_GPIO0->FIOCLR  = 0x00180ff0;
    }

}
}
*********************************************************************************
implementation of same code using for loop
#include <LPC17xx.h>
unsigned int delay, count=0, Switchcount,j;

unsigned int Disp[16]={0x000003f0, 0x00000060,
                                       0x000005b0, 0x000004f0,
                                       0x00000660,0x000006d0,
                                       0x000007d0, 0x00000070,
                                       0x000007f0, 0x000006f0,
                                      0x00000770,0x000007c0,
                                      0x00000390, 0x000005e0,
                                      0x00000790, 0x00000710 };

#define ALLDISP  0x00180000 //Select all display
#define DATAPORT 0x00000ff0 //P0.4 to P0.11 : Data lines connected to drive Seven Segments

int main (void)
{
LPC_PINCON->PINSEL0 = 0x00000000;
LPC_PINCON->PINSEL1 = 0x00000000;
LPC_GPIO0->FIODIR = 0x00180ff0;

while(1)
{

for(Switchcount=0;Switchcount<16;Switchcount++)
{
LPC_GPIO0->FIOSET |= ALLDISP;
LPC_GPIO0->FIOCLR = 0x00000ff0;   // clear the data lines to 7-segment displays

LPC_GPIO0->FIOSET = Disp[Switchcount];    // get the 7-segment display value from the array
for(j=0;j<3;j++)
for(delay=0;delay<30000;delay++);  // 1s delay
       
}
}
}
*********************************************************************************

implementation of count code using for loop 0 to F and F to 0

#include <LPC17xx.h>
unsigned int delay, count=0, Switchcount,j;

unsigned int Disp[16]={0x000003f0, 0x00000060,
                                       0x000005b0, 0x000004f0,
                                       0x00000660,0x000006d0,
                                       0x000007d0, 0x00000070,
                                       0x000007f0, 0x000006f0,
                                      0x00000770,0x000007c0,
                                      0x00000390, 0x000005e0,
                                      0x00000790, 0x00000710 };

#define ALLDISP  0x00180000 //Select all display
#define DATAPORT 0x00000ff0 //P0.4 to P0.11 : Data lines connected to drive Seven Segments

int main (void)
{
LPC_PINCON->PINSEL0 = 0x00000000;
LPC_PINCON->PINSEL1 = 0x00000000;
LPC_GPIO0->FIODIR = 0x00180ff0;

while(1)
{

for(Switchcount=0;Switchcount<16;Switchcount++)
{
LPC_GPIO0->FIOSET |= ALLDISP;
LPC_GPIO0->FIOCLR = 0x00000ff0;   // clear the data lines to 7-segment displays

LPC_GPIO0->FIOSET = Disp[Switchcount];    // get the 7-segment display value from the array
for(j=0;j<3;j++)
for(delay=0;delay<30000;delay++);  // 1s delay
       
}

for(Switchcount=15;Switchcount>=0;Switchcount--)
{
LPC_GPIO0->FIOSET |= ALLDISP;
LPC_GPIO0->FIOCLR = 0x00000ff0;   // clear the data lines to 7-segment displays

LPC_GPIO0->FIOSET = Disp[Switchcount];    // get the 7-segment display value from the array
for(j=0;j<3;j++)
for(delay=0;delay<30000;delay++);  // 1s delay
       
}

}
}
*********************************************************************************
to control each display independently written by Adarsh N D 6th sem TCE, JNNCE

#include<LPC17xx.h>
unsigned int delay,count=0,Switchcount=0,j,i,k;
unsigned int disp[16]={0x000003f0,0x00000060,0x000005b0,0x000004f0,
0x00000660,0x000006d0,0x000007d0,0x00000070,
0x000007f0,0x000006f0,0x00000770,0x000007c0,
0x00000390,0x000005e0,0x00000790,0x00000710};

void dispone(void);
void disptwo(void);

#define ALLDISP 0x00180000
#define DATAPORT 0x00000ff0

int main(void)
{
LPC_PINCON ->PINSEL0=0x00000000;
LPC_PINCON ->PINSEL1=0x00000000;

while(1)
{
for (i=0;i<16;i++)
dispone();                    //function call dispone
for(k=0;k<16;k++)
disptwo();                   //function call disptwo
}
}

//function for display1
void dispone(void)
{
LPC_GPIO0->FIODIR=0x00080ff0;
LPC_GPIO0 ->FIOSET =ALLDISP;
LPC_GPIO0 ->FIOCLR =0x00000ff0;
LPC_GPIO0 ->FIOSET=disp[Switchcount];
for(j=0;j<3;j++)
for(delay=0;delay<2500000;delay++);
Switchcount++;
if(Switchcount==0x10)
{
Switchcount=0;
LPC_GPIO0 ->FIOCLR=0x00180ff0;
}
}

//function for display2
void disptwo(void)
{
LPC_GPIO0->FIODIR=0x00100ff0;
LPC_GPIO0 ->FIOSET =ALLDISP;
LPC_GPIO0 ->FIOCLR =0x00000ff0;

LPC_GPIO0 ->FIOSET=disp[Switchcount];
for(j=0;j<3;j++)
for(delay=0;delay<2500000;delay++);
Switchcount++;
if(Switchcount==0x10)
{
Switchcount=0;
LPC_GPIO0 ->FIOCLR=0x00180ff0;
}
}



Download:7 segment LED to display 0 to F

1 comment:

  1. Can you explain how you derived the hex values and added the 0 x 0000 in front? 0x000003f0, 0x00000060,
    0x000005b0, 0x000004f0,
    0x00000660,0x000006d0,
    0x000007d0, 0x00000070,
    0x000007f0, 0x000006f0,
    0x00000770,0x000007c0,
    0x00000390, 0x000005e0,
    0x00000790, 0x00000710

    ReplyDelete

lab record

TECHNICAL SPECIFICATIONS of LPC1768 (15-16 of ARMCTXM3) ******************************************************************************...