|
#include <reg52.h> //引用c51頭文件
#include <intrins.h> //循環(huán)移位標(biāo)準(zhǔn)函數(shù)
#define uchar unsigned char //用define對(duì)char、int變量進(jìn)行宏定義
#define uint unsigned int //*宏定義后面不用加分號(hào),因?yàn)樗穷A(yù)處理指令不是語(yǔ)句
sbit aa = P2^3; //蜂鳴器相關(guān)變量
uchar temp; //定義LED相關(guān)函數(shù)
void delay(z) //引用延時(shí)函數(shù)delay(毫秒級(jí))
{
int x,y;
for(x = z; x > 0; x--)
for(y = 144; y > 0; y--);
//這里當(dāng)for只執(zhí)行下一條for語(yǔ)句是不用加花括號(hào);兩條以上需要花括號(hào)
}
void main() //*main函數(shù)自帶循環(huán)
{
temp = 0xf; //給temp賦值十六進(jìn)制0xfe,二進(jìn)制位1111 1110,一次點(diǎn)亮四個(gè)LED燈
P1 = temp; //給P1口賦值temp
delay(100); //毫秒級(jí)延時(shí)函數(shù),持續(xù)時(shí)間為100毫秒
while(1) //使用while循環(huán)函數(shù),一個(gè)大循環(huán)
{
temp = _crol_(temp,1); /*循環(huán)移位函數(shù)_crol_,表示為左移循環(huán)1位,括號(hào)里的
temp左移1位賦值給括號(hào)外的temp結(jié)果為1111 1101*/
P1=temp;
aa = ~aa; //~取反值,點(diǎn)響蜂鳴器
delay(100); //毫秒級(jí)延時(shí)函數(shù),持續(xù)時(shí)間為100毫秒
}
}
|
評(píng)分
-
查看全部評(píng)分
|