一個簡單的流水燈問題,在調用子程序的時候,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++;
}
}
|