0

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.

1
  • 2
    Tag your question with the programming language, and at least post the error message from the compiler. Commented Dec 21, 2013 at 8:33

2 Answers 2

3
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

Sign up to request clarification or add additional context in comments.

Comments

0

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].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.