|
單片機源程序:
#include<reg52.h>//開頭,字體HGSoeiPresemceEB
#include<intrins.h>//用intrins頭文件函數(shù)
#define uchar unsigned char//宏定義uchar代表unsigned char
#define uint unsigned int//宏定義unit代表unsigned int
uint a;//定義a為無符號整型(16位)
uchar i;//定義i為無符號字符型(8位)
uchar temp;//定義字符型變量
void delay(uint z);//void為無返回值函數(shù),delay為時間延時函數(shù)
void main()//唯一主函數(shù),無返回值,沒參數(shù)
{
temp = 0x7f;//temp賦值為11111110
P1 = temp;//P1賦值為temp
while(1)//無限循環(huán)
{
for(i = 0; i <8; i++)//i從0開始,<8,執(zhí)行函數(shù),0+1,<8,執(zhí)行函數(shù),0+1+1,<8,執(zhí)行函數(shù)...一直到0+1+1+1+1+1+1+1+1為止跳出函數(shù)
{
temp = _crol_(temp,1);//定義的temp每次左移一位,循環(huán)
P1 = temp;//賦值P1為temp
delay(500);//延時500毫秒
}
}
}
void delay(uint z) //定義z,z是int型形式參數(shù)(形參)
{
uint x,y;//定義x和y都是int型數(shù)值
for(x = z; x > 0; x--)//for循環(huán)初始值x=z,當x>0時,成立,x自減
for(y = 120; y > 0 ; y--);//for循環(huán)初始值y=120,當y>0時,成立,y自減
}
按照教程,控制led燈的流水閃爍,但是有幾個紅字的地方,我不是很懂,希望得到大家的幫助
最后這段
uint x,y;//定義x和y都是int型數(shù)值
for(x = z; x > 0; x--)//for循環(huán)初始值x=z,當x>0時,成立,x自減
for(y = 120; y > 0 ; y--);//for循環(huán)初始值y=120,當y>0時,成立,y自減
雖然做了注釋,但是,我不理解,他是怎么和delay(500)配合工作的,如果刪了這一段,led燈就流水閃爍的特別厲害,,謝謝大家的幫助,,,
|
|