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