veleda
Newbie level 2
Hi Alll...
I am new to this forum.
I am trying to interface 4 digit 7segment display with AM lpc2138
I am working in Keil uVision4.
I wrote the code...but its not working.
Can anybody help me?
I am writing my code here.
Plz plz plz..help me asap.
#include<lpc21xx.h>
void wait(void)
{
int d;
for(d=0;d<100000;d++)
}
#define SEGCONTROL 0x000000F0 //port0 pin 0.4 to 0.7 selected
#define SEG1 0x00000010 //1ST DIGIT out of 4 dig 7 segment selected
#define SEG2 0x00000020
#define SEG3 0x00000040
#define SEG4 0x00000080
#define SEGDATA 0xFF000000 //port1 pin 1.24 to 1.31 selected
#define ONE 0xF9000000
#define TWO 0XA4000000
#define THREE 0xB0000000
#define FOUR 0X99000000
#define FIVE 0X92000000
#define SIX 0x82000000
#define SEVEN 0xF8000000
#define EIGHT 0x80000000
#define NINE 0x90000000
#define ZERO 0xC0000000
void DispData(int data);
void DispON(int ID);
void ShowDigit(int r, int i);
void DispOFF(int ID);
int main(void)
{
int count;
IODIR0 = SEGCONTROL;
IODIR1 = SEGDATA;
DispON(SEG1);
DispData(ONE);
for(count = 0; count<=9999; count++)
{
IOCLR1 = 1234;
DispData(count);
wait();
wait();
wait();
}
void DispON(int ID)
{
IOSET0 = ID;
wait();
IOCLR0 = ID;
IOSET0 = 0Xfffffffff & (~ID);
}
void DispOFF(int ID)
{ IOSET1 = SAGDATA;
}
void DispData(int data)
{
int r, int i;
for(i= 0; i<4; i++)
{
if(data>9)
{
r = data%10;
ShowDigit(r,i);
data = data/10;
}
else if(data >= 0 && data<=9)
{
ShowDigit(r,i);
i=4;
}
wait();
wait();
}
void ShowDigit(int r, int i)
{
switch(i)
{
case 0: DispON(SEG1);
break;
.
.
.
case 3: DispON(SEG3);
break;
}
wait();
switch(r)
{
case 0: IOSET1 = ZERO;
wait();
IOCLR1 =ZERO;
break;
.
.
.
.
case 9: IOSET1 = NINE;
wait();
IOCLR1 =NINE;
break;
}
wait();
switch(i)
{
case 0: DispOFF(SEG1);
break;
.
.
.
case 3: DispOFF(SEG3);
break;
}
}
plz tell me where i am going wrong in this code.
and if possible plz give me code so that i can see where i went wrong?
I am new to this forum.
I am trying to interface 4 digit 7segment display with AM lpc2138
I am working in Keil uVision4.
I wrote the code...but its not working.
Can anybody help me?
I am writing my code here.
Plz plz plz..help me asap.
#include<lpc21xx.h>
void wait(void)
{
int d;
for(d=0;d<100000;d++)
}
#define SEGCONTROL 0x000000F0 //port0 pin 0.4 to 0.7 selected
#define SEG1 0x00000010 //1ST DIGIT out of 4 dig 7 segment selected
#define SEG2 0x00000020
#define SEG3 0x00000040
#define SEG4 0x00000080
#define SEGDATA 0xFF000000 //port1 pin 1.24 to 1.31 selected
#define ONE 0xF9000000
#define TWO 0XA4000000
#define THREE 0xB0000000
#define FOUR 0X99000000
#define FIVE 0X92000000
#define SIX 0x82000000
#define SEVEN 0xF8000000
#define EIGHT 0x80000000
#define NINE 0x90000000
#define ZERO 0xC0000000
void DispData(int data);
void DispON(int ID);
void ShowDigit(int r, int i);
void DispOFF(int ID);
int main(void)
{
int count;
IODIR0 = SEGCONTROL;
IODIR1 = SEGDATA;
DispON(SEG1);
DispData(ONE);
for(count = 0; count<=9999; count++)
{
IOCLR1 = 1234;
DispData(count);
wait();
wait();
wait();
}
void DispON(int ID)
{
IOSET0 = ID;
wait();
IOCLR0 = ID;
IOSET0 = 0Xfffffffff & (~ID);
}
void DispOFF(int ID)
{ IOSET1 = SAGDATA;
}
void DispData(int data)
{
int r, int i;
for(i= 0; i<4; i++)
{
if(data>9)
{
r = data%10;
ShowDigit(r,i);
data = data/10;
}
else if(data >= 0 && data<=9)
{
ShowDigit(r,i);
i=4;
}
wait();
wait();
}
void ShowDigit(int r, int i)
{
switch(i)
{
case 0: DispON(SEG1);
break;
.
.
.
case 3: DispON(SEG3);
break;
}
wait();
switch(r)
{
case 0: IOSET1 = ZERO;
wait();
IOCLR1 =ZERO;
break;
.
.
.
.
case 9: IOSET1 = NINE;
wait();
IOCLR1 =NINE;
break;
}
wait();
switch(i)
{
case 0: DispOFF(SEG1);
break;
.
.
.
case 3: DispOFF(SEG3);
break;
}
}
plz tell me where i am going wrong in this code.
and if possible plz give me code so that i can see where i went wrong?