一个简单的流水灯问题,在调用子程序的时候,led_flow(); ()里面一定需要有参数吗,我没有写参数,但是也能正确运行,但是没有参数的话,又是怎么传到子程序的呢
代码如下:
#include<reg51.h>
void delay(int x)
{
int i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void led_flow(unsigned char *p)
{
P1=*p;
delay(1000);
}
void main(void)
{
unsigned char Tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff};
unsigned char *pointer;
pointer=Tab;
while(1)
{
if(*pointer==0xff)
pointer=Tab;
led_flow();
*pointer++;
}
}
|