简体   繁体   中英

function contains unnamed parameter

I'm a new programmer,my program is about getting LED on,maybe the simplest in C language,but it is always having _'Delay10ms':function contains unnamed parameter ,hoping someone help me to solve it. here are my words:

#include<reg51.h>
#include<intrins.h>
#define GPIO_LED P2

void Delay10ms(unsigned char time)
{
    unsigned char i,j;
    for(i=1;i<110*time;i++)
       for(j=1;j<110;j++);
}

void main()
{
    unsigned char n,i,j;
    GPIO_LED=0X01;
    while(1)
    {
        for(n=0;n<7;n++)
        {
            GPIO_LED=_crol_(GPIO_LED,1);
            Delay10ms(50);
        }

        for(n=0;n<7;n++)
        {
            GPIO_LED=_cror_(GPIO_LED,1);
            Delay10ms(50);
        }
    }
}

Either <reg51.h> or <intrins.h> probably have standard library includes. One of these library includes contains the standard header function time() that returns the current system time. Because your function parameter's name is time the IDE probably can't figure out what you meant with it and thus it gives you that error/warning. Try renaming your variable.

Also, the return type of main() has never been void (C++), use int .

It has been a Long time gone since I played c, but your code Looks ok, maybe there is a name conflict ("time")

But there are some more questions: - Why do you use char (unsigned char = 0..255) instead of classic int? This would be make code more readable. - What do you expect how relyable your timer could be on a multitasking operating System?

I would implement such a function (if it not exists) as

void MyDelay (unsigned int delay_time)
{    
    start = MyOs.GiveMeTheTime()
    while (MyOs.GiveMeTheTime() - start < delay_time)
    {};
}

MyOs and GiveMeTheTime are names chosen by me. You must find out, which functions are available on your System, I am sure, they are.

I suppose, you try to program anything like a raspberry pi. Maybe this link could help:

Example Which Provides Accurate uS Timing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM