Reputation: 79
MY friend is trying to program a shift register ic 74hc595 with 8051 microcontroller attached to display a moving led message.
But my compiler is giving me error in send_data(alf(a));
Here is code->
#include<8051.h>
#define clock P2_0
#define data_bit P2_1
#define latch P2_2
#define shift 8
void delay(unsigned int i)
{
int k=0;
while(k<i)
{
k++;
}
}
void send_data(unsigned char temp)
{
unsigned char i;
unsigned char dd;
latch=0;
clock=0;
for(i=0;i<shift;i++){
dd=temp>>i;
if(dd&1)
data_bit=1;
else
data_bit=0;
clock=1;
clock=0;
}
latch=1;
}
unsigned char alf[]={16,6,6,16};
void main()
{
unsigned char a;
while(1){
for(a=0;a<4;a++)
{
send_data(alf(a));
delay(10000);
}
}
}
Since its my friend who is making, i dont have much info about it. But if anything else is needed, please tell and i will provide but please help me solve this prob. Thanks.
Upvotes: 0
Views: 89
Reputation: 4002
In your case alf
is an array not a function. If alf
is a function then you can call alf(a)
. For array you need to pass index so you need to call alf[a].
Upvotes: 0
Reputation: 41045
send_data(alf(a));
should be
send_data(alf[a]);
On the other hand, the body of delay
can be optimized (and removed) by your compiler, take a look to the volatile keyword
Upvotes: 3