EmbDev.net

Forum: ARM programming with GCC/GNU tools need help in programming 7 segment display


von Veleda A. (veleda)


Rate this post
useful
not useful
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.
1
#include<lpc21xx.h>
2
3
void wait(void)
4
{
5
int d;
6
for(d=0;d<100000;d++)
7
}
8
9
#define SEGCONTROL 0x000000F0  //port0 pin 0.4 to 0.7 selected
10
#define SEG1 0x00000010  //1ST DIGIT out of 4 dig 7 segment selected
11
#define SEG2 0x00000020  
12
#define SEG3 0x00000040
13
#define SEG4 0x00000080
14
15
#define SEGDATA 0xFF000000  //port1 pin 1.24 to 1.31 selected
16
#define ONE     0xF9000000
17
#define TWO     0XA4000000
18
#define THREE   0xB0000000
19
#define FOUR    0X99000000
20
#define FIVE    0X92000000
21
#define SIX     0x82000000
22
#define SEVEN   0xF8000000
23
#define EIGHT   0x80000000
24
#define NINE    0x90000000
25
#define ZERO    0xC0000000
26
27
void DispData(int data);
28
void DispON(int ID);
29
void ShowDigit(int r, int i);
30
void DispOFF(int ID);
31
32
int main(void)
33
{
34
35
int count;
36
37
IODIR0 = SEGCONTROL;
38
IODIR1 = SEGDATA;
39
40
DispON(SEG1);
41
DispData(ONE);
42
43
for(count = 0; count<=9999; count++)
44
{
45
IOCLR1 = 1234;
46
DispData(count);
47
wait();
48
wait();
49
wait();
50
}
51
52
void DispON(int ID)
53
{
54
IOSET0 = ID;
55
wait();
56
IOCLR0 = ID;
57
IOSET0 = 0Xfffffffff & (~ID);
58
}
59
void DispOFF(int ID)
60
{ IOSET1 = SAGDATA;
61
}
62
63
void DispData(int data)
64
{
65
int r, int i;
66
for(i= 0; i<4; i++)
67
{
68
if(data>9)
69
{
70
r = data%10;
71
ShowDigit(r,i);
72
data = data/10;
73
}
74
else if(data >= 0 && data<=9)
75
{
76
ShowDigit(r,i);
77
i=4;
78
}
79
wait();
80
wait();
81
}
82
83
void ShowDigit(int r, int i)
84
{
85
switch(i)
86
{
87
case 0: DispON(SEG1);
88
        break;
89
.
90
.
91
.
92
case 3: DispON(SEG3);
93
        break;
94
}
95
wait();
96
97
switch(r)
98
{
99
 case 0: IOSET1 = ZERO;
100
         wait();
101
         IOCLR1 =ZERO;
102
         break;
103
.
104
.
105
.
106
.
107
case 9: IOSET1 = NINE;
108
         wait();
109
         IOCLR1 =NINE;
110
         break;  
111
}
112
wait();
113
switch(i)
114
{
115
case 0: DispOFF(SEG1);
116
        break;
117
.
118
.
119
.
120
case 3: DispOFF(SEG3);
121
        break;
122
}
123
124
}

its not working!!!
plz tell me where i am going wrong

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.